class SmsDeliveryReportsProcessor in SMS Framework 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/SmsDeliveryReportsProcessor.php \Drupal\sms\EventSubscriber\SmsDeliveryReportsProcessor
- 2.1.x src/EventSubscriber/SmsDeliveryReportsProcessor.php \Drupal\sms\EventSubscriber\SmsDeliveryReportsProcessor
Handles delivery reports as they come in and updates storage.
Hierarchy
- class \Drupal\sms\EventSubscriber\SmsDeliveryReportsProcessor implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SmsDeliveryReportsProcessor
1 string reference to 'SmsDeliveryReportsProcessor'
1 service uses SmsDeliveryReportsProcessor
File
- src/
EventSubscriber/ SmsDeliveryReportsProcessor.php, line 13
Namespace
Drupal\sms\EventSubscriberView source
class SmsDeliveryReportsProcessor implements EventSubscriberInterface {
/**
* The entity storage for SMS delivery reports.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $reportStorage;
/**
* Creates a new SmsDeliveryReportsProcessor controller.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->reportStorage = $entity_type_manager
->getStorage('sms_report');
}
/**
* Updates the delivery status on stored SMS delivery reports.
*
* @param \Drupal\sms\Event\SmsDeliveryReportEvent $event
* The event containing updated delivery reports status.
*/
public function updateDeliveryReports(SmsDeliveryReportEvent $event) {
foreach ($event
->getReports() as $report) {
// Only messages that have message IDs can be tracked and updated.
if ($report
->getMessageId()) {
$existing = $this->reportStorage
->loadByProperties([
'message_id' => $report
->getMessageId(),
]);
if ($existing) {
$existing = reset($existing);
$existing
->setStatus($report
->getStatus())
->setStatusMessage($report
->getStatusMessage())
->setStatusTime($report
->getStatusTime())
->save();
}
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Update delivery reports as they are received.
$events[SmsEvents::DELIVERY_REPORT_POST_PROCESS][] = [
'updateDeliveryReports',
1024,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SmsDeliveryReportsProcessor:: |
protected | property | The entity storage for SMS delivery reports. | |
SmsDeliveryReportsProcessor:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SmsDeliveryReportsProcessor:: |
public | function | Updates the delivery status on stored SMS delivery reports. | |
SmsDeliveryReportsProcessor:: |
public | function | Creates a new SmsDeliveryReportsProcessor controller. |