Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / calendar / import / PhabricatorCalendarICSURIImportEngine.php
blobbd52ec5bc2ac19c7afe2853d93f7d06695357011
1 <?php
3 final class PhabricatorCalendarICSURIImportEngine
4 extends PhabricatorCalendarICSImportEngine {
6 const ENGINETYPE = 'icsuri';
8 public function getImportEngineName() {
9 return pht('Import .ics URI');
12 public function getImportEngineTypeName() {
13 return pht('.ics URI');
16 public function getImportEngineHint() {
17 return pht('Import or subscribe to a calendar in .ics format by URI.');
20 public function supportsTriggers(PhabricatorCalendarImport $import) {
21 return true;
24 public function appendImportProperties(
25 PhabricatorUser $viewer,
26 PhabricatorCalendarImport $import,
27 PHUIPropertyListView $properties) {
29 $uri_key = PhabricatorCalendarImportICSURITransaction::PARAMKEY_URI;
30 $uri = $import->getParameter($uri_key);
32 // Since the URI may contain a secret hash, don't show it to users who
33 // can not edit the import.
34 $can_edit = PhabricatorPolicyFilter::hasCapability(
35 $viewer,
36 $import,
37 PhabricatorPolicyCapability::CAN_EDIT);
38 if (!$can_edit) {
39 $uri_display = phutil_tag('em', array(), pht('Restricted'));
40 } else if (!PhabricatorEnv::isValidRemoteURIForLink($uri)) {
41 $uri_display = $uri;
42 } else {
43 $uri_display = phutil_tag(
44 'a',
45 array(
46 'href' => $uri,
47 'target' => '_blank',
48 'rel' => 'noreferrer',
50 $uri);
53 $properties->addProperty(pht('Source URI'), $uri_display);
56 public function newEditEngineFields(
57 PhabricatorEditEngine $engine,
58 PhabricatorCalendarImport $import) {
59 $fields = array();
61 if ($engine->getIsCreate()) {
62 $fields[] = id(new PhabricatorTextEditField())
63 ->setKey('uri')
64 ->setLabel(pht('URI'))
65 ->setDescription(pht('URI to import.'))
66 ->setTransactionType(
67 PhabricatorCalendarImportICSURITransaction::TRANSACTIONTYPE)
68 ->setConduitDescription(pht('URI to import.'))
69 ->setConduitTypeDescription(pht('New URI.'));
72 return $fields;
75 public function getDisplayName(PhabricatorCalendarImport $import) {
76 return pht('ICS URI');
79 public function importEventsFromSource(
80 PhabricatorUser $viewer,
81 PhabricatorCalendarImport $import,
82 $should_queue) {
84 $uri_key = PhabricatorCalendarImportICSURITransaction::PARAMKEY_URI;
85 $uri = $import->getParameter($uri_key);
87 PhabricatorSystemActionEngine::willTakeAction(
88 array($viewer->getPHID()),
89 new PhabricatorFilesOutboundRequestAction(),
90 1);
92 $file = PhabricatorFile::newFromFileDownload(
93 $uri,
94 array(
95 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
96 'authorPHID' => $import->getAuthorPHID(),
97 'canCDN' => true,
98 ));
100 $import->newLogMessage(
101 PhabricatorCalendarImportFetchLogType::LOGTYPE,
102 array(
103 'file.phid' => $file->getPHID(),
106 $data = $file->loadFileData();
108 if ($should_queue && $this->shouldQueueDataImport($data)) {
109 return $this->queueDataImport($import, $data);
112 return $this->importICSData($viewer, $import, $data);
115 public function canDisable(
116 PhabricatorUser $viewer,
117 PhabricatorCalendarImport $import) {
118 return true;