Skip to content

Commit

Permalink
Add PDF page D.O. support to regen. task (#1794) (#1795)
Browse files Browse the repository at this point in the history
Fixed issue with the digital objects regeneration task
(digitalobject:regen-derivatives) deleting, but not regenerating,
digital objects representing PDF pages.

Removed unneeded and unused digital object class method.
  • Loading branch information
mcantelon authored Apr 4, 2024
1 parent 753044f commit 700ea1c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
12 changes: 0 additions & 12 deletions lib/model/QubitDigitalObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1661,18 +1661,6 @@ public function isImage()
return self::isImageFile($this->getName());
}

/**
* Return true if this is a compound digital object.
*
* @return bool
*/
public function isCompoundObject()
{
$isCompoundObjectProp = QubitProperty::getOneByObjectIdAndName($this->id, 'is_compound_object');

return null !== $isCompoundObjectProp && '1' == $isCompoundObjectProp->getValue(['sourceCulture' => true]);
}

/**
* Derive file path for a digital object asset.
*
Expand Down
49 changes: 37 additions & 12 deletions lib/task/digitalobject/digitalObjectRegenDerivativesTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,36 @@ public static function regenerateDerivatives(&$digitalObject, $options = [])
$digitalObject->getLocalPath();
}

// Delete existing derivatives
$criteria = new Criteria();
$criteria->add(QubitDigitalObject::PARENT_ID, $digitalObject->id);

// Delete only ref or thumnail derivative if "type" flag set
if (QubitTerm::REFERENCE_ID == $usageId || QubitTerm::THUMBNAIL_ID == $usageId) {
$criteria->add(QubitDigitalObject::USAGE_ID, $usageId);
}
// Delete derivatives normally, if not dealing with digital objects representing PDF pages
if (null === $digitalObject->getDisplayAsCompoundObject()) {
// Delete existing derivatives
$criteria = new Criteria();
$criteria->add(QubitDigitalObject::PARENT_ID, $digitalObject->id);

// Delete only ref or thumnail derivative if "type" flag set
if (QubitTerm::REFERENCE_ID == $usageId || QubitTerm::THUMBNAIL_ID == $usageId) {
$criteria->add(QubitDigitalObject::USAGE_ID, $usageId);
}

foreach (QubitDigitalObject::get($criteria) as $derivative) {
$derivative->delete();
foreach (QubitDigitalObject::get($criteria) as $derivative) {
$derivative->delete();
}
} else {
// Find parent information object's child information objects representing PDF pages
$criteria = new Criteria();
$criteria->add(QubitInformationObject::PARENT_ID, $digitalObject->objectId);

foreach (QubitInformationObject::get($criteria) as $childIo) {
if (count($childIo->digitalObjectsRelatedByobjectId)) {
// Attempt to get page count property from child information object's digital object
$property = $childIo->digitalObjectsRelatedByobjectId[0]->getPropertyByName('page_count');

// If a property was found then delete the information object
if (null !== $property) {
$childIo->delete();
}
}
}
}

// Delete existing transcript if 'keepTranscript' option is not sent or it's false,
Expand All @@ -64,8 +83,14 @@ public static function regenerateDerivatives(&$digitalObject, $options = [])
$transcriptProperty->delete();
}

// Generate new derivatives
$digitalObject->createRepresentations($usageId, $conn);
// Regenerate derivatives normally, if not dealing with digital objects representing PDF pages
if (null === $digitalObject->getDisplayAsCompoundObject()) {
// Generate new derivatives
$digitalObject->createRepresentations($usageId, $conn);
} else {
// Re-create information objects representing PDF pages and their respective derivatives
$digitalObject->createCompoundChildren();
}

if ($options['index']) {
// Update index
Expand Down

0 comments on commit 700ea1c

Please sign in to comment.