Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15481673
D19370.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D19370.diff
View Options
diff --git a/src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php b/src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php
--- a/src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php
+++ b/src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php
@@ -6,7 +6,9 @@
protected function didConstruct() {
$this
->setName('migrate-hunk')
- ->setExamples('**migrate-hunk** --id __hunk__ --to __storage__')
+ ->setExamples(
+ "**migrate-hunk** --id __hunk__ --to __storage__\n".
+ "**migrate-hunk** --all")
->setSynopsis(pht('Migrate storage engines for a hunk.'))
->setArguments(
array(
@@ -20,14 +22,27 @@
'param' => 'storage',
'help' => pht('Storage engine to migrate to.'),
),
+ array(
+ 'name' => 'all',
+ 'help' => pht('Migrate all hunks.'),
+ ),
));
}
public function execute(PhutilArgumentParser $args) {
$id = $args->getArg('id');
- if (!$id) {
+ $is_all = $args->getArg('all');
+
+ if ($is_all && $id) {
throw new PhutilArgumentUsageException(
- pht('Specify a hunk to migrate with --id.'));
+ pht(
+ 'Options "--all" (to migrate all hunks) and "--id" (to migrate a '.
+ 'specific hunk) are mutually exclusive.'));
+ } else if (!$is_all && !$id) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Specify a hunk to migrate with "--id", or migrate all hunks '.
+ 'with "--all".'));
}
$storage = $args->getArg('to');
@@ -40,10 +55,51 @@
pht('Specify a hunk storage engine with --to.'));
}
- $hunk = $this->loadHunk($id);
+ if ($id) {
+ $hunk = $this->loadHunk($id);
+ $hunks = array($hunk);
+ } else {
+ $hunks = new LiskMigrationIterator(new DifferentialHunk());
+ }
+
+ foreach ($hunks as $hunk) {
+ try {
+ $this->migrateHunk($hunk, $storage);
+ } catch (Exception $ex) {
+ // If we're migrating a single hunk, just throw the exception. If
+ // we're migrating multiple hunks, warn but continue.
+ if ($id) {
+ throw $ex;
+ }
+
+ $this->logWarn(
+ pht('WARN'),
+ pht(
+ 'Failed to migrate hunk %d: %s',
+ $hunk->getID(),
+ $ex->getMessage()));
+ }
+ }
+
+ return 0;
+ }
+
+ private function loadHunk($id) {
+ $hunk = id(new DifferentialHunk())->load($id);
+ if (!$hunk) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'No hunk exists with ID "%s".',
+ $id));
+ }
+
+ return $hunk;
+ }
+
+ private function migrateHunk(DifferentialHunk $hunk, $format) {
$old_data = $hunk->getChanges();
- switch ($storage) {
+ switch ($format) {
case DifferentialHunk::DATATYPE_TEXT:
$hunk->saveAsText();
$this->logOkay(
@@ -58,7 +114,7 @@
break;
}
- $hunk = $this->loadHunk($id);
+ $hunk = $this->loadHunk($hunk->getID());
$new_data = $hunk->getChanges();
if ($old_data !== $new_data) {
@@ -66,20 +122,6 @@
pht(
'Integrity check failed: new file data differs fom old data!'));
}
-
- return 0;
- }
-
- private function loadHunk($id) {
- $hunk = id(new DifferentialHunk())->load($id);
- if (!$hunk) {
- throw new PhutilArgumentUsageException(
- pht(
- 'No hunk exists with ID "%s".',
- $id));
- }
-
- return $hunk;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 9, 10:23 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7738408
Default Alt Text
D19370.diff (3 KB)
Attached To
Mode
D19370: Add an "--all" flag to "bin/differential migrate-hunk"
Attached
Detach File
Event Timeline
Log In to Comment