You are here

function backup_db_cron in Backup Database 8

1 string reference to 'backup_db_cron'
BackupDatabaseCronForm::getFormId in src/Form/BackupDatabaseCronForm.php
Returns a unique string identifying the form.

File

./backup_db.module, line 87
backup_db.module

Code

function backup_db_cron() {
  $config = \Drupal::config('backup_db.settings');
  if ($config
    ->get('cron_backup_enabled')) {
    $interval = (int) $config
      ->get('cron_interval') * 60 * 60;
    $expires = Drupal::state()
      ->get('backup_db.cron_last_run') ?: REQUEST_TIME;
    $next = Drupal::state()
      ->get('backup_db.cron_next_backup') ?: $expires + $interval;
    if (REQUEST_TIME > $next) {
      $client = \Drupal::service('backup_db.client');

      // Use the local adapter for cron export.
      $handler = new BackupDatabaseLocalAdapter($client);
      $handler
        ->export();

      /* @todo, error handler
         if (!$backup->error()) {
           drupal_set_message(t('Backup has been successfully completed.'), 'status');
           Drupal::state()->set('backup_db.cron_next_backup', REQUEST_TIME + $interval);
         }
         else {
           drupal_set_message(t('Backup has failed, please review recent log messages.'), 'warning');
         }*/
    }
    Drupal::state()
      ->set('backup_db.cron_last_run', REQUEST_TIME);
  }
}