Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/management/PhabricatorCalendarManagementReloadWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarManagementReloadWorkflow
4
extends PhabricatorCalendarManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('reload')
9
->setExamples('**reload** [options] __id__ ...')
10
->setSynopsis(
11
pht(
12
'Reload event imports from the command line. Useful for '.
13
'testing and debugging importers.'))
14
->setArguments(
15
array(
16
array(
17
'name' => 'ids',
18
'wildcard' => true,
19
'help' => pht('List of import IDs to reload.'),
20
),
21
));
22
}
23
24
public function execute(PhutilArgumentParser $args) {
25
$viewer = $this->getViewer();
26
27
$ids = $args->getArg('ids');
28
if (!$ids) {
29
throw new PhutilArgumentUsageException(
30
pht('Specify at least one import ID to reload.'));
31
}
32
33
$imports = id(new PhabricatorCalendarImportQuery())
34
->setViewer($viewer)
35
->withIDs($ids)
36
->execute();
37
$imports = mpull($imports, null, 'getID');
38
foreach ($ids as $id) {
39
if (empty($imports[$id])) {
40
throw new PhutilArgumentUsageException(
41
pht(
42
'Unable to load Calendar import with ID "%s".',
43
$id));
44
}
45
}
46
47
$imports = array_select_keys($imports, $ids);
48
49
foreach ($imports as $import) {
50
echo tsprintf(
51
"%s\n",
52
pht(
53
'Importing "%s"...',
54
$import->getDisplayName()));
55
56
$engine = $import->getEngine();
57
58
$engine->importEventsFromSource($viewer, $import, false);
59
}
60
61
echo tsprintf(
62
"%s\n",
63
pht('Done.'));
64
65
return 0;
66
}
67
68
}
69
70