Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / calendar / import / PhabricatorCalendarICSFileImportEngine.php
blobc37ba6c9448973ce14359662fd3005107b3ad1b8
1 <?php
3 final class PhabricatorCalendarICSFileImportEngine
4 extends PhabricatorCalendarICSImportEngine {
6 const ENGINETYPE = 'icsfile';
8 public function getImportEngineName() {
9 return pht('Import .ics File');
12 public function getImportEngineTypeName() {
13 return pht('.ics File');
16 public function getImportEngineHint() {
17 return pht('Import an event in ".ics" (iCalendar) format.');
20 public function supportsTriggers(PhabricatorCalendarImport $import) {
21 return false;
24 public function appendImportProperties(
25 PhabricatorUser $viewer,
26 PhabricatorCalendarImport $import,
27 PHUIPropertyListView $properties) {
29 $phid_key = PhabricatorCalendarImportICSFileTransaction::PARAMKEY_FILE;
30 $file_phid = $import->getParameter($phid_key);
32 $properties->addProperty(
33 pht('Source File'),
34 $viewer->renderHandle($file_phid));
37 public function newEditEngineFields(
38 PhabricatorEditEngine $engine,
39 PhabricatorCalendarImport $import) {
40 $fields = array();
42 if ($engine->getIsCreate()) {
43 $fields[] = id(new PhabricatorFileEditField())
44 ->setKey('icsFilePHID')
45 ->setLabel(pht('ICS File'))
46 ->setDescription(pht('ICS file to import.'))
47 ->setTransactionType(
48 PhabricatorCalendarImportICSFileTransaction::TRANSACTIONTYPE)
49 ->setConduitDescription(pht('File PHID to import.'))
50 ->setConduitTypeDescription(pht('File PHID.'));
53 return $fields;
56 public function getDisplayName(PhabricatorCalendarImport $import) {
57 $filename_key = PhabricatorCalendarImportICSFileTransaction::PARAMKEY_NAME;
58 $filename = $import->getParameter($filename_key);
59 if (strlen($filename)) {
60 return pht('ICS File "%s"', $filename);
61 } else {
62 return pht('ICS File');
66 public function importEventsFromSource(
67 PhabricatorUser $viewer,
68 PhabricatorCalendarImport $import,
69 $should_queue) {
71 $phid_key = PhabricatorCalendarImportICSFileTransaction::PARAMKEY_FILE;
72 $file_phid = $import->getParameter($phid_key);
74 $file = id(new PhabricatorFileQuery())
75 ->setViewer($viewer)
76 ->withPHIDs(array($file_phid))
77 ->executeOne();
78 if (!$file) {
79 throw new Exception(
80 pht(
81 'Unable to load file ("%s") for import.',
82 $file_phid));
85 $data = $file->loadFileData();
87 if ($should_queue && $this->shouldQueueDataImport($data)) {
88 return $this->queueDataImport($import, $data);
91 return $this->importICSData($viewer, $import, $data);
94 public function canDisable(
95 PhabricatorUser $viewer,
96 PhabricatorCalendarImport $import) {
97 return false;
100 public function explainCanDisable(
101 PhabricatorUser $viewer,
102 PhabricatorCalendarImport $import) {
103 return pht(
104 'You can not disable import of an ICS file because the entire import '.
105 'occurs immediately when you upload the file. There is no further '.
106 'activity to disable.');