Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / nuance / management / NuanceManagementImportWorkflow.php
blobb14537f885665c875f194ad3cf3db48951a67baa
1 <?php
3 final class NuanceManagementImportWorkflow
4 extends NuanceManagementWorkflow {
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.'),
18 array(
19 'name' => 'cursor',
20 'param' => 'cursor',
21 'help' => pht('Import only a particular cursor.'),
23 ));
26 public function execute(PhutilArgumentParser $args) {
27 $source = $this->loadSource($args, 'source');
29 $definition = $source->getDefinition()
30 ->setViewer($this->getViewer())
31 ->setSource($source);
33 if (!$definition->hasImportCursors()) {
34 throw new PhutilArgumentUsageException(
35 pht(
36 'This source ("%s") does not expose import cursors.',
37 $source->getName()));
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()));
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));
66 } else {
67 echo tsprintf(
68 "%s\n",
69 pht(
70 'Importing all cursors: %s.',
71 implode(', ', array_keys($cursors))));
73 echo tsprintf(
74 "%s\n",
75 pht('(Use --cursor to import only a particular cursor.)'));
78 foreach ($cursors as $cursor) {
79 $cursor->importFromSource();
82 return 0;