Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/xaction/PhabricatorCalendarImportICSURITransaction.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarImportICSURITransaction
4
extends PhabricatorCalendarImportTransactionType {
5
6
const TRANSACTIONTYPE = 'calendar.import.ics.uri';
7
const PARAMKEY_URI = 'ics.uri';
8
9
public function generateOldValue($object) {
10
return $object->getParameter(self::PARAMKEY_URI);
11
}
12
13
public function applyInternalEffects($object, $value) {
14
$object->setParameter(self::PARAMKEY_URI, $value);
15
}
16
17
public function getTitle() {
18
// NOTE: This transaction intentionally does not disclose the actual
19
// URI.
20
return pht(
21
'%s updated the import URI.',
22
$this->renderAuthor());
23
}
24
25
public function validateTransactions($object, array $xactions) {
26
$viewer = $this->getActor();
27
$errors = array();
28
29
$ics_type = PhabricatorCalendarICSURIImportEngine::ENGINETYPE;
30
$import_type = $object->getEngine()->getImportEngineType();
31
if ($import_type != $ics_type) {
32
if (!$xactions) {
33
return $errors;
34
}
35
36
$errors[] = $this->newInvalidError(
37
pht(
38
'You can not attach an ICS URI to an import type other than '.
39
'an ICS URI import (type is "%s").',
40
$import_type));
41
42
return $errors;
43
}
44
45
$new_value = $object->getParameter(self::PARAMKEY_URI);
46
foreach ($xactions as $xaction) {
47
$new_value = $xaction->getNewValue();
48
if (!strlen($new_value)) {
49
continue;
50
}
51
52
try {
53
PhabricatorEnv::requireValidRemoteURIForFetch(
54
$new_value,
55
array(
56
'http',
57
'https',
58
));
59
} catch (Exception $ex) {
60
$errors[] = $this->newInvalidError(
61
$ex->getMessage(),
62
$xaction);
63
}
64
}
65
66
if (!strlen($new_value)) {
67
$errors[] = $this->newRequiredError(
68
pht('You must select an ".ics" URI to import.'));
69
}
70
71
return $errors;
72
}
73
}
74
75