Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / calendar / xaction / PhabricatorCalendarEventForkTransaction.php
blob7baba94109536984d7da3ae1b76fe888eaa59f82
1 <?php
3 final class PhabricatorCalendarEventForkTransaction
4 extends PhabricatorCalendarEventTransactionType {
6 const TRANSACTIONTYPE = 'calendar.fork';
8 public function generateOldValue($object) {
9 return false;
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;
18 public function applyInternalEffects($object, $value) {
19 $parent = $object->getParentEvent();
21 $object->setInstanceOfEventPHID(null);
22 $object->attachParentEvent(null);
24 $rrule = $parent->newRecurrenceRule();
25 $object->setRecurrenceRule($rrule);
27 $until = $parent->newUntilDateTime();
28 if ($until) {
29 $object->setUntilDateTime($until);
32 $old_sequence_index = $object->getSequenceIndex();
33 $object->setSequenceIndex(0);
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();
43 $parent->setUntilDateTime($until_cutoff);
44 $parent->save();
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.
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());