Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix stable 3 3 0 10249 fix data loss on settings #4379

Merged
38 changes: 29 additions & 9 deletions classes/migration/upgrade/OJSv3_3_0UpgradeMigration.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,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) {
jonasraoni marked this conversation as resolved.
Show resolved Hide resolved
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($row) as $column) {
if (substr($column, -3, '_id')) {
$primaryKeys[] = $column;
jonasraoni marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

$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]);
}
Expand Down
6 changes: 5 additions & 1 deletion dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<!-- migrateUserAndAuthorNames should be after migrateSRLocale -->
<code function="migrateUserAndAuthorNames" condition="return $installer->tableExists('users_tmp');" />
</upgrade>

<upgrade minversion="2.4.0.0" maxversion="3.1.9.9">
<code function="migrateSubmissionCoverImages" />
</upgrade>
Expand Down Expand Up @@ -208,6 +208,10 @@
<note file="docs/release-notes/README-3.3.0" />
</upgrade>

<upgrade minversion="3.3.0.16" maxversion="3.3.0.19">
jonasraoni marked this conversation as resolved.
Show resolved Hide resolved
jonasraoni marked this conversation as resolved.
Show resolved Hide resolved
<migration class="lib.pkp.classes.migration.upgrade.I10249_FixProfileImageDataLoss" />
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
<code function="addPluginVersions" />
</install>
Loading