abstract class PurgeBase in Acquia Content Hub 8.2
Class PurgeBase.
Provides the base event subscriber class for "purge successful" webhook handler for acquia_contenthub_publisher and acquia_contenthub_subscriber modules.
@package Drupal\acquia_contenthub\EventSubscriber\HandleWebhook
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\HandleWebhook\PurgeBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of PurgeBase
2 files declare their use of PurgeBase
File
- src/
EventSubscriber/ HandleWebhook/ PurgeBase.php, line 20
Namespace
Drupal\acquia_contenthub\EventSubscriber\HandleWebhookView source
abstract class PurgeBase implements EventSubscriberInterface {
/**
* The webhook's "purge" event name.
*/
protected const PURGE = 'purge';
/**
* The Queue.
*
* @var \Drupal\Core\Queue\QueueInterface
*/
protected $queue;
/**
* The logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* PurgeBase constructor.
*
* @param \Drupal\Core\Queue\QueueFactory $queue_factory
* The queue factory.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger_channel
* The logger factory.
*/
public function __construct(QueueFactory $queue_factory, LoggerChannelInterface $logger_channel) {
$this->queue = $queue_factory
->get($this
->getQueueName());
$this->logger = $logger_channel;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::HANDLE_WEBHOOK][] = 'onHandleWebhook';
return $events;
}
/**
* On handle webhook event.
*
* @param \Drupal\acquia_contenthub\Event\HandleWebhookEvent $event
* The handle webhook event.
*/
public function onHandleWebhook(HandleWebhookEvent $event) {
$payload = $event
->getPayload();
if (self::PURGE !== $payload['crud']) {
return;
}
if ('successful' !== $payload['status']) {
$this->logger
->error('Failed to react on @webhook webhook (@payload).', [
'@webhook' => self::PURGE,
'@payload' => print_r($payload, TRUE),
]);
return;
}
$this
->onPurgeSuccessful();
}
/**
* Reacts on "purge successful" webhook.
*/
protected function onPurgeSuccessful() {
// Delete queue.
$this->queue
->deleteQueue();
$this->logger
->info('Queue @queue has been purged successfully.', [
'@queue' => $this
->getQueueName(),
]);
}
/**
* Returns the queue name to delete.
*
* @return string
* Queue name.
*/
protected abstract function getQueueName() : string;
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PurgeBase:: |
protected | property | The logger service. | |
PurgeBase:: |
protected | property | The Queue. | |
PurgeBase:: |
abstract protected | function | Returns the queue name to delete. | 2 |
PurgeBase:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
PurgeBase:: |
public | function | On handle webhook event. | |
PurgeBase:: |
protected | function | Reacts on "purge successful" webhook. | 1 |
PurgeBase:: |
protected | constant | The webhook's "purge" event name. | |
PurgeBase:: |
public | function | PurgeBase constructor. | 1 |