示例#1
0
 /**
  * @param BackupMigrateInterface $bam
  *  The Backup and Migrate service object used to execute the backups
  *
  * @param bool $force
  *  Run the schedule even if it is not due to be run.
  */
 public function run(BackupMigrateInterface $bam, $force = FALSE)
 {
     $next_run_at = $this->getNextRun();
     $should_run_now = REQUEST_TIME >= $next_run_at;
     $enabled = $this->get('enabled');
     if ($force || $should_run_now && $enabled) {
         // Set the last run time before attempting backup.
         // This will prevent a failing schedule from retrying on every cron run.
         $this->setLastRun(REQUEST_TIME);
         try {
             $config = [];
             if ($settings_profile_id = $this->get('settings_profile_id')) {
                 // Load the settings profile if one is selected.
                 $profile = SettingsProfile::load($settings_profile_id);
                 if (!$profile) {
                     throw new BackupMigrateException("The settings profile '%profile' does not exist", ['%profile' => $settings_profile_id]);
                 }
                 $config = $profile->get('config');
             }
             \Drupal::logger('backup_migrate')->info("Running schedule %name", ['%name' => $this->get('label')]);
             // TODO: Set the config (don't just use the defaults).
             // Run the backup.
             $bam->setConfig(new Config($config));
             $bam->backup($this->get('source_id'), $this->get('destination_id'), $config);
             drupal_set_message('Backup Complete.');
         } catch (BackupMigrateException $e) {
             \Drupal::logger('backup_migrate')->error("Scheduled backup '%name' failed: @err", ['%name' => $this->get('label'), '@err' => $e->getMessage()]);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     $config = [];
     // Load the settings profile if one is selected.
     if ($values['settings_profile_id']) {
         $config = SettingsProfile::load($values['settings_profile_id'])->get('config');
     }
     backup_migrate_perform_backup($values['source_id'], $values['destination_id'], $config);
 }
 /**
  * GEt a pulldown for the list of all settings profiles.
  *
  * @param $title
  * @return array
  */
 public static function getSettingsProfileSelector($title)
 {
     $options = [];
     foreach (SettingsProfile::loadMultiple() as $key => $profile) {
         $options[$key] = $profile->get('label');
     }
     if ($options) {
         return ['#type' => 'select', '#title' => $title, '#options' => $options];
     }
 }