backup.inc

  1. 8.0.x commands/pm/version_control/backup.inc
  2. 6.x commands/pm/version_control/backup.inc
  3. 7.x commands/pm/version_control/backup.inc
  4. 3.x commands/pm/version_control/backup.inc
  5. 4.x commands/pm/version_control/backup.inc
  6. 5.x commands/pm/version_control/backup.inc
  7. master commands/pm/version_control/backup.inc

Drush pm directory copy backup extension

Classes

File

commands/pm/version_control/backup.inc
View source
  1. <?php
  2. /**
  3. * @file Drush pm directory copy backup extension
  4. */
  5. class drush_version_control_backup implements drush_version_control {
  6. /**
  7. * Implementation of pre_update().
  8. */
  9. public function pre_update(&$project, $items_to_test = array()) {
  10. if (drush_get_option('no-backup', FALSE)) {
  11. return TRUE;
  12. }
  13. if ($backup_target = $this->prepare_backup_dir()) {
  14. if ($project['project_type'] != 'core') {
  15. $backup_target .= '/' . $project['project_type'] . 's';
  16. drush_mkdir($backup_target);
  17. }
  18. $backup_target .= '/'. $project['name'];
  19. // Save for rollback or notifications.
  20. $project['backup_target'] = $backup_target;
  21. // Move or copy to backup target based in package-handler.
  22. if (drush_get_option('package-handler', 'wget') == 'wget') {
  23. if (drush_move_dir($project['full_project_path'], $backup_target)) {
  24. return TRUE;
  25. }
  26. }
  27. // cvs or git.
  28. elseif (drush_copy_dir($project['full_project_path'], $backup_target)) {
  29. return TRUE;
  30. }
  31. return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('Failed to backup project directory !project to !backup_target', array('!project' => $project['full_project_path'], '!backup_target' => $backup_target)));
  32. }
  33. }
  34. /**
  35. * Implementation of rollback().
  36. */
  37. public function rollback($project) {
  38. if (drush_get_option('no-backup', FALSE)) {
  39. return;
  40. }
  41. if (drush_move_dir($project['backup_target'], $project['full_project_path'], TRUE)) {
  42. return drush_log(dt("Backups were restored successfully."), 'ok');
  43. }
  44. return drush_set_error('DRUSH_PM_BACKUP_ROLLBACK_FAILED', dt('Could not restore backup and rollback from failed upgrade. You will need to resolve manually.'));
  45. }
  46. /**
  47. * Implementation of post_update().
  48. */
  49. public function post_update($project) {
  50. if (drush_get_option('no-backup', FALSE)) {
  51. return;
  52. }
  53. if ($project['backup_target']) {
  54. drush_log(dt("Backups were saved into the directory !backup_target.", array('!backup_target' => $project['backup_target'])), 'ok');
  55. }
  56. }
  57. /**
  58. * Implementation of post_download().
  59. */
  60. public function post_download($project) {
  61. // NOOP
  62. }
  63. // Helper for pre_update.
  64. public function prepare_backup_dir($subdir = NULL) {
  65. return drush_prepare_backup_dir($subdir);
  66. }
  67. public static function reserved_files() {
  68. return array();
  69. }
  70. }