From 1a106b91fd9ff32d132346abffb51967df7258de Mon Sep 17 00:00:00 2001 From: Jonas Raoni Soares da Silva Date: Wed, 31 Jul 2024 13:33:40 +0300 Subject: [PATCH] pkp/pkp-lib#10249 Fixed regression on migration --- .../upgrade/OPSv3_3_0UpgradeMigration.inc.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php b/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php index 4a6343587b..c30dc63034 100644 --- a/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php +++ b/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php @@ -143,17 +143,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]); }