Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/xaction/PhabricatorCalendarImportICSFileTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarImportICSFileTransaction
4
extends PhabricatorCalendarImportTransactionType {
5
6
const TRANSACTIONTYPE = 'calendar.import.ics.file';
7
const PARAMKEY_FILE = 'ics.filePHID';
8
const PARAMKEY_NAME = 'ics.fileName';
9
10
public function generateOldValue($object) {
11
return $object->getParameter(self::PARAMKEY_FILE);
12
}
13
14
public function applyInternalEffects($object, $value) {
15
$object->setParameter(self::PARAMKEY_FILE, $value);
16
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());
24
}
25
}
26
27
public function getTitle() {
28
return pht(
29
'%s imported an ICS file.',
30
$this->renderAuthor());
31
}
32
33
public function validateTransactions($object, array $xactions) {
34
$viewer = $this->getActor();
35
$errors = array();
36
37
$ics_type = PhabricatorCalendarICSFileImportEngine::ENGINETYPE;
38
$import_type = $object->getEngine()->getImportEngineType();
39
if ($import_type != $ics_type) {
40
if (!$xactions) {
41
return $errors;
42
}
43
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));
49
50
return $errors;
51
}
52
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;
58
}
59
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);
70
}
71
}
72
73
if (!$new_value) {
74
$errors[] = $this->newRequiredError(
75
pht('You must select an ".ics" file to import.'));
76
}
77
78
return $errors;
79
}
80
}
81
82