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