Example #1
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_schedule = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Schedule Name'), '#maxlength' => 255, '#default_value' => $backup_migrate_schedule->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_schedule->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\Schedule::load'), '#disabled' => !$backup_migrate_schedule->isNew());
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Schedule enabled'), '#default_value' => $backup_migrate_schedule->get('enabled'));
     $bam = backup_migrate_get_service_object([], ['nobrowser' => TRUE]);
     $form['source_id'] = DrupalConfigHelper::getSourceSelector($bam, t('Backup Source'));
     $form['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, t('Backup Destination'));
     $form['settings_profile_id'] = DrupalConfigHelper::getSettingsProfileSelector(t('Settings Profile'));
     $period = Schedule::secondsToPeriod($backup_migrate_schedule->get('period'));
     $form['period_container'] = array('#parents' => array(), '#type' => 'fieldset', '#title' => $this->t('Frequency'), '#field_prefix' => $this->t('Run every'), '#attributes' => array('class' => array('container-inline', 'fieldgroup', 'form-composite')));
     $form['period_container']['period_number'] = array('#type' => 'number', '#default_value' => $period['number'], '#min' => 1, '#title' => $this->t('Period number'), '#title_display' => 'invisible', '#size' => 2);
     $form['period_container']['period_type'] = ['#type' => 'select', '#title' => $this->t('Period type'), '#title_display' => 'invisible', '#options' => [], '#default_value' => $period['type']];
     foreach (Schedule::getPeriodTypes() as $key => $type) {
         $form['period_container']['period_type']['#options'][$key] = $type['title'];
     }
     //    $form['keep'] = array(
     //      '#type' => 'textfield',
     //      '#title' => $this->t('Number to keep'),
     //      '#default_value' => $backup_migrate_schedule->get('keep'),
     //      '#description' => $this->t('The number of backups to retain. Once this number is reached, the oldest backup will be deleted to make room for the most recent backup. Leave blank to keep all backups.'),
     //      '#size' => 10,
     //    );
     return $form;
 }
 public function listAll()
 {
     $bam = backup_migrate_get_service_object();
     $out = [];
     foreach ($bam->destinations()->getAllByOp('listFiles') as $id => $destination) {
         $out[$id] = ['title' => ['#markup' => '<h2>Backups in ' . $destination->confGet('name') . '</h2>'], 'list' => $this::listDestinationBackups($destination, $id)];
     }
     return $out;
 }
 /**
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  * @param null $backup_migrate_destination
  * @param null $backup_id
  * @return array
  */
 public function buildForm(array $form, FormStateInterface $form_state, $backup_migrate_destination = NULL, $backup_id = NULL)
 {
     $this->destination = $backup_migrate_destination;
     $this->backup_id = $backup_id;
     $bam = backup_migrate_get_service_object();
     $form['source_id'] = DrupalConfigHelper::getPluginSelector($bam->sources(), $this->t('Restore To'));
     $conf_schema = $bam->plugins()->map('configSchema', array('operation' => 'restore'));
     $form += DrupalConfigHelper::buildFormFromSchema($conf_schema, $bam->plugins()->config());
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_settings = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $backup_migrate_settings->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_settings->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\SettingsProfile::load'), '#disabled' => !$backup_migrate_settings->isNew());
     $bam = backup_migrate_get_service_object($backup_migrate_settings->get('config'));
     $form['config'] = DrupalConfigHelper::buildAllPluginsForm($bam->plugins(), 'backup', ['config']);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = array();
     $bam = backup_migrate_get_service_object();
     $form['backup_migrate_restore_upload'] = array('#title' => t('Upload a Backup File'), '#type' => 'file', '#description' => t("Upload a backup file created by Backup and Migrate. For other database or file backups please use another tool for import. Max file size: %size", array("%size" => format_size(file_upload_max_size()))));
     $form['source_id'] = DrupalConfigHelper::getPluginSelector($bam->sources(), $this->t('Restore To'));
     $conf_schema = $bam->plugins()->map('configSchema', array('operation' => 'restore'));
     $form += DrupalConfigHelper::buildFormFromSchema($conf_schema, $bam->plugins()->config());
     $form['quickbackup']['submit'] = array('#type' => 'submit', '#value' => t('Restore now'), '#weight' => 1);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $bam = backup_migrate_get_service_object($form_state->getValues());
     // Let the plugins validate their own config data.
     if ($plugin_errors = $bam->plugins()->map('configErrors', array('operation' => 'backup'))) {
         foreach ($plugin_errors as $plugin_key => $errors) {
             foreach ($errors as $error) {
                 $form_state->setErrorByName($plugin_key . '][' . $error->getFieldKey(), $this->t($error->getMessage(), $error->getReplacement()));
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = array();
     // Theme the form if we want it inline.
     // @FIXME
     // $form['#theme'] = 'backup_migrate_ui_manual_quick_backup_form_inline';
     $bam = backup_migrate_get_service_object();
     $form['quickbackup'] = array('#type' => 'fieldset', "#title" => t("Quick Backup"), "#collapsible" => FALSE, "#collapsed" => FALSE, "#tree" => FALSE);
     $form['quickbackup']['source_id'] = DrupalConfigHelper::getPluginSelector($bam->plugins()->getAllByOp('exportToFile'), t('Backup Source'));
     $form['quickbackup']['destination_id'] = DrupalConfigHelper::getPluginSelector($bam->plugins()->getAllByOp('saveFile'), t('Backup Destination'));
     // Create the service
     //    $bam = backup_migrate_get_service_object($config);
     //    $bam->plugins()->get('namer')->confGet('filename');
     // $form['quickbackup']['source_id'] = _backup_migrate_get_source_pulldown(\Drupal::config('backup_migrate.settings')->get('backup_migrate_source_id'));
     // $form['quickbackup']['destination'] = _backup_migrate_get_destination_pulldown('manual backup', \Drupal::config('backup_migrate.settings')->get('backup_migrate_destination_id'), \Drupal::config('backup_migrate.settings')->get('backup_migrate_copy_destination_id'));
     $form['quickbackup']['submit'] = array('#type' => 'submit', '#value' => t('Backup now'), '#weight' => 1);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_schedule = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Schedule Name'), '#maxlength' => 255, '#default_value' => $backup_migrate_schedule->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_schedule->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\Schedule::load'), '#disabled' => !$backup_migrate_schedule->isNew());
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Schedule enabled'), '#default_value' => $backup_migrate_schedule->get('enabled'));
     $bam = backup_migrate_get_service_object([], ['nobrowser' => TRUE]);
     $form['source_id'] = DrupalConfigHelper::getPluginSelector($bam->plugins()->getAllByOp('exportToFile'), t('Backup Source'));
     $form['source_id']['source_id']['#default_value'] = $backup_migrate_schedule->get('source_id');
     $form['destination_id'] = DrupalConfigHelper::getPluginSelector($bam->plugins()->getAllByOp('saveFile'), t('Backup Destination'));
     $form['source_id']['destination_id']['#default_value'] = $backup_migrate_schedule->get('destination_id');
     $form['period'] = array('#type' => 'textfield', '#title' => $this->t('Frequency'), '#default_value' => $backup_migrate_schedule->get('period'), '#field_suffix' => $this->t('Seconds'), '#size' => 10);
     //    $form['keep'] = array(
     //      '#type' => 'textfield',
     //      '#title' => $this->t('Number to keep'),
     //      '#default_value' => $backup_migrate_schedule->get('keep'),
     //      '#description' => $this->t('The number of backups to retain. Once this number is reached, the oldest backup will be deleted to make room for the most recent backup. Leave blank to keep all backups.'),
     //      '#size' => 10,
     //    );
     return $form;
 }
<?php

// Run backup if nonce validates
if (isset($_REQUEST['bam_simple_backup']) && wp_verify_nonce($_REQUEST['bam_simple_backup'], 'bam_simple_backup')) {
    $bam = backup_migrate_get_service_object();
    $bam->backup('db', 'download');
}
add_action('admin_menu', 'bam_add_admin_menu');
function bam_add_admin_menu()
{
    add_management_page(__('Backup and Migrate', 'backupmigrate'), __('Backup and Migrate', 'backupmigrate'), 'manage_options', 'bam-admin-page', 'bam_admin_page');
}
function bam_admin_page()
{
    // Output basic backup form
    echo '<div class="wrap">';
    echo '<h1>' . __('Backup and Migrate', 'backupmigrate') . '</h1>';
    echo '<form method="post">';
    echo wp_nonce_field('bam_simple_backup', 'bam_simple_backup');
    submit_button(__('Backup Database', 'backupmigrate'));
    echo '</form>';
    echo '</div class="wrap">';
}
function backup_migrate_get_service_object($config_array = [])
{
    static $bam = NULL;
    // If the static cached object has not been loaded.
    if ($bam === NULL) {
        // Create the environment services.
        // Create the service locator
        $services = new \BackupMigrate\Core\Service\ServiceLocator();