1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00
phorge-phorge/src/applications/calendar/xaction/PhabricatorCalendarEventDateTransaction.php
epriestley 22a566f732 Ignore Calendar date edits which just change the internal date timezone without rescheduling it
Summary:
Ref T11816. Currently, if someone in California creates an event and then someone in New York edits it, we generate a no-op "<user> changed the start time from 3PM to 3PM." transaction.

This is because the internal timezone of the event is changing, but the actual absolute time is not.

Instead, when an edit wouldn't reschedule an event and would only change the internal timezone, ignore the edit.

Test Plan:
  - Edited non-all-day events in PST / EST with out making changes (ignored).
  - Edited non-all-day events in PST / EST with changes (changes worked).
  - Performed the same edits with all-day events, which also were ignored and worked, respectively.
  - Pulled events in and out of all-day mode in different timezones, behavior seemeed reasonable.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11816

Differential Revision: https://secure.phabricator.com/D16955
2016-11-28 10:33:59 -08:00

69 lines
2 KiB
PHP

<?php
abstract class PhabricatorCalendarEventDateTransaction
extends PhabricatorCalendarEventTransactionType {
abstract protected function getInvalidDateMessage();
public function isInheritedEdit() {
return false;
}
public function generateNewValue($object, $value) {
$editor = $this->getEditor();
if ($value->isDisabled()) {
return null;
}
return $value->newPhutilDateTime()
->setIsAllDay($editor->getNewIsAllDay())
->newAbsoluteDateTime()
->toDictionary();
}
public function getTransactionHasEffect($object, $old, $new) {
$editor = $this->getEditor();
$actor = $this->getActor();
$actor_timezone = $actor->getTimezoneIdentifier();
// When an edit only changes the timezone of an event without materially
// changing the absolute time, discard it. This can happen if two users in
// different timezones edit an event without rescheduling it.
// Eventually, after T11073, there may be a UI control to adjust timezones.
// If a user explicitly changed the timezone, we should respect that.
// However, there is no way for users to intentionally apply this kind of
// edit today.
$old_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($old)
->setIsAllDay($editor->getNewIsAllDay())
->setViewerTimezone($actor_timezone);
$new_datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($new)
->setIsAllDay($editor->getNewIsAllDay())
->setViewerTimezone($actor_timezone);
$old_epoch = $old_datetime->getEpoch();
$new_epoch = $new_datetime->getEpoch();
return ($old_epoch !== $new_epoch);
}
public function validateTransactions($object, array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
if ($xaction->getNewValue()->isValid()) {
continue;
}
$message = $this->getInvalidDateMessage();
$errors[] = $this->newInvalidError($message, $xaction);
}
return $errors;
}
}