From 1e488e92771a0700f0eda938805df469e40eba59 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 28 Oct 2016 15:59:26 -0700 Subject: [PATCH] When importing events, delete events which have been removed on the other end Summary: Ref T10747. If stuff has been deleted on the other calendar, delete it on ours. Test Plan: Imported with deletion, saw deletions: {F1889689} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10747 Differential Revision: https://secure.phabricator.com/D16768 --- src/__phutil_library_map__.php | 2 ++ .../PhabricatorCalendarImportEngine.php | 26 +++++++++++--- ...PhabricatorCalendarImportDeleteLogType.php | 34 +++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/applications/calendar/importlog/PhabricatorCalendarImportDeleteLogType.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c6b7b28774..b8eb474a20 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2111,6 +2111,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarImport' => 'applications/calendar/storage/PhabricatorCalendarImport.php', 'PhabricatorCalendarImportDefaultLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportDefaultLogType.php', 'PhabricatorCalendarImportDeleteController' => 'applications/calendar/controller/PhabricatorCalendarImportDeleteController.php', + 'PhabricatorCalendarImportDeleteLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportDeleteLogType.php', 'PhabricatorCalendarImportDeleteTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportDeleteTransaction.php', 'PhabricatorCalendarImportDisableController' => 'applications/calendar/controller/PhabricatorCalendarImportDisableController.php', 'PhabricatorCalendarImportDisableTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportDisableTransaction.php', @@ -6965,6 +6966,7 @@ phutil_register_library_map(array( ), 'PhabricatorCalendarImportDefaultLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportDeleteController' => 'PhabricatorCalendarController', + 'PhabricatorCalendarImportDeleteLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportDeleteTransaction' => 'PhabricatorCalendarImportTransactionType', 'PhabricatorCalendarImportDisableController' => 'PhabricatorCalendarController', 'PhabricatorCalendarImportDisableTransaction' => 'PhabricatorCalendarImportTransactionType', diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php index 1eae386869..74d3866fb7 100644 --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -409,10 +409,28 @@ abstract class PhabricatorCalendarImportEngine array()); } - // TODO: When the source is a subscription-based ICS file or some other - // similar source, we should load all events from the source here and - // destroy the ones we didn't update. These are events that have been - // deleted. + // Delete any events which are no longer present in the source. + $updated_events = mpull($update_map, null, 'getPHID'); + $source_events = id(new PhabricatorCalendarEventQuery()) + ->setViewer($viewer) + ->withImportSourcePHIDs(array($import->getPHID())) + ->execute(); + + $engine = new PhabricatorDestructionEngine(); + foreach ($source_events as $source_event) { + if (isset($updated_events[$source_event->getPHID()])) { + // We imported and updated this event, so keep it around. + continue; + } + + $import->newLogMessage( + PhabricatorCalendarImportDeleteLogType::LOGTYPE, + array( + 'name' => $source_event->getName(), + )); + + $engine->destroyObject($source_event); + } } private function getFullNodeUID(PhutilCalendarEventNode $node) { diff --git a/src/applications/calendar/importlog/PhabricatorCalendarImportDeleteLogType.php b/src/applications/calendar/importlog/PhabricatorCalendarImportDeleteLogType.php new file mode 100644 index 0000000000..04801a4612 --- /dev/null +++ b/src/applications/calendar/importlog/PhabricatorCalendarImportDeleteLogType.php @@ -0,0 +1,34 @@ +getParameter('name')); + } + + public function getDisplayIcon( + PhabricatorUser $viewer, + PhabricatorCalendarImportLog $log) { + return 'fa-times'; + } + + public function getDisplayColor( + PhabricatorUser $viewer, + PhabricatorCalendarImportLog $log) { + return 'grey'; + } + +}