Documentation

CRM_Upgrade_Incremental_php_TimezoneRevertTrait

Circa v5.47.x-5.48.x, the `civicrm_event.event_tz` columns were introduced. But there were still significant issues.

This rollsback the schema changes. The same logic should be used for various upgrade-paths involving 5.47.x or 5.48.x, so it helps to use a trait shared by them.

Table of Contents

Methods

addEventTzTasks()  : void
addSeconds()  : string
convertModifiedEvents()  : bool
If a user edited an `Event` in the UI while running 5.47.alpha1 - 5.47.2, then `revertEventDates` won't be good enough. In particular:
convertTz()  : mixed
createEventTzPostUpgradeMessage()  : string
createEventTzPreUpgradeMessage()  : string
fillBackupEventDates()  : bool
dev/core#2122 - keep a copy of converted dates In theory we could skip this step if logging is enabled, but (a) people might turn off logging before running upgrades, and (b) there may not be a complete record anyway. People can drop the new column if they don't need it.
findDstError()  : int
revertEventDates()  : bool
This is the straight-up opposite of the conversion done in `5.47.alpha1`.
findLogRange()  : array<string|int, mixed>
Find the slice of `civicrm_log` which occurred between version $X and version $Y.
pickSkewTz()  : string
Choose a representative timezone for identifying DST errors.
swapTz()  : CRM_Utils_AutoClean
areEventsUsingTimestamp()  : bool
Check if civicrm_event start_date is a timestamp.
areThereAnyCiviEvents()  : bool
Are there any events in the system?
getTimezoneStats()  : array<string|int, mixed>

Methods

addSeconds()

public static addSeconds(string $dateTime, int $skew) : string
Parameters
$dateTime : string
$skew : int
Return values
string

convertModifiedEvents()

If a user edited an `Event` in the UI while running 5.47.alpha1 - 5.47.2, then `revertEventDates` won't be good enough. In particular:

public static convertModifiedEvents([CRM_Queue_TaskContext|null $ctx = NULL ]) : bool
  • It's likely to have activated the DST bug (based on the current-user's TZ).
  • The user could have filled-in/corrected the values of event_tz and/or each TIMESTAMP column.

The algorithm reads backup values (eg start_date_ts_bak) and rewrites live values (eg start_date)

It uses a heuristic approach to cleaning DST error ("skew"). This requires a representative timezone ("skewTz"). It should not be necessary to know the exact TZ of every edit -- as long as all TZs have similar DST rules. For example:

  • Most locales in US+CA have the same DST rules. (America/Los_Angeles and America/Chicago are equally representative.)
  • Most locales in Europe have the same DST rules. (Europe/Helsinki and Europe/Berlin are equally representative.)
  • Most locales in Australia have the same DST rules.

By default, this will borrow the current user (sysadmin)'s timezone as the representative skewTz. This can be overridden with env-var CIVICRM_TZ_SKEW.

Parameters
$ctx : CRM_Queue_TaskContext|null = NULL
Return values
bool

convertTz()

public static convertTz(string $dateTimeExpr, string $srcTz, string $destTz) : mixed
Parameters
$dateTimeExpr : string
$srcTz : string
$destTz : string

createEventTzPostUpgradeMessage()

public createEventTzPostUpgradeMessage() : string
Return values
string

createEventTzPreUpgradeMessage()

public createEventTzPreUpgradeMessage() : string
Return values
string

fillBackupEventDates()

dev/core#2122 - keep a copy of converted dates In theory we could skip this step if logging is enabled, but (a) people might turn off logging before running upgrades, and (b) there may not be a complete record anyway. People can drop the new column if they don't need it.

public static fillBackupEventDates(CRM_Queue_TaskContext $ctx) : bool
Parameters
$ctx : CRM_Queue_TaskContext
Return values
bool

findDstError()

public static findDstError(string $modificationTime, string $targetValue, string $timeZone) : int
Parameters
$modificationTime : string
$targetValue : string
$timeZone : string
Return values
int

revertEventDates()

This is the straight-up opposite of the conversion done in `5.47.alpha1`.

public static revertEventDates([CRM_Queue_TaskContext|null $ctx = NULL ]) : bool

It flips the TIMESTAMPs back to DATETIMEs. This should be a clean/straight revert - provided that the records have not changed.

But some records may have changed. convertModifiedEvents() will address those.

Parameters
$ctx : CRM_Queue_TaskContext|null = NULL
Return values
bool

findLogRange()

Find the slice of `civicrm_log` which occurred between version $X and version $Y.

protected static findLogRange(string $lowVersion, string $highVersion) : array<string|int, mixed>
Parameters
$lowVersion : string
$highVersion : string
Return values
array<string|int, mixed>

pickSkewTz()

Choose a representative timezone for identifying DST errors.

protected static pickSkewTz() : string

Preference will be given to ENV['CIVICRM_TZ_SKEW'] or the current user's TZ.

An explict value of IGNORE will opt-out of skew correction.

Return values
string

areEventsUsingTimestamp()

Check if civicrm_event start_date is a timestamp.

private static areEventsUsingTimestamp() : bool
Return values
bool

areThereAnyCiviEvents()

Are there any events in the system?

private static areThereAnyCiviEvents() : bool
Return values
bool

getTimezoneStats()

private getTimezoneStats() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results