1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00
phorge-phorge/resources/sql/autopatches/20161005.cal.01.rrules.php
epriestley 3164ff68db Convert Calendar Events to use RRULE frequency constants in various other places
Summary:
Ref T10747.

  - Store recurrence as RRULEs internally.
  - Use RRULE constants.
  - Migrate existing rules to RRULEs.

Test Plan: Ran migration, nothing seemed broken?

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16670
2016-10-06 04:02:27 -07:00

44 lines
1 KiB
PHP

<?php
$table = new PhabricatorCalendarEvent();
$conn = $table->establishConnection('w');
$table_name = 'calendar_event';
foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) {
$parameters = phutil_json_decode($row['parameters']);
if (isset($parameters['recurrenceRule'])) {
// This event has already been migrated.
continue;
}
if (!$row['isRecurring']) {
continue;
}
$old_rule = $row['recurrenceFrequency'];
if (!$old_rule) {
continue;
}
try {
$frequency = phutil_json_decode($old_rule);
if ($frequency) {
$frequency_rule = $frequency['rule'];
$frequency_rule = phutil_utf8_strtoupper($frequency_rule);
$rrule = id(new PhutilCalendarRecurrenceRule())
->setFrequency($frequency_rule);
}
} catch (Exception $ex) {
continue;
}
$parameters['recurrenceRule'] = $rrule->toDictionary();
queryfx(
$conn,
'UPDATE %T SET parameters = %s WHERE id = %d',
$table_name,
phutil_json_encode($parameters),
$row['id']);
}