From 59ea0a1266ee39b3a76a68ea418193b6f65fdadd Mon Sep 17 00:00:00 2001 From: Steve Wirt Date: Wed, 20 Nov 2024 17:19:05 -0500 Subject: [PATCH] DKAN-4287 Make harvest_run id not a primary key. --- modules/harvest/harvest.install | 26 ++++++++++++++++++++++- modules/harvest/src/Entity/HarvestRun.php | 8 +------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/modules/harvest/harvest.install b/modules/harvest/harvest.install index 64c25a4134..7ccdf298ec 100644 --- a/modules/harvest/harvest.install +++ b/modules/harvest/harvest.install @@ -95,8 +95,32 @@ function harvest_update_8007(&$sandbox) { * This finishes the process started by harvest_update_8007. */ function harvest_update_8008(&$sandbox) { + // Repeated in 8009. +} + +/** + * Update schema to make timestamp based harvest id un-unique. + * + * @see https://github.com/GetDKAN/dkan/issues/4287 + */ +function harvest_update_8009(&$sandbox) { + $table_name = 'harvest_runs '; + // Harvest runs currently has an id field marked as key. It needs to not + // be a key so that it can contain duplicate values. + $dropped = \Drupal::database()->schema()->dropPrimaryKey($table_name); + if ($dropped) { + $msg = "Primary key removed from table {$table_name}. "; + } + else { + $msg = "No primary key found to drop from table {$table_name}. "; + } + + $msg = 'Table harvest_runs had primary key removed. '; + /** @var \Drupal\harvest\HarvestUtility $harvest_utility */ $harvest_utility = \Drupal::service('dkan.harvest.utility'); $harvest_utility->harvestRunsUpdate(); - return 'Harvest runs coalesced into table harvest_runs.'; + $msg .= 'Harvest runs coalesced into table harvest_runs.'; + + return $msg; } diff --git a/modules/harvest/src/Entity/HarvestRun.php b/modules/harvest/src/Entity/HarvestRun.php index 66de79c20d..3d0c5fb1bb 100644 --- a/modules/harvest/src/Entity/HarvestRun.php +++ b/modules/harvest/src/Entity/HarvestRun.php @@ -44,17 +44,11 @@ * }, * base_table = "harvest_runs", * admin_permission = "administer harvest_run", - * entity_keys = { - * "id" = "id", - * "label" = "id", - * }, + * entity_keys = {}, * links = { * "canonical" = "/harvest-run/{harvest_run}", * }, * ) - * - * @todo Convert to using microtime() or other better system for the timestamp/ - * id. */ final class HarvestRun extends HarvestEntityBase implements HarvestRunInterface {