Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/xaction/PhabricatorCalendarEventForkTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarEventForkTransaction
4
extends PhabricatorCalendarEventTransactionType {
5
6
const TRANSACTIONTYPE = 'calendar.fork';
7
8
public function generateOldValue($object) {
9
return false;
10
}
11
12
public function shouldHide() {
13
// This transaction is purely an internal implementation detail which
14
// supports editing groups of events like "All Future Events".
15
return true;
16
}
17
18
public function applyInternalEffects($object, $value) {
19
$parent = $object->getParentEvent();
20
21
$object->setInstanceOfEventPHID(null);
22
$object->attachParentEvent(null);
23
24
$rrule = $parent->newRecurrenceRule();
25
$object->setRecurrenceRule($rrule);
26
27
$until = $parent->newUntilDateTime();
28
if ($until) {
29
$object->setUntilDateTime($until);
30
}
31
32
$old_sequence_index = $object->getSequenceIndex();
33
$object->setSequenceIndex(0);
34
35
// Stop the parent event from recurring after the start date of this event.
36
// Since the "until" time is inclusive, rewind it by one second. We could
37
// figure out the previous instance's time instead or use a COUNT, but this
38
// seems simpler as long as it doesn't cause any issues.
39
$until_cutoff = $object->newStartDateTime()
40
->newRelativeDateTime('-PT1S')
41
->newAbsoluteDateTime();
42
43
$parent->setUntilDateTime($until_cutoff);
44
$parent->save();
45
46
// NOTE: If we implement "COUNT" on editable events, we need to adjust
47
// the "COUNT" here and divide it up between the parent and the fork.
48
49
// Make all following children of the old parent children of this node
50
// instead.
51
$conn = $object->establishConnection('w');
52
queryfx(
53
$conn,
54
'UPDATE %T SET
55
instanceOfEventPHID = %s,
56
sequenceIndex = (sequenceIndex - %d)
57
WHERE instanceOfEventPHID = %s
58
AND utcInstanceEpoch > %d',
59
$object->getTableName(),
60
$object->getPHID(),
61
$old_sequence_index,
62
$parent->getPHID(),
63
$object->getUTCInstanceEpoch());
64
}
65
66
}
67
68