From d4d46501ed1b2e588746ba55b0b5cf27275b86fa Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 10 Apr 2017 04:35:34 -0700 Subject: [PATCH] Add a repair migration to fix legacy Calendar events without "utcInstanceEpoch" Summary: Fixes T12488. Some events appear to have survived earlier migrations without getting completely fixed. Fix them. Test Plan: - Ran migration locally with `bin/storage upgrade` (but: I could not reproduce this problem locally). - Ran migration in production and saw ICS import stop fataling. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12488 Differential Revision: https://secure.phabricator.com/D17642 --- .../20170410.calendar.01.repair.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 resources/sql/autopatches/20170410.calendar.01.repair.php diff --git a/resources/sql/autopatches/20170410.calendar.01.repair.php b/resources/sql/autopatches/20170410.calendar.01.repair.php new file mode 100644 index 0000000000..7d0000e581 --- /dev/null +++ b/resources/sql/autopatches/20170410.calendar.01.repair.php @@ -0,0 +1,42 @@ +establishConnection('w'); +$table_name = $table->getTableName(); + +$viewer = PhabricatorUser::getOmnipotentUser(); +$all_events = id(new PhabricatorCalendarEventQuery()) + ->setViewer($viewer) + ->execute(); +foreach ($all_events as $event) { + $id = $event->getID(); + + if (!$event->getInstanceOfEventPHID()) { + // Not a child event, so no instance epoch. + continue; + } + + if ($event->getUTCInstanceEpoch()) { + // Already has an instance epoch. + continue; + } + + try { + $event->updateUTCEpochs(); + } catch (Exception $ex) { + phlog($ex); + continue; + } + + queryfx( + $conn, + 'UPDATE %T SET utcInstanceEpoch = %nd WHERE id = %d', + $table_name, + $event->getUTCInstanceEpoch(), + $id); +}