diff --git a/src/Entity/FixityCheck.php b/src/Entity/FixityCheck.php index 1c95791..4ea5099 100644 --- a/src/Entity/FixityCheck.php +++ b/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; } /** diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index 2bc09b5..2872688 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/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()); }