public function drush_version_control_backup::pre_update

8.0.x backup.inc public drush_version_control_backup::pre_update(&$project, $items_to_test = array())
6.x backup.inc public drush_version_control_backup::pre_update(&$project, $items_to_test = array())
7.x backup.inc public drush_version_control_backup::pre_update(&$project, $items_to_test = array())
5.x backup.inc public drush_version_control_backup::pre_update(&$project, $items_to_test = array())
master backup.inc public drush_version_control_backup::pre_update(&$project, $items_to_test = array())

Implementation of pre_update().

Overrides drush_version_control::pre_update

File

commands/pm/version_control/backup.inc, line 13
Drush pm directory copy backup extension

Class

drush_version_control_backup

Code

public function pre_update(&$project, $items_to_test = array()) {
  if (drush_get_option('no-backup', FALSE)) {
    return TRUE;
  }
  if ($backup_target = $this->prepare_backup_dir()) {
    if ($project['project_type'] != 'core') {
      $backup_target .= '/' . $project['project_type'] . 's';
      drush_mkdir($backup_target);
    }
    $backup_target .= '/' . $project['name'];
    // Save for rollback or notifications.
    $project['backup_target'] = $backup_target;

    // Move or copy to backup target based in package-handler.
    if (drush_get_option('package-handler', 'wget') == 'wget') {
      if (drush_move_dir($project['full_project_path'], $backup_target)) {
        return TRUE;
      }
    }
    // cvs or git.
    elseif (drush_copy_dir($project['full_project_path'], $backup_target)) {
      return TRUE;
    }
    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)));
  }
}