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