Commit 1bad8896 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3300864: Add kill-switch

parent 831a3416
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -5,8 +5,10 @@ namespace Drupal\danse\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Site\Settings;

/**
 * Defines the DANSE notification entity class.
@@ -35,6 +37,16 @@ class Notification extends ContentEntityBase implements NotificationInterface {

  use EntityChangedTrait;

  /**
   * {@inheritdoc}
   */
  public function postCreate(EntityStorageInterface $storage): void {
    parent::postCreate($storage);
    if (!Settings::get('danse_notification_delivery', TRUE)) {
      $this->set('delivered', TRUE);
    }
  }

  /**
   * {@inheritdoc}
   */
+10 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Site\Settings;
use Drupal\danse\Entity\Event;
use Drupal\danse\Entity\EventInterface;
use Drupal\danse\Entity\Notification;
@@ -161,8 +162,13 @@ abstract class PluginBase extends CorePluginBase implements PluginInterface, Con
        if ($event->isPush()) {
          foreach ($this->recipientSelectionPlugins as $recipientSelectionPlugin) {
            if ($recipientSelectionPlugin instanceof DirectPushInterface) {
              $result = $recipientSelectionPlugin->push($payload);
              $channelPluginId = $recipientSelectionPlugin->directPushChannelId();
              if (Settings::get('danse_notification_delivery', TRUE)) {
                $result = $recipientSelectionPlugin->push($payload);
              }
              else {
                $result = ChannelPluginInterface::RESULT_STATUS_SUCCESS;
              }
              $success = $result === ChannelPluginInterface::RESULT_STATUS_SUCCESS;
              foreach ($this->createNotification($event, 'push', 1) as $notification) {
                if ($success) {
@@ -177,8 +183,9 @@ abstract class PluginBase extends CorePluginBase implements PluginInterface, Con
                ]);
                try {
                  $action->save();
                } catch (EntityStorageException $e) {
                  // TODO: Log this exception.
                }
                catch (EntityStorageException $e) {
                  // @todo Log this exception.
                }
              }
            }