1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

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
This commit is contained in:
epriestley 2016-10-18 13:47:41 -07:00
parent b47a42bf55
commit 67cb277bed
5 changed files with 78 additions and 22 deletions

View file

@ -2118,6 +2118,7 @@ phutil_register_library_map(array(
'PhabricatorCalendarImportEpochLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php', 'PhabricatorCalendarImportEpochLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportEpochLogType.php',
'PhabricatorCalendarImportFrequencyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php', 'PhabricatorCalendarImportFrequencyLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportFrequencyLogType.php',
'PhabricatorCalendarImportICSFileTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php', 'PhabricatorCalendarImportICSFileTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php',
'PhabricatorCalendarImportICSLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportICSLogType.php',
'PhabricatorCalendarImportIgnoredNodeLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportIgnoredNodeLogType.php', 'PhabricatorCalendarImportIgnoredNodeLogType' => 'applications/calendar/importlog/PhabricatorCalendarImportIgnoredNodeLogType.php',
'PhabricatorCalendarImportListController' => 'applications/calendar/controller/PhabricatorCalendarImportListController.php', 'PhabricatorCalendarImportListController' => 'applications/calendar/controller/PhabricatorCalendarImportListController.php',
'PhabricatorCalendarImportLog' => 'applications/calendar/storage/PhabricatorCalendarImportLog.php', 'PhabricatorCalendarImportLog' => 'applications/calendar/storage/PhabricatorCalendarImportLog.php',
@ -6952,6 +6953,7 @@ phutil_register_library_map(array(
'PhabricatorCalendarImportEpochLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportEpochLogType' => 'PhabricatorCalendarImportLogType',
'PhabricatorCalendarImportFrequencyLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportFrequencyLogType' => 'PhabricatorCalendarImportLogType',
'PhabricatorCalendarImportICSFileTransaction' => 'PhabricatorCalendarImportTransactionType', 'PhabricatorCalendarImportICSFileTransaction' => 'PhabricatorCalendarImportTransactionType',
'PhabricatorCalendarImportICSLogType' => 'PhabricatorCalendarImportLogType',
'PhabricatorCalendarImportIgnoredNodeLogType' => 'PhabricatorCalendarImportLogType', 'PhabricatorCalendarImportIgnoredNodeLogType' => 'PhabricatorCalendarImportLogType',
'PhabricatorCalendarImportListController' => 'PhabricatorCalendarController', 'PhabricatorCalendarImportListController' => 'PhabricatorCalendarController',
'PhabricatorCalendarImportLog' => array( 'PhabricatorCalendarImportLog' => array(

View file

@ -62,9 +62,25 @@ final class PhabricatorCalendarICSImportEngine
$data = $file->loadFileData(); $data = $file->loadFileData();
$parser = id(new PhutilICSParser()); $parser = new PhutilICSParser();
try {
$document = $parser->parseICSData($data); $document = $parser->parseICSData($data);
} catch (PhutilICSParserException $ex) {
// TODO: In theory, it would be nice to store these in a fully abstract
// form so they can be translated at display time. As-is, we'll store the
// error messages in whatever language we were using when the parser
// failure occurred.
$import->newLogMessage(
PhabricatorCalendarImportICSLogType::LOGTYPE,
array(
'ics.code' => $ex->getParserFailureCode(),
'ics.message' => $ex->getMessage(),
));
$document = null;
}
return $this->importEventDocument($viewer, $import, $document); return $this->importEventDocument($viewer, $import, $document);
} }

View file

@ -42,11 +42,12 @@ abstract class PhabricatorCalendarImportEngine
final protected function importEventDocument( final protected function importEventDocument(
PhabricatorUser $viewer, PhabricatorUser $viewer,
PhabricatorCalendarImport $import, PhabricatorCalendarImport $import,
PhutilCalendarRootNode $root) { PhutilCalendarRootNode $root = null) {
$event_type = PhutilCalendarEventNode::NODETYPE; $event_type = PhutilCalendarEventNode::NODETYPE;
$nodes = array(); $nodes = array();
if ($root) {
foreach ($root->getChildren() as $document) { foreach ($root->getChildren() as $document) {
foreach ($document->getChildren() as $node) { foreach ($document->getChildren() as $node) {
$node_type = $node->getNodeType(); $node_type = $node->getNodeType();
@ -62,6 +63,7 @@ abstract class PhabricatorCalendarImportEngine
$nodes[] = $node; $nodes[] = $node;
} }
} }
}
// Reject events which have dates outside of the range of a signed // 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 // 32-bit integer. We'll need to accommodate a wider range of events

View file

@ -0,0 +1,36 @@
<?php
final class PhabricatorCalendarImportICSLogType
extends PhabricatorCalendarImportLogType {
const LOGTYPE = 'ics';
public function getDisplayType(
PhabricatorUser $viewer,
PhabricatorCalendarImportLog $log) {
return pht('ICS Parse Error');
}
public function getDisplayDescription(
PhabricatorUser $viewer,
PhabricatorCalendarImportLog $log) {
return pht(
'Failed to parse ICS file ("%s"): %s',
$log->getParameter('ics.code'),
$log->getParameter('ics.message'));
}
public function getDisplayIcon(
PhabricatorUser $viewer,
PhabricatorCalendarImportLog $log) {
return 'fa-file';
}
public function getDisplayColor(
PhabricatorUser $viewer,
PhabricatorCalendarImportLog $log) {
return 'red';
}
}

View file

@ -48,7 +48,7 @@ final class PhabricatorCalendarImportLogView extends AphrontView {
: null), : null),
id(new PHUIIconView())->setIcon($icon, $color), id(new PHUIIconView())->setIcon($icon, $color),
$name, $name,
$description, phutil_escape_html_newlines($description),
phabricator_datetime($log->getDateCreated(), $viewer), phabricator_datetime($log->getDateCreated(), $viewer),
); );
} }
@ -70,12 +70,12 @@ final class PhabricatorCalendarImportLogView extends AphrontView {
)) ))
->setColumnClasses( ->setColumnClasses(
array( array(
null, 'top',
null, 'top',
null, 'top',
'pri', 'top pri',
'wide', 'top wide',
null, 'top',
)); ));
return $table; return $table;