Path: blob/master/src/applications/nuance/management/NuanceManagementImportWorkflow.php
12256 views
<?php12final class NuanceManagementImportWorkflow3extends NuanceManagementWorkflow {45protected function didConstruct() {6$this7->setName('import')8->setExamples('**import** --source __source__ [__options__]')9->setSynopsis(pht('Import data from a source.'))10->setArguments(11array(12array(13'name' => 'source',14'param' => 'source',15'help' => pht('Choose which source to import.'),16),17array(18'name' => 'cursor',19'param' => 'cursor',20'help' => pht('Import only a particular cursor.'),21),22));23}2425public function execute(PhutilArgumentParser $args) {26$source = $this->loadSource($args, 'source');2728$definition = $source->getDefinition()29->setViewer($this->getViewer())30->setSource($source);3132if (!$definition->hasImportCursors()) {33throw new PhutilArgumentUsageException(34pht(35'This source ("%s") does not expose import cursors.',36$source->getName()));37}3839$cursors = $definition->getImportCursors();40if (!$cursors) {41throw new PhutilArgumentUsageException(42pht(43'This source ("%s") does not have any import cursors.',44$source->getName()));45}4647$select = $args->getArg('cursor');48if (strlen($select)) {49if (empty($cursors[$select])) {50throw new PhutilArgumentUsageException(51pht(52'This source ("%s") does not have a "%s" cursor. Available '.53'cursors: %s.',54$source->getName(),55$select,56implode(', ', array_keys($cursors))));57} else {58echo tsprintf(59"%s\n",60pht(61'Importing cursor "%s" only.',62$select));63$cursors = array_select_keys($cursors, array($select));64}65} else {66echo tsprintf(67"%s\n",68pht(69'Importing all cursors: %s.',70implode(', ', array_keys($cursors))));7172echo tsprintf(73"%s\n",74pht('(Use --cursor to import only a particular cursor.)'));75}7677foreach ($cursors as $cursor) {78$cursor->importFromSource();79}8081return 0;82}8384}858687