@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reject high-frequency and out-of-range events during import

Summary: Ref T10747. Don't let users import SECONDLY events, or events outside of the range of a signed 32-bit integer (these are likely not too hard to support, but they're more headaches than we need right now).

Test Plan: Tried to import these no-good problem events, got helpful import errors.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16716

+137
+4
src/__phutil_library_map__.php
··· 2113 2113 'PhabricatorCalendarImportEditor' => 'applications/calendar/editor/PhabricatorCalendarImportEditor.php', 2114 2114 'PhabricatorCalendarImportEmptyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEmptyLogType.php', 2115 2115 'PhabricatorCalendarImportEngine' => 'applications/calendar/import/PhabricatorCalendarImportEngine.php', 2116 + 'PhabricatorCalendarImportEpochLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php', 2117 + 'PhabricatorCalendarImportFrequencyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php', 2116 2118 'PhabricatorCalendarImportICSFileTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php', 2117 2119 'PhabricatorCalendarImportIgnoredNodeLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportIgnoredNodeLogType.php', 2118 2120 'PhabricatorCalendarImportListController' => 'applications/calendar/controller/PhabricatorCalendarImportListController.php', ··· 6940 6942 'PhabricatorCalendarImportEditor' => 'PhabricatorApplicationTransactionEditor', 6941 6943 'PhabricatorCalendarImportEmptyLogType' => 'PhabricatorCalendarImportLogType', 6942 6944 'PhabricatorCalendarImportEngine' => 'Phobject', 6945 + 'PhabricatorCalendarImportEpochLogType' => 'PhabricatorCalendarImportLogType', 6946 + 'PhabricatorCalendarImportFrequencyLogType' => 'PhabricatorCalendarImportLogType', 6943 6947 'PhabricatorCalendarImportICSFileTransaction' => 'PhabricatorCalendarImportTransactionType', 6944 6948 'PhabricatorCalendarImportIgnoredNodeLogType' => 'PhabricatorCalendarImportLogType', 6945 6949 'PhabricatorCalendarImportListController' => 'PhabricatorCalendarController',
+61
src/applications/calendar/import/PhabricatorCalendarImportEngine.php
··· 63 63 } 64 64 } 65 65 66 + // Reject events which have dates outside of the range of a signed 67 + // 32-bit integer. We'll need to accommodate a wider range of events 68 + // eventually, but have about 20 years until it's an issue and we'll 69 + // all be dead by then. 70 + foreach ($nodes as $key => $node) { 71 + $dates = array(); 72 + $dates[] = $node->getStartDateTime(); 73 + $dates[] = $node->getEndDateTime(); 74 + $dates[] = $node->getCreatedDateTime(); 75 + $dates[] = $node->getModifiedDateTime(); 76 + $rrule = $node->getRecurrenceRule(); 77 + if ($rrule) { 78 + $dates[] = $rrule->getUntil(); 79 + } 80 + 81 + $bad_date = false; 82 + foreach ($dates as $date) { 83 + if ($date === null) { 84 + continue; 85 + } 86 + 87 + $year = $date->getYear(); 88 + if ($year < 1970 || $year > 2037) { 89 + $bad_date = true; 90 + break; 91 + } 92 + } 93 + 94 + if ($bad_date) { 95 + $import->newLogMessage( 96 + PhabricatorCalendarImportEpochLogType::LOGTYPE, 97 + array()); 98 + unset($nodes[$key]); 99 + } 100 + } 101 + 102 + // Reject events which occur too frequently. Users do not normally define 103 + // these events and the UI and application make many assumptions which are 104 + // incompatible with events recurring once per second. 105 + foreach ($nodes as $key => $node) { 106 + $rrule = $node->getRecurrenceRule(); 107 + if (!$rrule) { 108 + // This is not a recurring event, so we don't need to check the 109 + // frequency. 110 + continue; 111 + } 112 + $scale = $rrule->getFrequencyScale(); 113 + if ($scale >= PhutilCalendarRecurrenceRule::SCALE_DAILY) { 114 + // This is a daily, weekly, monthly, or yearly event. These are 115 + // supported. 116 + } else { 117 + // This is an hourly, minutely, or secondly event. 118 + $import->newLogMessage( 119 + PhabricatorCalendarImportFrequencyLogType::LOGTYPE, 120 + array( 121 + 'frequency' => $rrule->getFrequency(), 122 + )); 123 + unset($nodes[$key]); 124 + } 125 + } 126 + 66 127 $node_map = array(); 67 128 foreach ($nodes as $node) { 68 129 $full_uid = $this->getFullNodeUID($node);
+34
src/applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportEpochLogType 4 + extends PhabricatorCalendarImportLogType { 5 + 6 + const LOGTYPE = 'epoch'; 7 + 8 + public function getDisplayType( 9 + PhabricatorUser $viewer, 10 + PhabricatorCalendarImportLog $log) { 11 + return pht('Out of Range'); 12 + } 13 + 14 + public function getDisplayDescription( 15 + PhabricatorUser $viewer, 16 + PhabricatorCalendarImportLog $log) { 17 + return pht( 18 + 'Ignored an event with an out-of-range date. Only dates between '. 19 + '1970 and 2037 are supported.'); 20 + } 21 + 22 + public function getDisplayIcon( 23 + PhabricatorUser $viewer, 24 + PhabricatorCalendarImportLog $log) { 25 + return 'fa-clock-o'; 26 + } 27 + 28 + public function getDisplayColor( 29 + PhabricatorUser $viewer, 30 + PhabricatorCalendarImportLog $log) { 31 + return 'red'; 32 + } 33 + 34 + }
+38
src/applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportFrequencyLogType 4 + extends PhabricatorCalendarImportLogType { 5 + 6 + const LOGTYPE = 'frequency'; 7 + 8 + public function getDisplayType( 9 + PhabricatorUser $viewer, 10 + PhabricatorCalendarImportLog $log) { 11 + return pht('Too Frequent'); 12 + } 13 + 14 + public function getDisplayDescription( 15 + PhabricatorUser $viewer, 16 + PhabricatorCalendarImportLog $log) { 17 + 18 + $frequency = $log->getParameter('frequency'); 19 + 20 + return pht( 21 + 'Ignored an event with an unsupported frequency rule ("%s"). Events '. 22 + 'which repeat more frequently than daily are not supported.', 23 + $frequency); 24 + } 25 + 26 + public function getDisplayIcon( 27 + PhabricatorUser $viewer, 28 + PhabricatorCalendarImportLog $log) { 29 + return 'fa-clock-o'; 30 + } 31 + 32 + public function getDisplayColor( 33 + PhabricatorUser $viewer, 34 + PhabricatorCalendarImportLog $log) { 35 + return 'red'; 36 + } 37 + 38 + }