Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php
12256 views
1
<?php
2
3
abstract class PhabricatorCalendarEventDateTransaction
4
extends PhabricatorCalendarEventTransactionType {
5
6
abstract protected function getInvalidDateMessage();
7
8
public function isInheritedEdit() {
9
return false;
10
}
11
12
public function generateNewValue($object, $value) {
13
$editor = $this->getEditor();
14
15
if ($value->isDisabled()) {
16
return null;
17
}
18
19
return $value->newPhutilDateTime()
20
->setIsAllDay($editor->getNewIsAllDay())
21
->newAbsoluteDateTime()
22
->toDictionary();
23
}
24
25
public function getTransactionHasEffect($object, $old, $new) {
26
// If either value is `null` (for example, when setting a recurring event
27
// end date for the first time) and the other value is not `null`, this
28
// transaction has an effect.
29
$has_null = (($old === null) || ($new === null));
30
if ($has_null) {
31
return ($old !== $new);
32
}
33
34
$editor = $this->getEditor();
35
36
$actor = $this->getActor();
37
$actor_timezone = $actor->getTimezoneIdentifier();
38
39
// When an edit only changes the timezone of an event without materially
40
// changing the absolute time, discard it. This can happen if two users in
41
// different timezones edit an event without rescheduling it.
42
43
// Eventually, after T11073, there may be a UI control to adjust timezones.
44
// If a user explicitly changed the timezone, we should respect that.
45
// However, there is no way for users to intentionally apply this kind of
46
// edit today.
47
48
$old_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($old)
49
->setIsAllDay($editor->getNewIsAllDay())
50
->setViewerTimezone($actor_timezone);
51
52
$new_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($new)
53
->setIsAllDay($editor->getNewIsAllDay())
54
->setViewerTimezone($actor_timezone);
55
56
$old_epoch = $old_datetime->getEpoch();
57
$new_epoch = $new_datetime->getEpoch();
58
59
return ($old_epoch !== $new_epoch);
60
}
61
62
public function validateTransactions($object, array $xactions) {
63
$errors = array();
64
65
foreach ($xactions as $xaction) {
66
if ($xaction->getNewValue()->isValid()) {
67
continue;
68
}
69
70
$message = $this->getInvalidDateMessage();
71
$errors[] = $this->newInvalidError($message, $xaction);
72
}
73
74
return $errors;
75
}
76
77
}
78
79