diff --git a/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php b/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php
index 4a6343587b..030378d3fb 100644
--- a/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php
+++ b/classes/migration/upgrade/OPSv3_3_0UpgradeMigration.inc.php
@@ -143,17 +143,37 @@ 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
+ // Ensure ID fields are included on the filter to avoid updating similar rows
+ $tableDetails = Capsule::connection()->getDoctrineSchemaManager()->listTableDetails($tableName);
+ $primaryKeys = [];
+ try {
+ $primaryKeys = $tableDetails->getPrimaryKeyColumns();
+ } catch (Exception $e) {
+ foreach ($tableDetails->getIndexes() as $index) {
+ if($index->isPrimary() || $index->isUnique()) {
+ $primaryKeys = $index->getColumns();
+ break;
+ }
+ }
+ }
- // Remove empty filters
- $searchBy = array_filter($searchBy, function ($item) use ($row) {
- if (empty($row->{$item})) return false;
- return true;
- });
+ if (!count($primaryKeys)) {
+ foreach (array_keys(get_object_vars($row)) as $column) {
+ if (substr($column, -3, '_id')) {
+ $primaryKeys[] = $column;
+ }
+ }
+ }
+
+ $searchBy = array_merge($searchBy, $primaryKeys);
- $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]);
}
diff --git a/dbscripts/xml/upgrade.xml b/dbscripts/xml/upgrade.xml
index c395cfc545..a7b50f6733 100644
--- a/dbscripts/xml/upgrade.xml
+++ b/dbscripts/xml/upgrade.xml
@@ -30,6 +30,10 @@
+
+
+
+
diff --git a/lib/pkp b/lib/pkp
index a930f7b1aa..f09741c623 160000
--- a/lib/pkp
+++ b/lib/pkp
@@ -1 +1 @@
-Subproject commit a930f7b1aadd4e537b5cfb19a1b7df564da3c279
+Subproject commit f09741c62371de7721fad92321180ecd879749ab