Browse Source

Delete FixityCheck entity if file entity doesn't exist

pull/15/head
Chris MacDonald 11 months ago
parent
commit
f19338fc7d
  1. 8
      src/Entity/FixityCheck.php
  2. 5
      src/Plugin/QueueWorker/FixityCheckWorker.php

8
src/Entity/FixityCheck.php

@ -208,7 +208,13 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface {
public function getFile(): ?File {
/** @var \Drupal\Core\Field\EntityReferenceFieldItemList $file */
$file = $this->file;
return $file->isEmpty() ? NULL : $file->referencedEntities()[0];
if ($file->isEmpty()) {
return NULL;
}
$referenced_entities = $file->referencedEntities();
return !empty($referenced_entities) ? reset($referenced_entities) : NULL;
}
/**

5
src/Plugin/QueueWorker/FixityCheckWorker.php

@ -7,6 +7,7 @@ use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\dgi_fixity\FixityCheckServiceInterface;
use Drupal\dgi_fixity\FixityCheckInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use function PHPUnit\Framework\isEmpty;
/**
* Performs a fixity check.
@ -60,6 +61,10 @@ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPlugi
*/
public function processItem($data) {
if ($data instanceof FixityCheckInterface) {
if (isEmpty($data->getFile())) {
$data->delete();
return;
}
/** @var \Drupal\dgi_fixity\FixityCheckInterface $data */
$this->fixity->check($data->getFile());
}

Loading…
Cancel
Save