@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<?php
2
3final class NuanceManagementImportWorkflow
4 extends NuanceManagementWorkflow {
5
6 protected function didConstruct() {
7 $this
8 ->setName('import')
9 ->setExamples('**import** --source __source__ [__options__]')
10 ->setSynopsis(pht('Import data from a source.'))
11 ->setArguments(
12 array(
13 array(
14 'name' => 'source',
15 'param' => 'source',
16 'help' => pht('Choose which source to import.'),
17 ),
18 array(
19 'name' => 'cursor',
20 'param' => 'cursor',
21 'help' => pht('Import only a particular cursor.'),
22 ),
23 ));
24 }
25
26 public function execute(PhutilArgumentParser $args) {
27 $source = $this->loadSource($args, 'source');
28
29 $definition = $source->getDefinition()
30 ->setViewer($this->getViewer())
31 ->setSource($source);
32
33 if (!$definition->hasImportCursors()) {
34 throw new PhutilArgumentUsageException(
35 pht(
36 'This source ("%s") does not expose import cursors.',
37 $source->getName()));
38 }
39
40 $cursors = $definition->getImportCursors();
41 if (!$cursors) {
42 throw new PhutilArgumentUsageException(
43 pht(
44 'This source ("%s") does not have any import cursors.',
45 $source->getName()));
46 }
47
48 $select = $args->getArg('cursor');
49 if (strlen($select)) {
50 if (empty($cursors[$select])) {
51 throw new PhutilArgumentUsageException(
52 pht(
53 'This source ("%s") does not have a "%s" cursor. Available '.
54 'cursors: %s.',
55 $source->getName(),
56 $select,
57 implode(', ', array_keys($cursors))));
58 } else {
59 echo tsprintf(
60 "%s\n",
61 pht(
62 'Importing cursor "%s" only.',
63 $select));
64 $cursors = array_select_keys($cursors, array($select));
65 }
66 } else {
67 echo tsprintf(
68 "%s\n",
69 pht(
70 'Importing all cursors: %s.',
71 implode(', ', array_keys($cursors))));
72
73 echo tsprintf(
74 "%s\n",
75 pht('(Use --cursor to import only a particular cursor.)'));
76 }
77
78 foreach ($cursors as $cursor) {
79 $cursor->importFromSource();
80 }
81
82 return 0;
83 }
84
85}