From a1ebb2fa4bf2be3130abb959102a4ef13af9a2b7 Mon Sep 17 00:00:00 2001 From: Anvit Srivastav Date: Fri, 15 Sep 2023 14:33:14 -0700 Subject: [PATCH] Fix DO regen task query conditions (#1643) Add conditions for the regen task SQL query to whereClauses to ensure that they end up after the keyword WHERE instead of manually appending them to the query. --- .../digitalObjectRegenDerivativesTask.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/task/digitalobject/digitalObjectRegenDerivativesTask.class.php b/lib/task/digitalobject/digitalObjectRegenDerivativesTask.class.php index 36eca06db9..105ac15099 100644 --- a/lib/task/digitalobject/digitalObjectRegenDerivativesTask.class.php +++ b/lib/task/digitalobject/digitalObjectRegenDerivativesTask.class.php @@ -191,22 +191,20 @@ protected function execute($arguments = [], $options = []) // Only regenerate derivatives for remote digital objects if ($options['only-externals']) { - $query .= ' AND do.usage_id = '.QubitTerm::EXTERNAL_URI_ID; + array_push($whereClauses, sprintf('do.usage_id = %d', QubitTerm::EXTERNAL_URI_ID)); } // Only regenerate derivatives for digital objects of specific media type if ($options['media-type']) { - $query .= ' AND do.media_type_id = '.$validMediaTypes[$options['media-type']]; + array_push($whereClauses, sprintf('do.media_type_id = %d', $validMediaTypes[$options['media-type']])); } // Limit ids for regeneration by json list if ($options['json']) { $ids = json_decode(file_get_contents($options['json'])); - $query .= ' AND do.id IN ('.implode(', ', $ids).')'; + array_push($whereClauses, 'do.id IN ('.implode(', ', $ids).')'); } - $query .= ' AND do.usage_id != '.QubitTerm::OFFLINE_ID; - if ($options['no-overwrite']) { $query .= ' LEFT JOIN digital_object child ON do.id = child.parent_id'; array_push($whereClauses, 'do.parent_id IS NULL AND child.id IS NULL'); @@ -242,6 +240,8 @@ protected function execute($arguments = [], $options = []) $query .= sprintf(' WHERE %s', implode(' AND ', $whereClauses)); } + $query .= ' AND do.usage_id != '.QubitTerm::OFFLINE_ID; + // Do work foreach (QubitPdo::fetchAll($query) as $item) { $do = QubitDigitalObject::getById($item->id);