From f19338fc7d354dd4c6060e70411f88ade7698f34 Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:26:50 -0400 Subject: [PATCH 1/6] Delete FixityCheck entity if file entity doesn't exist --- src/Entity/FixityCheck.php | 8 +++++++- src/Plugin/QueueWorker/FixityCheckWorker.php | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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()); } From 6c0e5bdd149c00f41687dec6215edc7858a75d7f Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:28:27 -0400 Subject: [PATCH 2/6] Correct typo --- src/Plugin/QueueWorker/FixityCheckWorker.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index 2872688..b0a7106 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/src/Plugin/QueueWorker/FixityCheckWorker.php @@ -7,7 +7,6 @@ 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. @@ -61,7 +60,7 @@ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPlugi */ public function processItem($data) { if ($data instanceof FixityCheckInterface) { - if (isEmpty($data->getFile())) { + if (empty($data->getFile())) { $data->delete(); return; } From c604f8aa96f46b4dac12b17c0162e7d00791a539 Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:07:37 -0400 Subject: [PATCH 3/6] Wrap check in else --- src/Plugin/QueueWorker/FixityCheckWorker.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index b0a7106..48e9e11 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/src/Plugin/QueueWorker/FixityCheckWorker.php @@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @QueueWorker( * id = "dgi_fixity.fixity_check", * title = @Translation("Fixity Checks"), - * cron = {"time" = 15} + * cron = {"time" = 1} * ) */ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface { @@ -62,10 +62,10 @@ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPlugi if ($data instanceof FixityCheckInterface) { if (empty($data->getFile())) { $data->delete(); - return; + } else { + /** @var \Drupal\dgi_fixity\FixityCheckInterface $data */ + $this->fixity->check($data->getFile()); } - /** @var \Drupal\dgi_fixity\FixityCheckInterface $data */ - $this->fixity->check($data->getFile()); } } From f64a1194db11a371698ea4d54c52bbea89ca41c1 Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:07:59 -0400 Subject: [PATCH 4/6] Correct typo --- src/Plugin/QueueWorker/FixityCheckWorker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index 48e9e11..fc5e039 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/src/Plugin/QueueWorker/FixityCheckWorker.php @@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @QueueWorker( * id = "dgi_fixity.fixity_check", * title = @Translation("Fixity Checks"), - * cron = {"time" = 1} + * cron = {"time" = 15} * ) */ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface { From da8b0c2feba159df6c0d478400c209d7448e82b2 Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:45:15 -0400 Subject: [PATCH 5/6] Linting newline --- src/Plugin/QueueWorker/FixityCheckWorker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index fc5e039..04ad274 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/src/Plugin/QueueWorker/FixityCheckWorker.php @@ -62,7 +62,8 @@ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPlugi if ($data instanceof FixityCheckInterface) { if (empty($data->getFile())) { $data->delete(); - } else { + } + else { /** @var \Drupal\dgi_fixity\FixityCheckInterface $data */ $this->fixity->check($data->getFile()); } From fc548202bfd54bce8d1dd7bb79b5b7d430f71df3 Mon Sep 17 00:00:00 2001 From: Chris MacDonald <31731869+chrismacdonaldw@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:34:03 -0400 Subject: [PATCH 6/6] Revert changes. --- src/Plugin/QueueWorker/FixityCheckWorker.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Plugin/QueueWorker/FixityCheckWorker.php b/src/Plugin/QueueWorker/FixityCheckWorker.php index 04ad274..2bc09b5 100644 --- a/src/Plugin/QueueWorker/FixityCheckWorker.php +++ b/src/Plugin/QueueWorker/FixityCheckWorker.php @@ -60,13 +60,8 @@ class FixityCheckWorker extends QueueWorkerBase implements ContainerFactoryPlugi */ public function processItem($data) { if ($data instanceof FixityCheckInterface) { - if (empty($data->getFile())) { - $data->delete(); - } - else { - /** @var \Drupal\dgi_fixity\FixityCheckInterface $data */ - $this->fixity->check($data->getFile()); - } + /** @var \Drupal\dgi_fixity\FixityCheckInterface $data */ + $this->fixity->check($data->getFile()); } }