diff --git a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php index 83978d9764..eda43e2ef3 100644 --- a/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php +++ b/src/applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php @@ -36,6 +36,12 @@ final class PhabricatorFilesManagementMigrateWorkflow 'name' => 'all', 'help' => pht('Migrate all files.'), ), + array( + 'name' => 'copy', + 'help' => pht( + 'Copy file data instead of moving it: after migrating, do not '. + 'remove the old data even if it is no longer referenced.'), + ), array( 'name' => 'names', 'wildcard' => true, @@ -70,6 +76,8 @@ final class PhabricatorFilesManagementMigrateWorkflow $min_size = (int)$args->getArg('min-size'); $max_size = (int)$args->getArg('max-size'); + $is_copy = $args->getArg('copy'); + $failed = array(); $engines = PhabricatorFileStorageEngine::loadAllEngines(); $total_bytes = 0; @@ -158,7 +166,7 @@ final class PhabricatorFilesManagementMigrateWorkflow if ($is_dry_run) { // Do nothing, this is a dry run. } else { - $file->migrateToEngine($target_engine); + $file->migrateToEngine($target_engine, $is_copy); } $total_files += 1; diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 8d81c3ae98..d301abceca 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -422,7 +422,10 @@ final class PhabricatorFile extends PhabricatorFileDAO return self::buildFromFileData($data, $params); } - public function migrateToEngine(PhabricatorFileStorageEngine $engine) { + public function migrateToEngine( + PhabricatorFileStorageEngine $engine, + $make_copy) { + if (!$this->getID() || !$this->getStorageHandle()) { throw new Exception( pht("You can not migrate a file which hasn't yet been saved.")); @@ -446,10 +449,12 @@ final class PhabricatorFile extends PhabricatorFileDAO $this->setStorageHandle($new_handle); $this->save(); - $this->deleteFileDataIfUnused( - $old_engine, - $old_identifier, - $old_handle); + if (!$make_copy) { + $this->deleteFileDataIfUnused( + $old_engine, + $old_identifier, + $old_handle); + } return $this; }