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

Fixes #5127 mapped uuids not saving in registry #5139

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Common/Uuid/UuidMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public static function createMappingRecordForResourcePaths($targetUuid, $resourc
sqlStatementNoLog($insertStatement, $bindValues, true);
$index++;
}
// now insert the mapped uuids into the registry
$uuidRegistry->insertUuidsIntoRegistry($uuids);
}
return $uuids;
}
Expand Down
22 changes: 22 additions & 0 deletions src/Common/Uuid/UuidRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public static function populateAllMissingUuids($log = true)
self::appendPopulateLog('uuid_mapping', $mappedCounter, $logEntryComment);
}

// To rectify a bug where mapped uuids were created but nothing in the UUID register for vital observations we
// will populate the UUIDRegistry
$mappedRegistryUuidCounter = self::createMissingMappedUuids();
self::appendPopulateLog('uuid_registry', $mappedRegistryUuidCounter, $logEntryComment);

if (!empty($logEntryComment)) {
$logEntryComment = rtrim($logEntryComment, ', ');
}
Expand All @@ -151,6 +156,23 @@ public static function populateAllMissingUuids($log = true)
}
}

/**
* Creates registry entries for missing uuids in uuid_mapping that are not in uuid_registry. Returns the count of
* the records that were created.
* @return int
*/
private static function createMissingMappedUuids()
{
$createdRows = 0;
$sql = "INSERT INTO `uuid_registry`(`uuid`,`table_name`,`table_id`,`mapped`) "
. " SELECT `uuid_mapping`.`uuid`,'uuid_mapping','id',1 FROM `uuid_mapping` LEFT JOIN `uuid_registry` registry2 ON `uuid_mapping`.`uuid` = registry2.uuid WHERE registry2.uuid IS NULL";
$result = sqlStatementNoLog($sql, []);
if ($result !== false) {
$createdRows = generic_sql_affected_rows();
}
return $createdRows;
}

/**
* Returns the uuid registry record for a given uuid.
* @param string|binary $uuid The uuid to search
Expand Down