Skip to content

Commit

Permalink
Fix DO regen task query conditions (#1643)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anvit committed Oct 3, 2023
1 parent f374ec5 commit a1ebb2f
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a1ebb2f

Please sign in to comment.