public function ActivitySendEmailWorker::processItem in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.2 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.3 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.4 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.5 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.6 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.7 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 8.8 modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 10.3.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 10.0.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 10.1.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
- 10.2.x modules/custom/activity_send/modules/activity_send_email/src/Plugin/QueueWorker/ActivitySendEmailWorker.php \Drupal\activity_send_email\Plugin\QueueWorker\ActivitySendEmailWorker::processItem()
Works on a single queue item.
Parameters
mixed $data: The data that was passed to \Drupal\Core\Queue\QueueInterface::createItem() when the item was queued.
Throws
\Drupal\Core\Queue\RequeueException Processing is not yet finished. This will allow another process to claim the item immediately.
\Exception A QueueWorker plugin may throw an exception to indicate there was a problem. The cron process will log the exception, and leave the item in the queue to be processed again later.
\Drupal\Core\Queue\SuspendQueueException More specifically, a SuspendQueueException should be thrown when a QueueWorker plugin is aware that the problem will affect all subsequent workers of its queue. For example, a callback that makes HTTP requests may find that the remote server is not responding. The cron process will behave as with a normal Exception, and in addition will not attempt to process further items from the current item's queue during the current cron run.
Overrides QueueWorkerInterface::processItem
See also
\Drupal\Core\Cron::processQueues()
File
- modules/
custom/ activity_send/ modules/ activity_send_email/ src/ Plugin/ QueueWorker/ ActivitySendEmailWorker.php, line 27
Class
- ActivitySendEmailWorker
- An activity send email worker.
Namespace
Drupal\activity_send_email\Plugin\QueueWorkerCode
public function processItem($data) {
// First make sure it's an actual Activity entity.
if (!empty($data['entity_id']) && ($activity = Activity::load($data['entity_id']))) {
// Get target account.
$target_account = EmailActivityDestination::getSendTargetUser($activity);
if ($target_account instanceof User) {
// Get Message Template id.
$message = Message::load($activity->field_activity_message->target_id);
$message_template_id = $message
->getTemplate()
->id();
// Retrieve the users email settings.
$user_email_settings = EmailActivityDestination::getSendEmailUserSettings($target_account);
// Determine email frequency to use, defaults to immediately.
// @todo make these frequency constants?
$frequency = 'immediately';
if (!empty($user_email_settings[$message_template_id])) {
$frequency = $user_email_settings[$message_template_id];
}
// Send item to EmailFrequency instance.
// @todo use dependency injection for this.
$emailfrequencymanager = \Drupal::service('plugin.manager.emailfrequency');
$instance = $emailfrequencymanager
->createInstance($frequency);
$instance
->processItem($activity, $message, $target_account);
}
}
}