Skip to content

Commit

Permalink
pkp/pkp-lib#10249 Fixed regression on migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Jul 26, 2024
1 parent 8517ea2 commit b91c713
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions classes/migration/upgrade/OJSv3_3_0UpgradeMigration.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,20 @@ private function _toJSON($row, $tableName, $searchBy, $valueToConvert)
if (is_array($oldValue) && $this->_isNumerical($oldValue)) $oldValue = array_values($oldValue);
$newValue = json_encode($oldValue, JSON_UNESCAPED_UNICODE); // don't convert utf-8 characters to unicode escaped code

$id = array_key_first((array)$row); // get first/primary key column

// Remove empty filters
$searchBy = array_filter($searchBy, function ($item) use ($row) {
if (empty($row->{$item})) return false;
return true;
});
// Ensure ID fields are included on the filter to avoid updating similar rows
foreach (array_keys($row) as $column) {
if (substr($column, -3, '_id')) {
$searchBy[] = $column;
}
}

$queryBuilder = Capsule::table($tableName)->where($id, $row->{$id});
foreach ($searchBy as $key => $column) {
$queryBuilder = $queryBuilder->where($column, $row->{$column});
$queryBuilder = Capsule::table($tableName);
foreach (array_unique($searchBy) as $column) {
if ($row->{$column} !== null) {
$queryBuilder->where($column, $row->{$column});
} else {
$queryBuilder->whereNull($column);
}
}
$queryBuilder->update([$valueToConvert => $newValue]);
}
Expand Down

0 comments on commit b91c713

Please sign in to comment.