You are here

class OrphanedEntitiesHandler in Acquia Content Hub 8.2

Discovers entities with given origin.

@package Drupal\acquia_contenthub\EventSubscriber\Unregister

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\Unregister\OrphanedEntitiesHandler implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of OrphanedEntitiesHandler

1 string reference to 'OrphanedEntitiesHandler'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses OrphanedEntitiesHandler
acquia_contenthub.unregister.orphaned_entities in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\Unregister\OrphanedEntitiesHandler

File

src/EventSubscriber/Unregister/OrphanedEntitiesHandler.php, line 15

Namespace

Drupal\acquia_contenthub\EventSubscriber\Unregister
View source
class OrphanedEntitiesHandler implements EventSubscriberInterface {

  /**
   * The client factory.
   *
   * @var \Drupal\acquia_contenthub\Client\ClientFactory
   */
  protected $clientFactory;

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::ACH_UNREGISTER][] = [
      'onDeleteWebhook',
    ];
    return $events;
  }

  /**
   * OrphanedFilterHandler constructor.
   *
   * @param \Drupal\acquia_contenthub\Client\ClientFactory $factory
   *   ACH Client Factory.
   */
  public function __construct(ClientFactory $factory) {
    $this->clientFactory = $factory;
  }

  /**
   * Gathers information about orphaned entities.
   *
   * @param \Drupal\acquia_contenthub\Event\AcquiaContentHubUnregisterEvent $event
   *   The event being dispatched.
   *
   * @throws \Exception
   */
  public function onDeleteWebhook(AcquiaContentHubUnregisterEvent $event) : void {
    $client = $this->clientFactory
      ->getClient();
    $origin = !empty($event
      ->getOriginUuid()) ? $event
      ->getOriginUuid() : $client
      ->getSettings()
      ->getUuid();
    $list_entities = $client
      ->listEntities([
      'origin' => $origin,
    ]);
    $orphaned_entites = $list_entities['total'] <= 1 ? 0 : $list_entities['total'];
    $event
      ->setOrphanedEntitiesAmount($orphaned_entites);
    $event
      ->setOrphanedEntities($list_entities['data']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrphanedEntitiesHandler::$clientFactory protected property The client factory.
OrphanedEntitiesHandler::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
OrphanedEntitiesHandler::onDeleteWebhook public function Gathers information about orphaned entities.
OrphanedEntitiesHandler::__construct public function OrphanedFilterHandler constructor.