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 Drush pm directory copy backup extension
  4. */
  5. class drush_pm_version_control_backup implements drush_pm_version_control {
  6. /**
  7. * Implementation of pre_update().
  8. */
  9. public function pre_update(&$project, $items_to_test = array()) {
  10. $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  11. // Save the date to be used in the backup directory's path name.
  12. $date = date('YmdHis', $_SERVER['REQUEST_TIME']);
  13. $backup_dir = drush_get_option('backup-dir', $drupal_root . '/backup');
  14. $backup_dir = rtrim($backup_dir, '/');
  15. @drush_op('mkdir', $backup_dir, 0777);
  16. $backup_dir .= '/modules';
  17. @drush_op('mkdir', $backup_dir, 0777);
  18. $backup_dir .= "/$date";
  19. @drush_op('mkdir', $backup_dir, 0777);
  20. $backup_target = $backup_dir . '/'. $project['name'];
  21. // Save for rollback or notifications.
  22. $project['backup_target'] = $backup_target;
  23. if (!drush_op('rename', $project['full_project_path'], $backup_target)) {
  24. 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)));
  25. }
  26. return TRUE;
  27. }
  28. /**
  29. * Implementation of rollback().
  30. */
  31. public function rollback($project) {
  32. if (drush_op('rename', $project['backup_target'], $project['full_project_path']) && is_dir($project['full_project_path'])) {
  33. return drush_log(dt("Backups were restored successfully."), 'ok');
  34. }
  35. 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.'));
  36. }
  37. /**
  38. * Implementation of post_update().
  39. */
  40. public function post_update($project) {
  41. if ($project['backup_target']) {
  42. drush_log(dt("Backups were saved into the directory !backup_target.", array('!backup_target' => $project['backup_target'])), 'ok');
  43. }
  44. }
  45. /**
  46. * Implementation of post_download().
  47. */
  48. public function post_download($project) {
  49. // NOOP
  50. }
  51. }