From 91d5fa0fc51be987a33b7a95a8b66a6ea262a75e Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Wed, 2 Mar 2022 11:10:36 +0100 Subject: [PATCH] Prevent an event-processing error if there is no timezone setting refs https://github.com/TryGhost/Ghost/pull/14197 - We default to UTC when there is no setting timezone --- .../services/email-analytics/lib/event-processor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/server/services/email-analytics/lib/event-processor.js b/core/server/services/email-analytics/lib/event-processor.js index d13d087db8..f82d50f75c 100644 --- a/core/server/services/email-analytics/lib/event-processor.js +++ b/core/server/services/email-analytics/lib/event-processor.js @@ -88,7 +88,13 @@ class GhostEventProcessor extends EventProcessor { opened_at: this.db.knex.raw('COALESCE(opened_at, ?)', [moment.utc(event.timestamp).format('YYYY-MM-DD HH:mm:ss')]) }); - const {value: timezone} = await this.db.knex('settings').first('value').where('key', 'timezone'); + // Using the default timezone set in https://github.com/TryGhost/Ghost/blob/2c5643623db0fc4db390f6997c81a73dca7ccacd/core/server/data/schema/default-settings/default-settings.json#L105 + let timezone = 'Etc/UTC'; + const timezoneData = await this.db.knex('settings').first('value').where('key', 'timezone'); + if (timezoneData && timezoneData.value) { + timezone = timezoneData.value; + } + await this.db.knex('members') .where('email', '=', event.recipientEmail) .andWhere(builder => builder