protected final function importICSData(PhabricatorUser $viewer, PhabricatorCalendarImport $import, $data)
 {
     $parser = new PhutilICSParser();
     try {
         $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;
     }
     foreach ($parser->getWarnings() as $warning) {
         $import->newLogMessage(PhabricatorCalendarImportICSWarningLogType::LOGTYPE, array('ics.warning.code' => $warning['code'], 'ics.warning.line' => $warning['line'], 'ics.warning.text' => $warning['text'], 'ics.warning.message' => $warning['message']));
     }
     return $this->importEventDocument($viewer, $import, $document);
 }
 public function importEventsFromSource(PhabricatorUser $viewer, PhabricatorCalendarImport $import, $should_queue)
 {
     $uri_key = PhabricatorCalendarImportICSURITransaction::PARAMKEY_URI;
     $uri = $import->getParameter($uri_key);
     PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1);
     $file = PhabricatorFile::newFromFileDownload($uri, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'authorPHID' => $import->getAuthorPHID(), 'canCDN' => true));
     $import->newLogMessage(PhabricatorCalendarImportFetchLogType::LOGTYPE, array('file.phid' => $file->getPHID()));
     $data = $file->loadFileData();
     if ($should_queue && $this->shouldQueueDataImport($data)) {
         return $this->queueDataImport($import, $data);
     }
     return $this->importICSData($viewer, $import, $data);
 }
 protected final function queueDataImport(PhabricatorCalendarImport $import, $data)
 {
     $import->newLogMessage(PhabricatorCalendarImportQueueLogType::LOGTYPE, array('data.size' => strlen($data), 'data.limit' => self::QUEUE_BYTE_LIMIT));
     // When we queue on this pathway, we're queueing in response to an explicit
     // user action (like uploading a big `.ics` file), so we queue at normal
     // priority instead of bulk/import priority.
     PhabricatorWorker::scheduleTask('PhabricatorCalendarImportReloadWorker', array('importPHID' => $import->getPHID(), 'via' => PhabricatorCalendarImportReloadWorker::VIA_BACKGROUND), array('objectPHID' => $import->getPHID()));
 }