@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add an "--all" flag to "bin/differential migrate-hunk"

Summary:
Depends on D19369. Ref T13120. Add a flag to migrate every hunk.

This isn't terribly useful on its own, but I'm going to add an `--auto` flag next so that you can run `--auto --all` to migrate hunks to the preferred hunk format.

Test Plan: Ran `bin/differential migrate-hunk --all --to text`.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13120

Differential Revision: https://secure.phabricator.com/D19370

+62 -20
+62 -20
src/applications/differential/management/PhabricatorDifferentialMigrateHunkWorkflow.php
··· 6 6 protected function didConstruct() { 7 7 $this 8 8 ->setName('migrate-hunk') 9 - ->setExamples('**migrate-hunk** --id __hunk__ --to __storage__') 9 + ->setExamples( 10 + "**migrate-hunk** --id __hunk__ --to __storage__\n". 11 + "**migrate-hunk** --all") 10 12 ->setSynopsis(pht('Migrate storage engines for a hunk.')) 11 13 ->setArguments( 12 14 array( ··· 20 22 'param' => 'storage', 21 23 'help' => pht('Storage engine to migrate to.'), 22 24 ), 25 + array( 26 + 'name' => 'all', 27 + 'help' => pht('Migrate all hunks.'), 28 + ), 23 29 )); 24 30 } 25 31 26 32 public function execute(PhutilArgumentParser $args) { 27 33 $id = $args->getArg('id'); 28 - if (!$id) { 34 + $is_all = $args->getArg('all'); 35 + 36 + if ($is_all && $id) { 29 37 throw new PhutilArgumentUsageException( 30 - pht('Specify a hunk to migrate with --id.')); 38 + pht( 39 + 'Options "--all" (to migrate all hunks) and "--id" (to migrate a '. 40 + 'specific hunk) are mutually exclusive.')); 41 + } else if (!$is_all && !$id) { 42 + throw new PhutilArgumentUsageException( 43 + pht( 44 + 'Specify a hunk to migrate with "--id", or migrate all hunks '. 45 + 'with "--all".')); 31 46 } 32 47 33 48 $storage = $args->getArg('to'); ··· 40 55 pht('Specify a hunk storage engine with --to.')); 41 56 } 42 57 43 - $hunk = $this->loadHunk($id); 58 + if ($id) { 59 + $hunk = $this->loadHunk($id); 60 + $hunks = array($hunk); 61 + } else { 62 + $hunks = new LiskMigrationIterator(new DifferentialHunk()); 63 + } 64 + 65 + foreach ($hunks as $hunk) { 66 + try { 67 + $this->migrateHunk($hunk, $storage); 68 + } catch (Exception $ex) { 69 + // If we're migrating a single hunk, just throw the exception. If 70 + // we're migrating multiple hunks, warn but continue. 71 + if ($id) { 72 + throw $ex; 73 + } 74 + 75 + $this->logWarn( 76 + pht('WARN'), 77 + pht( 78 + 'Failed to migrate hunk %d: %s', 79 + $hunk->getID(), 80 + $ex->getMessage())); 81 + } 82 + } 83 + 84 + return 0; 85 + } 86 + 87 + private function loadHunk($id) { 88 + $hunk = id(new DifferentialHunk())->load($id); 89 + if (!$hunk) { 90 + throw new PhutilArgumentUsageException( 91 + pht( 92 + 'No hunk exists with ID "%s".', 93 + $id)); 94 + } 95 + 96 + return $hunk; 97 + } 98 + 99 + private function migrateHunk(DifferentialHunk $hunk, $format) { 44 100 $old_data = $hunk->getChanges(); 45 101 46 - switch ($storage) { 102 + switch ($format) { 47 103 case DifferentialHunk::DATATYPE_TEXT: 48 104 $hunk->saveAsText(); 49 105 $this->logOkay( ··· 58 114 break; 59 115 } 60 116 61 - $hunk = $this->loadHunk($id); 117 + $hunk = $this->loadHunk($hunk->getID()); 62 118 $new_data = $hunk->getChanges(); 63 119 64 120 if ($old_data !== $new_data) { ··· 66 122 pht( 67 123 'Integrity check failed: new file data differs fom old data!')); 68 124 } 69 - 70 - return 0; 71 - } 72 - 73 - private function loadHunk($id) { 74 - $hunk = id(new DifferentialHunk())->load($id); 75 - if (!$hunk) { 76 - throw new PhutilArgumentUsageException( 77 - pht( 78 - 'No hunk exists with ID "%s".', 79 - $id)); 80 - } 81 - 82 - return $hunk; 83 125 } 84 126 85 127