public function drush_pm_version_control_backup::pre_update

3.x backup.inc public drush_pm_version_control_backup::pre_update(&$project, $items_to_test = array())
4.x backup.inc public drush_pm_version_control_backup::pre_update(&$project, $items_to_test = array())

Implementation of pre_update().

Overrides drush_pm_version_control::pre_update

File

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

Class

drush_pm_version_control_backup

Code

public function pre_update(&$project, $items_to_test = array()) {
  $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');

  // Save the date to be used in the backup directory's path name.
  $date = date('YmdHis', $_SERVER['REQUEST_TIME']);

  $backup_dir = drush_get_option('backup-dir', $drupal_root . '/backup');
  $backup_dir = rtrim($backup_dir, '/');
  @drush_op('mkdir', $backup_dir, 0777);
  $backup_dir .= '/modules';
  @drush_op('mkdir', $backup_dir, 0777);
  $backup_dir .= "/$date";
  @drush_op('mkdir', $backup_dir, 0777);
  $backup_target = $backup_dir . '/' . $project['name'];
  // Save for rollback or notifications.
  $project['backup_target'] = $backup_target;
  if (!drush_op('rename', $project['full_project_path'], $backup_target)) {
    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)));
  }
  return TRUE;
}