You are here

function backup_migrate_ui_schedule_form in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.3 backup_migrate.module \backup_migrate_ui_schedule_form()
  2. 7.3 backup_migrate.module \backup_migrate_ui_schedule_form()

The quick schedule form.

1 string reference to 'backup_migrate_ui_schedule_form'
backup_migrate_ui_schedule in ./backup_migrate.module
The menu callback for quick schedules.

File

./backup_migrate.module, line 523
Create (manually or scheduled) and restore backups of your Drupal MySQL database with an option to exclude table data (e.g. cache_*)

Code

function backup_migrate_ui_schedule_form(&$form_state, $sources, $schedules) {
  $form = array();
  $form['quickschedule'] = array(
    '#tree' => TRUE,
  );

  // Add a quick schedule item for each source.
  foreach ($sources as $id => $source) {
    if (isset($schedules[$id])) {
      $schedule = $schedules[$id];
      $key = preg_replace('/[^A-Za-z0-9\\-_]/', '-', $id);
      $form['quickschedule'][$key] = array();
      $form['quickschedule'][$key]['#theme'] = 'backup_migrate_ui_quick_schedule_form_inline';
      $form['quickschedule'][$key]['id'] = array(
        '#type' => 'value',
        '#value' => $id,
      );
      $form['quickschedule'][$key]['enabled'] = array(
        '#type' => 'checkbox',
        '#title' => t('Automatically backup my @source', array(
          '@source' => $source
            ->get('name'),
        )),
        '#default_value' => $schedule
          ->get('enabled'),
      );

      /*
      $form['quickschedule'][$id]['source_id'] = array(
        '#type' => 'item',
        '#title' => t('Backup Source'),
        '#value' => $source->get('name'),
      );
      */
      $form['quickschedule'][$key]['settings'] = array(
        '#type' => 'backup_migrate_dependent',
        '#dependencies' => array(
          'quickschedule[' . $key . '][enabled]' => TRUE,
        ),
      );
      $options = array(
        60 * 60 => t('Once an hour'),
        60 * 60 * 24 => t('Once a day'),
        60 * 60 * 24 * 7 => t('Once a week'),
      );
      $period = $schedule
        ->get('period');
      if (!isset($options[$period])) {
        $options[$period] = $schedule
          ->get('frequency_description');
      }
      $form['quickschedule'][$key]['settings']['period'] = array(
        '#type' => 'select',
        '#title' => t('Schedule Frequency'),
        '#options' => $options,
        '#default_value' => $period,
      );
      $form['quickschedule'][$key]['settings']['destination'] = _backup_migrate_get_destination_pulldown('scheduled backup', $schedule
        ->get('destination_id'), $schedule
        ->get('copy_destination_id'));
      $form['quickschedule'][$key]['settings']['destination']['destination_id']['#parents'] = array(
        'quickschedule',
        $key,
        'destination_id',
      );
      $form['quickschedule'][$key]['settings']['destination']['copy']['#parents'] = array(
        'quickschedule',
        $key,
        'copy',
      );
      $form['quickschedule'][$key]['settings']['destination']['copy_destination']['copy_destination_id']['#parents'] = array(
        'quickschedule',
        $key,
        'copy_destination_id',
      );
      array(
        '#type' => 'select',
        '#title' => t('Backup Destination'),
        '#options' => _backup_migrate_get_destination_form_item_options('scheduled backup'),
        '#default_value' => $schedule
          ->get('period'),
      );
      $form['quickschedule'][$key]['settings']['profile_id'] = array(
        '#type' => 'select',
        '#title' => t('Settings Profile'),
        '#default_value' => $schedule
          ->get('profile_id'),
        '#options' => _backup_migrate_get_profile_form_item_options(),
      );
      $keep = $schedule
        ->get('keep');
      $option_keys = array_unique(array(
        BACKUP_MIGRATE_SMART_DELETE,
        30,
        100,
        500,
        BACKUP_MIGRATE_KEEP_ALL,
        $keep,
      ));
      $options = array();
      foreach ($option_keys as $i) {
        $options[$i] = $schedule
          ->generate_keep_description($i);
      }
      $form['quickschedule'][$key]['settings']['keep'] = array(
        '#type' => 'select',
        '#title' => t('Backup retention'),
        '#options' => $options,
        '#default_value' => $keep,
      );
      $form['quickschedule'][$key]['settings']['advanced'] = array(
        '#type' => 'markup',
        '#value' => l(t('Advanced Settings.'), BACKUP_MIGRATE_MENU_PATH . '/settings/schedule/edit/' . $id, array(
          'query' => drupal_get_destination(),
        )),
      );

      // Set the parent for the setttings up a level.
      foreach (element_children($form['quickschedule'][$key]['settings']) as $child) {
        $form['quickschedule'][$key]['settings'][$child]['#parents'] = array(
          'quickschedule',
          $key,
          $child,
        );
      }
    }
  }
  if (element_children($form['quickschedule'])) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save Schedules'),
    );
  }
  $form['advanced'] = array(
    '#type' => 'markup',
    '#value' => '<div class="clearblock backup-migrate-footer-message">' . t('For more scheduling options and do add additional schedules, try the <a href="!advancedurl">advanced schedule page</a>.', array(
      '!advancedurl' => url(BACKUP_MIGRATE_MENU_PATH . '/settings/schedule'),
    )) . '</div>',
  );
  return $form;
}