Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / calendar / xaction / PhabricatorCalendarImportICSFileTransaction.php
blob26a968d13dc9372a2d6b52199f73db49a11ddec4
1 <?php
3 final class PhabricatorCalendarImportICSFileTransaction
4 extends PhabricatorCalendarImportTransactionType {
6 const TRANSACTIONTYPE = 'calendar.import.ics.file';
7 const PARAMKEY_FILE = 'ics.filePHID';
8 const PARAMKEY_NAME = 'ics.fileName';
10 public function generateOldValue($object) {
11 return $object->getParameter(self::PARAMKEY_FILE);
14 public function applyInternalEffects($object, $value) {
15 $object->setParameter(self::PARAMKEY_FILE, $value);
17 $viewer = $this->getActor();
18 $file = id(new PhabricatorFileQuery())
19 ->setViewer($viewer)
20 ->withPHIDs(array($value))
21 ->executeOne();
22 if ($file) {
23 $object->setParameter(self::PARAMKEY_NAME, $file->getName());
27 public function getTitle() {
28 return pht(
29 '%s imported an ICS file.',
30 $this->renderAuthor());
33 public function validateTransactions($object, array $xactions) {
34 $viewer = $this->getActor();
35 $errors = array();
37 $ics_type = PhabricatorCalendarICSFileImportEngine::ENGINETYPE;
38 $import_type = $object->getEngine()->getImportEngineType();
39 if ($import_type != $ics_type) {
40 if (!$xactions) {
41 return $errors;
44 $errors[] = $this->newInvalidError(
45 pht(
46 'You can not attach an ICS file to an import type other than '.
47 'an ICS import (type is "%s").',
48 $import_type));
50 return $errors;
53 $new_value = $object->getParameter(self::PARAMKEY_FILE);
54 foreach ($xactions as $xaction) {
55 $new_value = $xaction->getNewValue();
56 if (!strlen($new_value)) {
57 continue;
60 $file = id(new PhabricatorFileQuery())
61 ->setViewer($viewer)
62 ->withPHIDs(array($new_value))
63 ->executeOne();
64 if (!$file) {
65 $errors[] = $this->newInvalidError(
66 pht(
67 'File PHID "%s" is not valid or not visible.',
68 $new_value),
69 $xaction);
73 if (!$new_value) {
74 $errors[] = $this->newRequiredError(
75 pht('You must select an ".ics" file to import.'));
78 return $errors;