diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2113,6 +2113,8 @@ 'PhabricatorCalendarImportEditor' => 'applications/calendar/editor/PhabricatorCalendarImportEditor.php', 'PhabricatorCalendarImportEmptyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEmptyLogType.php', 'PhabricatorCalendarImportEngine' => 'applications/calendar/import/PhabricatorCalendarImportEngine.php', + 'PhabricatorCalendarImportEpochLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php', + 'PhabricatorCalendarImportFrequencyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php', 'PhabricatorCalendarImportICSFileTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php', 'PhabricatorCalendarImportIgnoredNodeLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportIgnoredNodeLogType.php', 'PhabricatorCalendarImportListController' => 'applications/calendar/controller/PhabricatorCalendarImportListController.php', @@ -6940,6 +6942,8 @@ 'PhabricatorCalendarImportEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorCalendarImportEmptyLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportEngine' => 'Phobject', + 'PhabricatorCalendarImportEpochLogType' => 'PhabricatorCalendarImportLogType', + 'PhabricatorCalendarImportFrequencyLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportICSFileTransaction' => 'PhabricatorCalendarImportTransactionType', 'PhabricatorCalendarImportIgnoredNodeLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportListController' => 'PhabricatorCalendarController', diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -63,6 +63,67 @@ } } + // Reject events which have dates outside of the range of a signed + // 32-bit integer. We'll need to accommodate a wider range of events + // eventually, but have about 20 years until it's an issue and we'll + // all be dead by then. + foreach ($nodes as $key => $node) { + $dates = array(); + $dates[] = $node->getStartDateTime(); + $dates[] = $node->getEndDateTime(); + $dates[] = $node->getCreatedDateTime(); + $dates[] = $node->getModifiedDateTime(); + $rrule = $node->getRecurrenceRule(); + if ($rrule) { + $dates[] = $rrule->getUntil(); + } + + $bad_date = false; + foreach ($dates as $date) { + if ($date === null) { + continue; + } + + $year = $date->getYear(); + if ($year < 1970 || $year > 2037) { + $bad_date = true; + break; + } + } + + if ($bad_date) { + $import->newLogMessage( + PhabricatorCalendarImportEpochLogType::LOGTYPE, + array()); + unset($nodes[$key]); + } + } + + // Reject events which occur too frequently. Users do not normally define + // these events and the UI and application make many assumptions which are + // incompatible with events recurring once per second. + foreach ($nodes as $key => $node) { + $rrule = $node->getRecurrenceRule(); + if (!$rrule) { + // This is not a recurring event, so we don't need to check the + // frequency. + continue; + } + $scale = $rrule->getFrequencyScale(); + if ($scale >= PhutilCalendarRecurrenceRule::SCALE_DAILY) { + // This is a daily, weekly, monthly, or yearly event. These are + // supported. + } else { + // This is an hourly, minutely, or secondly event. + $import->newLogMessage( + PhabricatorCalendarImportFrequencyLogType::LOGTYPE, + array( + 'frequency' => $rrule->getFrequency(), + )); + unset($nodes[$key]); + } + } + $node_map = array(); foreach ($nodes as $node) { $full_uid = $this->getFullNodeUID($node); diff --git a/src/applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php b/src/applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php new file mode 100644 --- /dev/null +++ b/src/applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php @@ -0,0 +1,34 @@ +getParameter('frequency'); + + return pht( + 'Ignored an event with an unsupported frequency rule ("%s"). Events '. + 'which repeat more frequently than daily are not supported.', + $frequency); + } + + public function getDisplayIcon( + PhabricatorUser $viewer, + PhabricatorCalendarImportLog $log) { + return 'fa-clock-o'; + } + + public function getDisplayColor( + PhabricatorUser $viewer, + PhabricatorCalendarImportLog $log) { + return 'red'; + } + +}