Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementMovePathsWorkflow.php
blobced8663b3ca421e789d06f345fe8879e89c21288
1 <?php
3 final class PhabricatorRepositoryManagementMovePathsWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('move-paths')
9 ->setSynopsis(pht('Move repository local paths.'))
10 ->setArguments(
11 array(
12 array(
13 'name' => 'from',
14 'param' => 'prefix',
15 'help' => pht('Move paths with this prefix.'),
17 array(
18 'name' => 'to',
19 'param' => 'prefix',
20 'help' => pht('Replace matching prefixes with this string.'),
22 array(
23 'name' => 'force',
24 'help' => pht('Apply changes without prompting.'),
26 ));
29 public function execute(PhutilArgumentParser $args) {
30 $console = PhutilConsole::getConsole();
32 $repos = id(new PhabricatorRepositoryQuery())
33 ->setViewer($this->getViewer())
34 ->execute();
35 if (!$repos) {
36 $console->writeErr("%s\n", pht('There are no repositories.'));
37 return 0;
40 $from = $args->getArg('from');
41 if (!strlen($from)) {
42 throw new Exception(
43 pht(
44 'You must specify a path prefix to move from with --from.'));
47 $to = $args->getArg('to');
48 if (!strlen($to)) {
49 throw new Exception(
50 pht(
51 'You must specify a path prefix to move to with --to.'));
54 $is_force = $args->getArg('force');
56 $rows = array();
58 $any_changes = false;
59 foreach ($repos as $repo) {
60 $src = $repo->getLocalPath();
62 $row = array(
63 'repository' => $repo,
64 'move' => false,
65 'monogram' => $repo->getMonogram(),
66 'src' => $src,
67 'dst' => '',
70 if (strncmp($src, $from, strlen($from))) {
71 $row['action'] = pht('Ignore');
72 } else {
73 $dst = $to.substr($src, strlen($from));
75 $row['action'] = tsprintf('**%s**', pht('Move'));
76 $row['dst'] = $dst;
77 $row['move'] = true;
78 $any_changes = true;
81 $rows[] = $row;
84 $table = id(new PhutilConsoleTable())
85 ->addColumn(
86 'action',
87 array(
88 'title' => pht('Action'),
90 ->addColumn(
91 'monogram',
92 array(
93 'title' => pht('Repository'),
95 ->addColumn(
96 'src',
97 array(
98 'title' => pht('Src'),
100 ->addColumn(
101 'dst',
102 array(
103 'title' => pht('Dst'),
105 ->setBorders(true);
107 foreach ($rows as $row) {
108 $display = array_select_keys(
109 $row,
110 array(
111 'action',
112 'monogram',
113 'src',
114 'dst',
116 $table->addRow($display);
119 $table->draw();
121 if (!$any_changes) {
122 $console->writeOut(pht('No matching repositories.')."\n");
123 return 0;
126 $prompt = pht('Apply these changes?');
127 if (!$is_force && !phutil_console_confirm($prompt)) {
128 throw new Exception(pht('Declining to apply changes.'));
131 foreach ($rows as $row) {
132 if (empty($row['move'])) {
133 continue;
136 $repo = $row['repository'];
138 queryfx(
139 $repo->establishConnection('w'),
140 'UPDATE %T SET localPath = %s WHERE id = %d',
141 $repo->getTableName(),
142 $row['dst'],
143 $repo->getID());
146 $console->writeOut(pht('Applied changes.')."\n");
147 return 0;