/[drupal]/contributions/modules/backup_migrate/backup_migrate.module
ViewVC logotype

Diff of /contributions/modules/backup_migrate/backup_migrate.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.25.2.1.2.19, Mon Apr 6 04:07:53 2009 UTC revision 1.1.2.25.2.1.2.20, Mon Jun 1 03:02:21 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: backup_migrate.module,v 1.1.2.25.2.1.2.18 2009/04/05 04:18:09 ronan Exp $  // $Id: backup_migrate.module,v 1.1.2.25.2.1.2.19 2009/04/06 04:07:53 ronan Exp $
3    
4    
5  /**  /**
# Line 16  Line 16 
16  function backup_migrate_help($section, $arg) {  function backup_migrate_help($section, $arg) {
17    $help = array(    $help = array(
18      array(      array(
19        'body' => t('Backup and Migrate makes the task of backing up your Drupal database and migrating data from one Drupal install to another easier. It provides a function to backup the entire database to file or download, and to restore from a previous backup. You can also schedule the backup operation. Compression of backup files is also supported.'),        'body' =>
20           t('Backup and Migrate makes the task of backing up your Drupal database and migrating data from one Drupal install to another easier. It provides a function to backup the entire database to file or download, and to restore from a previous backup. You can also schedule the backup operation. Compression of backup files is also supported.  The database backup files created with this module can be imported into this or any other Drupal installation with the !restorelink, or you can use a database tool such as <a href="!phpmyadminurl">phpMyAdmin</a> or the mysql command line command.',
21             array(
22                '!restorelink' => user_access('restore from backup') ? l(t('restore feature'), 'admin/content/backup_migrate/restore') : t('restore feature'),
23                '!phpmyadminurl' => 'http://www.phpmyadmin.net'
24              )
25            )
26      ),      ),
27      'admin/content/backup_migrate' => array(      'admin/content/backup_migrate' => array(
28        'title' => t('Backup Tab'),        'title' => t('Quick Backup Tab'),
29        'body' => t('Use this form to run manual backups of your database. You can fill out the fields below, or if you have any !profilelink saved you can load one. The backup files created can be imported into this or any other Drupal installation with the !restorelink, or you can use a database tool such as <a href="!phpmyadminurl">phpMyAdmin</a> or the mysql command line command.',        'body' => t('Use this form to run simple manual backups of your database. Visit the !helppage for more help using this module',
30          array(
31            '!helppage' => l(t('help page'), 'admin/help/backup_migrate'))
32          ),
33        ),
34        'admin/content/backup_migrate/export/advanced' => array(
35          'title' => t('Advanced Backup Tab'),
36          'body' => t('Use this form to run manual backups of your database with more advanced options. If you have any !profilelink saved you can load those settings. You can save any of the changes you make to these settings as a new settings profile.',
37        array("!profilelink" => user_access('administer backup and migrate') ? l(t('settings profiles'), 'admin/content/backup_migrate/profile') : t('settings profiles'), '!restorelink' => user_access('restore from backup') ? l(t('restore feature'), 'admin/content/backup_migrate/restore') : t('restore feature'), '!phpmyadminurl' => 'http://www.phpmyadmin.net')),        array("!profilelink" => user_access('administer backup and migrate') ? l(t('settings profiles'), 'admin/content/backup_migrate/profile') : t('settings profiles'), '!restorelink' => user_access('restore from backup') ? l(t('restore feature'), 'admin/content/backup_migrate/restore') : t('restore feature'), '!phpmyadminurl' => 'http://www.phpmyadmin.net')),
38      ),      ),
39      'admin/content/backup_migrate/restore' => array(      'admin/content/backup_migrate/restore' => array(
# Line 71  function backup_migrate_menu() { Line 84  function backup_migrate_menu() {
84    $items['admin/content/backup_migrate'] = array(    $items['admin/content/backup_migrate'] = array(
85      'title' => 'Backup and Migrate',      'title' => 'Backup and Migrate',
86      'description' => 'Backup/restore your database or migrate data to or from another Drupal site.',      'description' => 'Backup/restore your database or migrate data to or from another Drupal site.',
87      'page callback' => 'backup_migrate_ui_manual_backup',      'page callback' => 'backup_migrate_ui_manual_backup_quick',
88      'access arguments' => array('access backup and migrate'),      'access arguments' => array('access backup and migrate'),
89      'type' => MENU_NORMAL_ITEM,      'type' => MENU_NORMAL_ITEM,
90    );    );
# Line 79  function backup_migrate_menu() { Line 92  function backup_migrate_menu() {
92      'title' => 'Backup',      'title' => 'Backup',
93      'description' => 'Backup the database.',      'description' => 'Backup the database.',
94      'page callback' => 'backup_migrate_menu_callback',      'page callback' => 'backup_migrate_menu_callback',
95      'page arguments' => array('', 'backup_migrate_ui_manual_backup', TRUE),      'page arguments' => array('', 'backup_migrate_ui_manual_backup_quick', TRUE),
96        'access arguments' => array('access backup and migrate'),
97        'weight' => 0,
98        'type' => MENU_DEFAULT_LOCAL_TASK,
99      );
100      $items['admin/content/backup_migrate/export/quick'] = array(
101        'title' => 'Quick Backup',
102        'description' => 'Backup the database.',
103        'page callback' => 'backup_migrate_menu_callback',
104        'page arguments' => array('', 'backup_migrate_ui_manual_backup_quick', TRUE),
105      'access arguments' => array('access backup and migrate'),      'access arguments' => array('access backup and migrate'),
106      'weight' => 0,      'weight' => 0,
107      'type' => MENU_DEFAULT_LOCAL_TASK,      'type' => MENU_DEFAULT_LOCAL_TASK,
108    );    );
109      $items['admin/content/backup_migrate/export/advanced'] = array(
110        'title' => 'Advanced Backup',
111        'description' => 'Backup the database.',
112        'page callback' => 'backup_migrate_menu_callback',
113        'page arguments' => array('', 'backup_migrate_ui_manual_backup_advanced', TRUE),
114        'access arguments' => array('perform backup'),
115        'weight' => 1,
116        'type' => MENU_LOCAL_TASK,
117      );
118    $items['admin/content/backup_migrate/restore'] = array(    $items['admin/content/backup_migrate/restore'] = array(
119      'title' => 'Restore',      'title' => 'Restore',
120      'description' => 'Restore the database from a previous backup',      'description' => 'Restore the database from a previous backup',
# Line 173  function backup_migrate_menu() { Line 204  function backup_migrate_menu() {
204      'page callback' => 'backup_migrate_menu_callback',      'page callback' => 'backup_migrate_menu_callback',
205      'page arguments' => array('schedules', 'backup_migrate_ui_schedule_display_schedules', TRUE),      'page arguments' => array('schedules', 'backup_migrate_ui_schedule_display_schedules', TRUE),
206      'access arguments' => array('administer backup and migrate'),      'access arguments' => array('administer backup and migrate'),
207      'weight' => 3,      'weight' => 4,
208      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
209    );    );
210    $items['admin/content/backup_migrate/schedule/list'] = array(    $items['admin/content/backup_migrate/schedule/list'] = array(
# Line 214  function backup_migrate_menu() { Line 245  function backup_migrate_menu() {
245      'type' => MENU_LOCAL_TASK,      'type' => MENU_LOCAL_TASK,
246    );    );
247    $items['admin/content/backup_migrate/profile'] = array(    $items['admin/content/backup_migrate/profile'] = array(
248      'title' => 'Profiles',      'title' => 'Settings Profiles',
249      'description' => 'View existing profiles',      'description' => 'View existing profiles',
250      'page callback' => 'backup_migrate_menu_callback',      'page callback' => 'backup_migrate_menu_callback',
251      'page arguments' => array('profiles', 'backup_migrate_ui_profile_display_profiles', TRUE),      'page arguments' => array('profiles', 'backup_migrate_ui_profile_display_profiles', TRUE),
# Line 286  function backup_migrate_exit() { Line 317  function backup_migrate_exit() {
317    if (function_exists('drupal_get_path')) {    if (function_exists('drupal_get_path')) {
318      require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/files.inc';      require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/files.inc';
319      // Delete any temporary files generated during this execution.      // Delete any temporary files generated during this execution.
320      _backup_migrate_temp_files_delete();      backup_migrate_cleanup();
321    }    }
322  }  }
323    
# Line 306  function backup_migrate_simpletest() { Line 337  function backup_migrate_simpletest() {
337    return array_keys($tests);    return array_keys($tests);
338  }  }
339    
340    /**
341     * Implementation of hook_theme().
342     */
343    function backup_migrate_theme() {
344      $themes = array(
345        'backup_migrate_ui_manual_quick_backup_form' => array(
346          'arguments' => array('form'),
347        ),
348      );
349      return $themes;
350    }
351    
352  /* Menu Callbacks */  /* Menu Callbacks */
353    
354  /**  /**
# Line 322  function backup_migrate_menu_callback($i Line 365  function backup_migrate_menu_callback($i
365  }  }
366    
367  /**  /**
368   * The menu callback for manual backups.   * The menu callback for easy manual backups.
369   */   */
370  function backup_migrate_ui_manual_backup($profile_id = NULL) {  function backup_migrate_ui_manual_backup_quick() {
   require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';  
371    $out = "";    $out = "";
372    if (user_access('perform backup')) {    if (user_access('perform backup')) {
373      $profile = _backup_migrate_profile_saved_default_profile($profile_id);      $out .= drupal_get_form('backup_migrate_ui_manual_quick_backup_form');
     $out .= drupal_get_form('backup_migrate_ui_manual_backup_load_profile_form', $profile);  
     $out .= drupal_get_form('backup_migrate_ui_manual_backup_form', $profile);  
374    }    }
375    else {    else {
376      $out = t('You do not have permission to back up this site.');      $out = t('You do not have permission to back up this site.');
# Line 339  function backup_migrate_ui_manual_backup Line 379  function backup_migrate_ui_manual_backup
379  }  }
380    
381  /**  /**
382     * The menu callback for advanced manual backups.
383     */
384    function backup_migrate_ui_manual_backup_advanced($profile_id = NULL) {
385      require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';
386      $out = "";
387      $profile = _backup_migrate_profile_saved_default_profile($profile_id);
388      $out .= drupal_get_form('backup_migrate_ui_manual_backup_load_profile_form', $profile);
389      $out .= drupal_get_form('backup_migrate_ui_manual_backup_form', $profile);
390      return $out;
391    }
392    
393    /**
394   * The backup/export load profile form.   * The backup/export load profile form.
395   */   */
396  function backup_migrate_ui_manual_backup_load_profile_form(&$form_state, $profile = NULL) {  function backup_migrate_ui_manual_backup_load_profile_form(&$form_state, $profile = NULL) {
397    $form = array();    $form = array();
398    $profile_options = _backup_migrate_get_profile_form_item_options();    $profile_options = _backup_migrate_get_profile_form_item_options();
399    if (count($profile_options) > 0) {    if (count($profile_options) > 0) {
400      $profile_options = array(0 => t('-- Select a Profile --')) + $profile_options;      $profile_options = array(0 => t('-- Select a Settings Profile --')) + $profile_options;
401      $form['profile'] = array(      $form['profile'] = array(
402        "#title" => t("Settings Profile"),        "#title" => t("Settings Profile"),
403        "#collapsible" => TRUE,        "#collapsible" => TRUE,
# Line 380  function backup_migrate_ui_manual_backup Line 432  function backup_migrate_ui_manual_backup
432    else {    else {
433      variable_set("backup_migrate_profile_id", NULL);      variable_set("backup_migrate_profile_id", NULL);
434    }    }
435    }
436    
437    /**
438     * The quick backup form.
439     */
440    function backup_migrate_ui_manual_quick_backup_form(&$form_state) {
441      require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/profiles.inc';
442      drupal_add_js(drupal_get_path('module', 'backup_migrate') .'/backup_migrate.js');
443    
444      $form = array();
445    
446      $form['quickbackup'] = array(
447        '#type' => 'fieldset',
448        "#title" => t("Quick Backup"),
449        "#collapsible" => FALSE,
450        "#collapsed" => FALSE,
451        "#tree" => FALSE,
452      );
453    
454      $form['quickbackup']['source_id'] = _backup_migrate_get_source_pulldown(variable_get('backup_migrate_source_id', NULL));
455    
456      $form['quickbackup']['destination_id'] = array(
457        "#type" => "select",
458        "#title" => t("Destination"),
459        "#options" => _backup_migrate_get_destination_form_item_options('manual backup'),
460        "#default_value" => variable_get("backup_migrate_destination_id", "download"),
461      );
462      $profile_options = _backup_migrate_get_profile_form_item_options();
463      $form['quickbackup']['profile_id'] = array(
464        "#type" => "select",
465        "#title" => t("Settings Profile"),
466        '#default_value' => variable_get('backup_migrate_profile_id', NULL),
467        "#options" => $profile_options,
468      );
469    
470      $form['quickbackup']['submit'] = array(
471        '#type' => 'submit',
472        '#value' => t('Backup now'),
473        '#weight' => 1,
474      );
475    
476      $form['advanced'] = array(
477        '#type' => 'markup',
478        '#value' => t('For more backup options, try the <a href="!advancedurl">advanced backup page</a>.', array('!advancedurl' => url('admin/content/backup_migrate/export/advanced'))),
479      );
480    
481    
482      return $form;
483    }
484    
485    /**
486     * Submit the quick backup form.
487     */
488    function backup_migrate_ui_manual_quick_backup_form_submit($form, &$form_state) {
489      if (user_access('perform backup')) {
490        // For a quick backup use the default settings.
491        $settings = _backup_migrate_profile_saved_default_profile($form_state['values']['profile_id']);
492    
493        // Set the destination to the one chosen in the pulldown.
494        $settings['destination_id'] = $form_state['values']['destination_id'];
495        $settings['source_id'] = $form_state['values']['source_id'];
496    
497        // Save the settings for next time.
498        variable_set("backup_migrate_source_id", $form_state['values']['source_id']);
499        variable_set("backup_migrate_destination_id", $form_state['values']['destination_id']);
500        variable_set("backup_migrate_profile_id", $form_state['values']['profile_id']);
501    
502        // Do the backup.
503        backup_migrate_ui_manual_backup_perform($settings);
504      }
505    $form_state['redirect'] = "admin/content/backup_migrate";    $form_state['redirect'] = "admin/content/backup_migrate";
506  }  }
507    
508  /**  /**
509     * Theme the quick backup form.
510     */
511    function theme_backup_migrate_ui_manual_quick_backup_form($form) {
512      // Remove the titles so that the pulldowns can be displayed inline.
513      unset($form['quickbackup']['source_id']['#title']);
514      unset($form['quickbackup']['destination_id']['#title']);
515      unset($form['quickbackup']['profile_id']['#title']);
516    
517      $replacements = array(
518        '!from' => drupal_render($form['quickbackup']['source_id']),
519        '!to' => drupal_render($form['quickbackup']['destination_id']),
520        '!profile' => drupal_render($form['quickbackup']['profile_id']),
521        '!submit' => drupal_render($form['quickbackup']['submit']),
522      );
523      $form['quickbackup']['markup'] = array(
524        '#type'   => 'markup',
525        "#prefix" => '<div class="container-inline">',
526        "#suffix" => '</div>',
527        '#value'  => t('Backup from !from to !to using !profile !submit', $replacements),
528      );
529      unset($form['quickbackup']['source_id']);
530      unset($form['quickbackup']['destination_id']);
531      unset($form['quickbackup']['profile_id']);
532      unset($form['quickbackup']['submit']);
533      return drupal_render($form);
534    }
535    
536    /**
537   * The backup/export form.   * The backup/export form.
538   */   */
539  function backup_migrate_ui_manual_backup_form(&$form_state, $profile = array()) {  function backup_migrate_ui_manual_backup_form(&$form_state, $profile = array()) {
# Line 449  function backup_migrate_ui_manual_backup Line 599  function backup_migrate_ui_manual_backup
599        $name["#default_value"] = t('Untitled Profile');        $name["#default_value"] = t('Untitled Profile');
600      }      }
601      $form['save_options']['name'] = $name;      $form['save_options']['name'] = $name;
602        $form['save_options'][] = array(
603          '#type' => 'submit',
604          '#value' => t('Save Without Backing Up'),
605        );
606    }    }
607    
608    $form[] = array(    $form[] = array(
# Line 462  function backup_migrate_ui_manual_backup Line 616  function backup_migrate_ui_manual_backup
616   * Submit the form. Save the values as defaults if desired and output the backup file.   * Submit the form. Save the values as defaults if desired and output the backup file.
617   */   */
618  function backup_migrate_ui_manual_backup_form_submit($form, &$form_state) {  function backup_migrate_ui_manual_backup_form_submit($form, &$form_state) {
619    if ($form_state['values']['op'] == t('Load Profile')) {    // Save the settings profile if the save box is checked.
620      if ($profile = backup_migrate_get_profile($form_state['values']['profile_id'])) {    $form_state['values']['nodata_tables'] = array_filter((array)$form_state['values']['nodata_tables']);
621        $form_state['redirect'] = "admin/content/backup_migrate/". $form_state['values']['profile_id'];    $form_state['values']['exclude_tables'] = array_filter((array)$form_state['values']['exclude_tables']);
622      if ($form_state['values']['save_settings'] && user_access('administer backup and migrate')) {
623        if (@$form_state['values']['create_new']) {
624          $form_state['values']['profile_id'] = NULL;
625      }      }
626        $profile = backup_migrate_profile_save_profile($form_state['values']);
627        variable_set("backup_migrate_profile_id", $profile['profile_id']);
628        variable_set("backup_migrate_destination_id", $form_state['values']['destination_id']);
629    }    }
   if ($form_state['values']['op'] == t('Backup Database') && user_access('perform backup')) {  
     $form_state['values']['nodata_tables'] = array_filter((array)$form_state['values']['nodata_tables']);  
     $form_state['values']['exclude_tables'] = array_filter((array)$form_state['values']['exclude_tables']);  
     if ($form_state['values']['save_settings']) {  
       if (@$form_state['values']['create_new']) {  
         $form_state['values']['profile_id'] = NULL;  
       }  
       $profile = backup_migrate_profile_save_profile($form_state['values']);  
       variable_set("backup_migrate_profile_id", $profile['profile_id']);  
       variable_set("backup_migrate_destination_id", $form_state['values']['destination_id']);  
     }  
630    
631      // Set interactive mode so that messages are sent to the user.    // Perform the actual backup if that is what was selected.
632      _backup_migrate_interactive(TRUE);    if ($form_state['values']['op'] == t('Backup Database') && user_access('perform backup')) {
633      $settings = $form_state['values'];      $settings = $form_state['values'];
634      $file = backup_migrate_perform_backup($settings);      backup_migrate_ui_manual_backup_perform($settings);
635      }
636      $form_state['redirect'] = "admin/content/backup_migrate/export/advanced";
637    }
638    
639      if ($file) {  /**
640        $destination = backup_migrate_get_destination($form_state['values']['destination_id']);   * Perform an actual manual backup and tell the user of the progress.
641        require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/destinations.inc';   */
642        $message = 'Database backup file %file saved to destination %dest. !links';  
643        $links = "";  function backup_migrate_ui_manual_backup_perform($settings) {
644        if ($links = $destination->get_file_links($file->file_id())) {    // Set interactive mode so that messages are sent to the user.
645          $links = ' ('. implode(", ", $links) .')';    _backup_migrate_interactive(TRUE);
646        }  
647        _backup_migrate_message($message, array('%file' => $settings['filename'], '%dest' => $destination->name(), '!links' => $links ? $links : ""));    // Peform the actual backup.
648      $file = backup_migrate_perform_backup($settings);
649    
650      // If the backup succeeded, tell the user and give options to download, restore etc.
651      if ($file) {
652        $destination = backup_migrate_get_destination($settings['destination_id']);
653        require_once './'. drupal_get_path('module', 'backup_migrate') .'/includes/destinations.inc';
654        $message = 'Database backup file %file saved to destination %dest. !links';
655        $links = "";
656        if ($links = $destination->get_file_links($file->file_id())) {
657          $links = ' ('. implode(", ", $links) .')';
658      }      }
659        _backup_migrate_message($message, array('%file' => $settings['filename'], '%dest' => $destination->name(), '!links' => $links ? $links : ""));
660    }    }
   $form_state['redirect'] = "admin/content/backup_migrate";  
661  }  }
662    
663  /**  /**
# Line 518  function backup_migrate_ui_manual_restor Line 680  function backup_migrate_ui_manual_restor
680    if (count($sources) > 1) {    if (count($sources) > 1) {
681      $form['source_id'] = array(      $form['source_id'] = array(
682        "#type" => "select",        "#type" => "select",
683        "#title" => t("Database"),        "#title" => t("Restore to"),
684        "#options" => _backup_migrate_get_destination_form_item_options('source'),        "#options" => _backup_migrate_get_destination_form_item_options('source'),
685        "#description" => t("Choose the database to restore to. Any database destinations you have created and any databases specified in your settings.php can be restored to."),        "#description" => t("Choose the database to restore to. Any database destinations you have created and any databases specified in your settings.php can be restored to."),
686        "#default_value" => 'db_url:default',        "#default_value" => 'db_url:default',
# Line 634  function backup_migrate_perform_backup(& Line 796  function backup_migrate_perform_backup(&
796    
797    $file = backup_migrate_filters_backup($file, $settings);    $file = backup_migrate_filters_backup($file, $settings);
798    if (!$file) {    if (!$file) {
799      _backup_migrate_temp_files_delete();      backup_migrate_cleanup();
800      return FALSE;      return FALSE;
801    }    }
802    
# Line 646  function backup_migrate_perform_backup(& Line 808  function backup_migrate_perform_backup(&
808    
809    backup_migrate_backup_succeed("Site backed up successfully.", array(), $settings);    backup_migrate_backup_succeed("Site backed up successfully.", array(), $settings);
810    // Delete any temporary files we've created.    // Delete any temporary files we've created.
811    _backup_migrate_temp_files_delete();    backup_migrate_cleanup();
812    return $file;    return $file;
813  }  }
814    
# Line 669  function backup_migrate_perform_restore( Line 831  function backup_migrate_perform_restore(
831    $file = backup_migrate_destination_get_file($destination_id, $file_id);    $file = backup_migrate_destination_get_file($destination_id, $file_id);
832    if (!$file) {    if (!$file) {
833      _backup_migrate_message("Could not restore because the file could not be loaded from the destination.", array(), 'error');      _backup_migrate_message("Could not restore because the file could not be loaded from the destination.", array(), 'error');
834      _backup_migrate_temp_files_delete();      backup_migrate_cleanup();
835      return FALSE;      return FALSE;
836    }    }
837    
# Line 677  function backup_migrate_perform_restore( Line 839  function backup_migrate_perform_restore(
839    $file = backup_migrate_filters_restore($file);    $file = backup_migrate_filters_restore($file);
840    if (!$file) {    if (!$file) {
841      // No error as filters should take care of that themselves.      // No error as filters should take care of that themselves.
842      _backup_migrate_temp_files_delete();      backup_migrate_cleanup();
843      return FALSE;      return FALSE;
844    }    }
845    
# Line 690  function backup_migrate_perform_restore( Line 852  function backup_migrate_perform_restore(
852      else {      else {
853        _backup_migrate_message("Could not restore the database.", array(), 'error');        _backup_migrate_message("Could not restore the database.", array(), 'error');
854      }      }
855      _backup_migrate_temp_files_delete();      backup_migrate_cleanup();
856      return FALSE;      return FALSE;
857    }    }
858    
# Line 723  function backup_migrate_perform_restore_ Line 885  function backup_migrate_perform_restore_
885    }    }
886    
887    // Delete any temp files we've created.    // Delete any temp files we've created.
888    _backup_migrate_temp_files_delete();    backup_migrate_cleanup();
889    return $num;    return $num;
890  }  }
891    

Legend:
Removed from v.1.1.2.25.2.1.2.19  
changed lines
  Added in v.1.1.2.25.2.1.2.20

  ViewVC Help
Powered by ViewVC 1.1.2