Skip to content

Commit

Permalink
refactor: Finish updating content data
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 5, 2024
1 parent f0d3c2a commit f5dd1e3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/services/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,26 @@ protected function updateContent(string $value, CantoFieldData $cantoFieldData,
$jsonSearchSql = $this->pgSqlJsonContains($cantoAssetDataFieldName, $jsonSearchNeedle);
}
$rows = (new Query())
->select([$cantoAssetDataFieldName])
->select(['id', $cantoAssetDataFieldName])
->from([$table])
->where([$cantoIdFieldName => 0, $jsonSearchSql])
->where([$cantoIdFieldName => 0])
->addParams([$jsonSearchSql])
->all();
// Iterate through each row, the field data as appropriate
foreach ($rows as $row) {
$rowCollection = new Collection($row[$cantoAssetDataFieldName]);
$rowCollection->transform(function ($item) use ($cantoFieldData) {
if ($item['id'] === $cantoFieldData->cantoId) {
$item = $cantoFieldData->cantoAssetData[0];
}
return $item;
});
try {
$rowsAffected = Db::update($table, [$cantoAssetDataFieldName => $rowCollection->all()], ['id' => $row['id']]);
} catch (Exception $e) {
Craft::error($e->getMessage(), __METHOD__);
}
}
}
}
}
Expand Down

0 comments on commit f5dd1e3

Please sign in to comment.