diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1427739390..a8901dadc1 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php index ca1885a4af..35e94634fe 100644 --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -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); diff --git a/src/applications/calendar/management/PhabricatorCalendarManagementReloadWorkflow.php b/src/applications/calendar/management/PhabricatorCalendarManagementReloadWorkflow.php new file mode 100644 index 0000000000..b1020c9e2f --- /dev/null +++ b/src/applications/calendar/management/PhabricatorCalendarManagementReloadWorkflow.php @@ -0,0 +1,68 @@ +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; + } + +} diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index b36ff628d4..2834228ec9 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -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)