marionnewlevant / craft-snitch

Craft plugin. Report when two people might be editing the same entry, category, or global
MIT License
35 stars 16 forks source link

Collisions not expiring due to DateTime formatting and timezone discrepancies #2

Closed benjamin-smith closed 7 years ago

benjamin-smith commented 7 years ago

Craft CMS (thankfully) stores all dates/times in the DB in the UTC timezone. The current master branch currently 1) expires collisions based on the Craft system timezone, and 2) does not actually pass a time to the MnSnitchRecord::model()->deleteAll() call, it only uses a YYYY-mm-dd formatted representation.

Passing a \Craft\DateTime object as a query binding causes \Craft\DateTime::__toString() to be called by the ORM, which returns the date in YYYY-mm-dd format. So collisions will not expire until the next day, since the time is not part of that string.

This patch uses the DateTimeHelper::formatTimeForDb() method to give us the proper DB engine formatted date/time string, in the UTC timezone.

Tested on Craft CMS 2.6.2903.