Browse Source

Use a proper exception.

pull/920/head
Rosie Le Faive 2 years ago
parent
commit
41f8710122
  1. 9
      src/EventGenerator/EmitEvent.php
  2. 12
      src/Exception/IslandoraDerivativeException.php
  3. 3
      src/Plugin/Action/AbstractGenerateDerivative.php

9
src/EventGenerator/EmitEvent.php

@ -14,6 +14,7 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\islandora\Event\StompHeaderEvent; use Drupal\islandora\Event\StompHeaderEvent;
use Drupal\islandora\Event\StompHeaderEventException; use Drupal\islandora\Event\StompHeaderEventException;
use Drupal\islandora\Exception\IslandoraDerivativeException;
use Stomp\Exception\StompException; use Stomp\Exception\StompException;
use Stomp\StatefulStomp; use Stomp\StatefulStomp;
use Stomp\Transport\Message; use Stomp\Transport\Message;
@ -157,10 +158,6 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
$user = $this->entityTypeManager->getStorage('user')->load($this->account->id()); $user = $this->entityTypeManager->getStorage('user')->load($this->account->id());
$data = $this->generateData($entity); $data = $this->generateData($entity);
// If $data is the bool false, then abort. No error, but don't emit event.
if ($data === FALSE) {
return;
}
$event = $this->eventDispatcher->dispatch( $event = $this->eventDispatcher->dispatch(
StompHeaderEvent::EVENT_NAME, StompHeaderEvent::EVENT_NAME,
@ -172,6 +169,10 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact
$event->getHeaders()->all() $event->getHeaders()->all()
); );
} }
catch (IslandoraDerivativeException $e) {
$this->logger->info($e->getMessage());
return;
}
catch (StompHeaderEventException $e) { catch (StompHeaderEventException $e) {
$this->logger->error($e->getMessage()); $this->logger->error($e->getMessage());
$this->messenger->addError($e->getMessage()); $this->messenger->addError($e->getMessage());

12
src/Exception/IslandoraDerivativeException.php

@ -0,0 +1,12 @@
<?php
namespace Drupal\islandora\Exception;
/**
* Islandora exceptions.
*
* @package islandora
*/
class IslandoraDerivativeException extends \RuntimeException
{
}

3
src/Plugin/Action/AbstractGenerateDerivative.php

@ -5,6 +5,7 @@ namespace Drupal\islandora\Plugin\Action;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\islandora\Exception\IslandoraDerivativeException;
/** /**
* Emits a Node event. * Emits a Node event.
@ -64,7 +65,7 @@ class AbstractGenerateDerivative extends AbstractGenerateDerivativeBase {
// same as the source media. Dont cause an error, just don't continue. // same as the source media. Dont cause an error, just don't continue.
$derivative_media = $this->utils->getMediaWithTerm($entity, $derivative_term); $derivative_media = $this->utils->getMediaWithTerm($entity, $derivative_term);
if (!is_null($derivative_media) && $derivative_media->id() == $source_media->id()) { if (!is_null($derivative_media) && $derivative_media->id() == $source_media->id()) {
return FALSE; throw new IslandoraDerivativeException("Halting derivative, as source and target media are the same. Derivative term: [" . $this->configuration['derivative_term_uri'] . "] Source term: [" . $this->configuration['source_term_uri'] . "] Node id: [". $entity->id() . "].", 500);
} }
$route_params = [ $route_params = [

Loading…
Cancel
Save