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