diff --git a/resources/sql/autopatches/20170410.calendar.01.repair.php b/resources/sql/autopatches/20170410.calendar.01.repair.php new file mode 100644 --- /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); +}