You are here

class Notify in Backup and Migrate 8.4

Class Notify

Notifies by email when a backup succeeds or fails.

@package BackupMigrate\Core\Filter

Hierarchy

Expanded class hierarchy of Notify

File

lib/backup_migrate_core/src/Filter/Notify.php, line 18

Namespace

BackupMigrate\Core\Filter
View source
class Notify extends PluginBase implements PluginCallerInterface {
  use PluginCallerTrait;

  /**
   * Add a weight so that our before* operations run before any other plugin has
   * a chance to write any log entries.
   *
   * @return array
   */
  public function supportedOps() {
    return [
      'beforeBackup' => [
        'weight' => -100000,
      ],
      'beforeRestore' => [
        'weight' => -100000,
      ],
    ];
  }

  /**
   * @var StashLogger
   */
  protected $logstash;
  public function beforeBackup() {
    $this
      ->addLogger();
  }
  public function beforeRestore() {
    $this
      ->addLogger();
  }
  public function backupSucceed() {
    $this
      ->sendNotification('Backup finished sucessfully');
  }
  public function backupFail(Exception $e) {
  }
  public function restoreSucceed() {
  }
  public function restoreFail() {
  }

  /**
   * @param $subject
   * @param $body
   * @param $messages
   */
  protected function sendNotification($subject) {
    $messages = $this->logstash
      ->getAll();
    $body = $subject . "\n";
    if (count($messages)) {
    }

    // $body .=
  }

  /**
   * add our stash logger to the service locator to capture all logged messages.
   */
  protected function addLogger() {
    $services = $this
      ->plugins()
      ->services();

    // Get the current logger.
    $logger = $services
      ->get('Logger');

    // Create a new stash logger to save messages.
    $this->logstash = new StashLogger();

    // Add a tee to send logs to both the regular logger and our stash.
    $services
      ->add('Logger', new TeeLogger([
      $logger,
      $this->logstash,
    ]));

    // Add the services back into the plugin manager to re-inject existing plugins
    $this
      ->plugins()
      ->setServiceLocator($services);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration. These configuration options can be overriden by the config options but will not be overwritten. If the object is re-configured after construction any missing configuration options will revert to these values.
ConfigurableTrait::confGet public function Get a specific value from the configuration.
ConfigurableTrait::config public function Get the configuration object for this item.
ConfigurableTrait::configDefaults public function Get the default values for the plugin. 10
ConfigurableTrait::configErrors public function Get any validation errors in the config.
ConfigurableTrait::configSchema public function Get a default (blank) schema. 10
ConfigurableTrait::setConfig public function Set the configuration for all plugins. 1
ConfigurableTrait::__construct public function 2
Notify::$logstash protected property
Notify::addLogger protected function add our stash logger to the service locator to capture all logged messages.
Notify::backupFail public function
Notify::backupSucceed public function
Notify::beforeBackup public function
Notify::beforeRestore public function
Notify::restoreFail public function
Notify::restoreSucceed public function
Notify::sendNotification protected function
Notify::supportedOps public function Add a weight so that our before* operations run before any other plugin has a chance to write any log entries. Overrides PluginBase::supportedOps
PluginBase::opWeight public function What is the weight of the given operation for this plugin. Overrides PluginInterface::opWeight
PluginBase::supportsOp public function Does this plugin implement the given operation. Overrides PluginInterface::supportsOp
PluginCallerTrait::$plugins protected property
PluginCallerTrait::plugins public function Get the plugin manager.
PluginCallerTrait::setPluginManager public function Inject the plugin manager.
TranslatableTrait::$translator protected property
TranslatableTrait::setTranslator public function
TranslatableTrait::t public function Translate the given string if there is a translator service available.