Skip to content
Snippets Groups Projects
Commit dfc87843 authored by saranya ashokkumar's avatar saranya ashokkumar Committed by saranya ashokkumar
Browse files

Issue #2935286 by saranya ashokkumar: @todo: use $notifications[] =...

Issue #2935286 by saranya ashokkumar: @todo: use $notifications[] = WorkflowNotification::LoadByProperties()
parent 29968201
Branches 8.x-2.x
No related tags found
No related merge requests found
......@@ -74,21 +74,39 @@ class WorkflowNotification extends ConfigEntityBase implements WorkflowNotificat
public $message = ['value' => '', 'format' => 'basic_html',];
/**
* {@inheritdoc}
*/
public static function loadByProperties($from_sid, $to_sid, $wid, $trigger, $days) {
$workflow_notifications = self::loadMultipleByProperties($from_sid, $to_sid, $wid, $trigger, $days);
if($workflow_notifications) {
return $workflow_notifications;
}
return NULL;
}
/**
* {@inheritdoc}
*/
public static function loadMultipleByProperties($from_sid, $to_sid, $wid, $trigger, $days) {
$result = \Drupal::entityQuery("workflow_notify");
if(!empty($from_sid) && !empty($to_state)) {
$from_state = $result->orConditionGroup()
->condition('from_sid', $from_sid, '=')
->condition('from_sid', 'all', '=');
->condition('from_sid', 'any', '=');
$to_state = $result->orConditionGroup()
->condition('to_sid', $to_sid, '=')
->condition('to_sid', 'all', '=');
->condition('to_sid', 'any', '=');
$result->condition($from_state)
->condition($to_state)
->condition('wid', $wid, '=')
->condition('when_to_trigger', $trigger, '=');
->condition($to_state);
}
if(!empty($wid)) {
$result->condition('wid', $wid, '=');
}
if (!empty($trigger)) {
$result->condition('when_to_trigger', $trigger, '=');
}
if (!empty($days)) {
$result->condition('days', $days, '=');
}
......
......@@ -82,13 +82,9 @@ function workflow_notifications_cron() {
$last_run = \Drupal::state()->get('workflow_notifications.last_run') ?: 0;
if (date('d', $last_run) != date('d')) {
// queue to send mail.
// @todo: use $notifications[] = WorkflowNotification::LoadByProperties()
$result = Drupal::entityQuery("workflow_notify")
->condition('when_to_trigger', 'before_state_change', '=')
->execute();
$result = WorkflowNotification::loadByProperties('','','','before_state_change',0);
foreach ($result as $key => $value) {
$entity = WorkflowNotification::load($key);
$data['entity'] = $entity;
$data['entity'] = $value;
$data['notify'] = "mail";
$queue = \Drupal::queue('workflow_scheduled_entity_mail');
$queue->createItem($data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment