@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.

When import fails because we can't parse an ICS file, show it nicely

Summary:
Ref T10747. When we hit an ICS parser error, render it into a log instead of fataling.

(This will be more important in the future with subscription-based URL ICS import.)

Test Plan: {F1875292}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

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

+78 -22
+2
src/__phutil_library_map__.php
··· 2118 2118 'PhabricatorCalendarImportEpochLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php', 2119 2119 'PhabricatorCalendarImportFrequencyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php', 2120 2120 'PhabricatorCalendarImportICSFileTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php', 2121 + 'PhabricatorCalendarImportICSLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportICSLogType.php', 2121 2122 'PhabricatorCalendarImportIgnoredNodeLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportIgnoredNodeLogType.php', 2122 2123 'PhabricatorCalendarImportListController' => 'applications/calendar/controller/PhabricatorCalendarImportListController.php', 2123 2124 'PhabricatorCalendarImportLog' => 'applications/calendar/storage/PhabricatorCalendarImportLog.php', ··· 6952 6953 'PhabricatorCalendarImportEpochLogType' => 'PhabricatorCalendarImportLogType', 6953 6954 'PhabricatorCalendarImportFrequencyLogType' => 'PhabricatorCalendarImportLogType', 6954 6955 'PhabricatorCalendarImportICSFileTransaction' => 'PhabricatorCalendarImportTransactionType', 6956 + 'PhabricatorCalendarImportICSLogType' => 'PhabricatorCalendarImportLogType', 6955 6957 'PhabricatorCalendarImportIgnoredNodeLogType' => 'PhabricatorCalendarImportLogType', 6956 6958 'PhabricatorCalendarImportListController' => 'PhabricatorCalendarController', 6957 6959 'PhabricatorCalendarImportLog' => array(
+18 -2
src/applications/calendar/import/PhabricatorCalendarICSImportEngine.php
··· 62 62 63 63 $data = $file->loadFileData(); 64 64 65 - $parser = id(new PhutilICSParser()); 65 + $parser = new PhutilICSParser(); 66 66 67 - $document = $parser->parseICSData($data); 67 + try { 68 + $document = $parser->parseICSData($data); 69 + } catch (PhutilICSParserException $ex) { 70 + // TODO: In theory, it would be nice to store these in a fully abstract 71 + // form so they can be translated at display time. As-is, we'll store the 72 + // error messages in whatever language we were using when the parser 73 + // failure occurred. 74 + 75 + $import->newLogMessage( 76 + PhabricatorCalendarImportICSLogType::LOGTYPE, 77 + array( 78 + 'ics.code' => $ex->getParserFailureCode(), 79 + 'ics.message' => $ex->getMessage(), 80 + )); 81 + 82 + $document = null; 83 + } 68 84 69 85 return $this->importEventDocument($viewer, $import, $document); 70 86 }
+15 -13
src/applications/calendar/import/PhabricatorCalendarImportEngine.php
··· 42 42 final protected function importEventDocument( 43 43 PhabricatorUser $viewer, 44 44 PhabricatorCalendarImport $import, 45 - PhutilCalendarRootNode $root) { 45 + PhutilCalendarRootNode $root = null) { 46 46 47 47 $event_type = PhutilCalendarEventNode::NODETYPE; 48 48 49 49 $nodes = array(); 50 - foreach ($root->getChildren() as $document) { 51 - foreach ($document->getChildren() as $node) { 52 - $node_type = $node->getNodeType(); 53 - if ($node_type != $event_type) { 54 - $import->newLogMessage( 55 - PhabricatorCalendarImportIgnoredNodeLogType::LOGTYPE, 56 - array( 57 - 'node.type' => $node_type, 58 - )); 59 - continue; 60 - } 50 + if ($root) { 51 + foreach ($root->getChildren() as $document) { 52 + foreach ($document->getChildren() as $node) { 53 + $node_type = $node->getNodeType(); 54 + if ($node_type != $event_type) { 55 + $import->newLogMessage( 56 + PhabricatorCalendarImportIgnoredNodeLogType::LOGTYPE, 57 + array( 58 + 'node.type' => $node_type, 59 + )); 60 + continue; 61 + } 61 62 62 - $nodes[] = $node; 63 + $nodes[] = $node; 64 + } 63 65 } 64 66 } 65 67
+36
src/applications/calendar/importlog/PhabricatorCalendarImportICSLogType.php
··· 1 + <?php 2 + 3 + final class PhabricatorCalendarImportICSLogType 4 + extends PhabricatorCalendarImportLogType { 5 + 6 + const LOGTYPE = 'ics'; 7 + 8 + public function getDisplayType( 9 + PhabricatorUser $viewer, 10 + PhabricatorCalendarImportLog $log) { 11 + return pht('ICS Parse Error'); 12 + } 13 + 14 + public function getDisplayDescription( 15 + PhabricatorUser $viewer, 16 + PhabricatorCalendarImportLog $log) { 17 + return pht( 18 + 'Failed to parse ICS file ("%s"): %s', 19 + $log->getParameter('ics.code'), 20 + $log->getParameter('ics.message')); 21 + } 22 + 23 + 24 + public function getDisplayIcon( 25 + PhabricatorUser $viewer, 26 + PhabricatorCalendarImportLog $log) { 27 + return 'fa-file'; 28 + } 29 + 30 + public function getDisplayColor( 31 + PhabricatorUser $viewer, 32 + PhabricatorCalendarImportLog $log) { 33 + return 'red'; 34 + } 35 + 36 + }
+7 -7
src/applications/calendar/view/PhabricatorCalendarImportLogView.php
··· 48 48 : null), 49 49 id(new PHUIIconView())->setIcon($icon, $color), 50 50 $name, 51 - $description, 51 + phutil_escape_html_newlines($description), 52 52 phabricator_datetime($log->getDateCreated(), $viewer), 53 53 ); 54 54 } ··· 70 70 )) 71 71 ->setColumnClasses( 72 72 array( 73 - null, 74 - null, 75 - null, 76 - 'pri', 77 - 'wide', 78 - null, 73 + 'top', 74 + 'top', 75 + 'top', 76 + 'top pri', 77 + 'top wide', 78 + 'top', 79 79 )); 80 80 81 81 return $table;