mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01:00
Provide a standalone bin/calendar reload ...
workflow for testing/debugging
Summary: Ref T11801. This makes testing/debugging a little easier. Also fix some inconsistencies with `importAuthorPHID` handling -- it should be the import's author PHID in all cases, so we update imported events properly. Test Plan: Imported a French holiday with `bin/calendar reload ...`. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11801 Differential Revision: https://secure.phabricator.com/D16814
This commit is contained in:
parent
2f93ce4c25
commit
7ddd570fa5
4 changed files with 80 additions and 3 deletions
|
@ -2157,6 +2157,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarImportUpdateLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportUpdateLogType.php',
|
||||
'PhabricatorCalendarImportViewController' => 'applications/calendar/controller/PhabricatorCalendarImportViewController.php',
|
||||
'PhabricatorCalendarManagementNotifyWorkflow' => 'applications/calendar/management/PhabricatorCalendarManagementNotifyWorkflow.php',
|
||||
'PhabricatorCalendarManagementReloadWorkflow' => 'applications/calendar/management/PhabricatorCalendarManagementReloadWorkflow.php',
|
||||
'PhabricatorCalendarManagementWorkflow' => 'applications/calendar/management/PhabricatorCalendarManagementWorkflow.php',
|
||||
'PhabricatorCalendarNotification' => 'applications/calendar/storage/PhabricatorCalendarNotification.php',
|
||||
'PhabricatorCalendarNotificationEngine' => 'applications/calendar/notifications/PhabricatorCalendarNotificationEngine.php',
|
||||
|
@ -7025,6 +7026,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarImportUpdateLogType' => 'PhabricatorCalendarImportLogType',
|
||||
'PhabricatorCalendarImportViewController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarManagementNotifyWorkflow' => 'PhabricatorCalendarManagementWorkflow',
|
||||
'PhabricatorCalendarManagementReloadWorkflow' => 'PhabricatorCalendarManagementWorkflow',
|
||||
'PhabricatorCalendarManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorCalendarNotification' => 'PhabricatorCalendarDAO',
|
||||
'PhabricatorCalendarNotificationEngine' => 'Phobject',
|
||||
|
|
|
@ -199,7 +199,7 @@ abstract class PhabricatorCalendarImportEngine
|
|||
if ($node_map) {
|
||||
$events = id(new PhabricatorCalendarEventQuery())
|
||||
->setViewer($viewer)
|
||||
->withImportAuthorPHIDs(array($viewer->getPHID()))
|
||||
->withImportAuthorPHIDs(array($import->getAuthorPHID()))
|
||||
->withImportUIDs(array_keys($node_map))
|
||||
->execute();
|
||||
$events = mpull($events, null, 'getImportUID');
|
||||
|
@ -218,7 +218,7 @@ abstract class PhabricatorCalendarImportEngine
|
|||
}
|
||||
|
||||
$event
|
||||
->setImportAuthorPHID($viewer->getPHID())
|
||||
->setImportAuthorPHID($import->getAuthorPHID())
|
||||
->setImportSourcePHID($import->getPHID())
|
||||
->setImportUID($full_uid)
|
||||
->attachImportSource($import);
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarManagementReloadWorkflow
|
||||
extends PhabricatorCalendarManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('reload')
|
||||
->setExamples('**reload** [options] __id__ ...')
|
||||
->setSynopsis(
|
||||
pht(
|
||||
'Reload event imports from the command line. Useful for '.
|
||||
'testing and debugging importers.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'ids',
|
||||
'wildcard' => true,
|
||||
'help' => pht('List of import IDs to reload.'),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$ids = $args->getArg('ids');
|
||||
if (!$ids) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('Specify at least one import ID to reload.'));
|
||||
}
|
||||
|
||||
$imports = id(new PhabricatorCalendarImportQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs($ids)
|
||||
->execute();
|
||||
$imports = mpull($imports, null, 'getID');
|
||||
foreach ($ids as $id) {
|
||||
if (empty($imports[$id])) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'Unable to load Calendar import with ID "%s".',
|
||||
$id));
|
||||
}
|
||||
}
|
||||
|
||||
$imports = array_select_keys($imports, $ids);
|
||||
|
||||
foreach ($imports as $import) {
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht(
|
||||
'Importing "%s"...',
|
||||
$import->getDisplayName()));
|
||||
|
||||
$engine = $import->getEngine();
|
||||
|
||||
$engine->importEventsFromSource($viewer, $import, false);
|
||||
}
|
||||
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht('Done.'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -75,9 +75,16 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
$now);
|
||||
list($datetime_start, $datetime_end) = $datetime_defaults;
|
||||
|
||||
// When importing events from a context like "bin/calendar reload", we may
|
||||
// be acting as the omnipotent user.
|
||||
$host_phid = $actor->getPHID();
|
||||
if (!$host_phid) {
|
||||
$host_phid = $app->getPHID();
|
||||
}
|
||||
|
||||
return id(new PhabricatorCalendarEvent())
|
||||
->setDescription('')
|
||||
->setHostPHID($actor->getPHID())
|
||||
->setHostPHID($host_phid)
|
||||
->setIsCancelled(0)
|
||||
->setIsAllDay(0)
|
||||
->setIsStub(0)
|
||||
|
|
Loading…
Reference in a new issue