Skip to content

Commit

Permalink
pkp#10249 Fixed regression on migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni authored and Hafsa-Naeem committed Dec 11, 2024
1 parent 68d4800 commit d45ea9a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions classes/migration/upgrade/PKPv3_3_0UpgradeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function (Builder $q) use ($row, $lastInsertedFileId) {
DB::table('event_log_settings as els')
->join(
'event_log_settings as file_setting',
fn (JoinClause $join) =>
fn(JoinClause $join) =>
$join->on('file_setting.log_id', '=', 'els.log_id')
->where('file_setting.setting_name', '=', 'fileId')
->where('file_setting.setting_value', '=', (string) $row->file_id)
Expand Down Expand Up @@ -823,7 +823,7 @@ private function _settingsAsJSON()
error_log("Failed to migrate the settings entity \"{$tableName}\"\n" . $e);
continue;
}
$settings->each(fn ($row) => $this->_toJSON($row, $tableName, ['setting_name', 'locale'], 'setting_value'));
$settings->each(fn($row) => $this->_toJSON($row, $tableName, ['setting_name', 'locale'], 'setting_value'));
}
}

Expand Down Expand Up @@ -876,19 +876,20 @@ private function _toJSON($row, $tableName, $searchBy, $valueToConvert)
}
$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;
// 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;
}
return true;
});
}

$queryBuilder = DB::table($tableName)->where($id, $row->{$id});
foreach ($searchBy as $key => $column) {
$queryBuilder = $queryBuilder->where($column, $row->{$column});
$queryBuilder = DB::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 d45ea9a

Please sign in to comment.