From 87667958978c8b119269abd3ef88bbfc6b8a8436 Mon Sep 17 00:00:00 2001 From: liverpoolfcfan <2759714+liverpoolfc-fan@users.noreply.github.com> Date: Tue, 30 May 2023 10:35:42 +0100 Subject: [PATCH 1/2] Replace deprecated gmstrftime PHP function gmstrftime - Warning: This function has been DEPRECATED as of PHP 8.1.0. Relying on this function is highly discouraged. Adding a new static function to Utils.php to generate the the required Compact Date strings to send to the device. --- src/backend/kopano/mapiprovider.php | 6 +++--- src/lib/core/streamer.php | 4 ++-- src/lib/syncobjects/syncappointment.php | 4 ++-- src/lib/utils/utils.php | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/backend/kopano/mapiprovider.php b/src/backend/kopano/mapiprovider.php index c3d2701b..9a927e46 100644 --- a/src/backend/kopano/mapiprovider.php +++ b/src/backend/kopano/mapiprovider.php @@ -1286,12 +1286,12 @@ private function setAppointment($mapimessage, $appointment) { if (isset($existingstartendprops[$amapping["starttime"]]) && !isset($appointment->starttime)) { $appointment->starttime = $existingstartendprops[$amapping["starttime"]]; - ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'starttime' was not set, using value from MAPI %d (%s).", $appointment->starttime, gmstrftime("%Y%m%dT%H%M%SZ", $appointment->starttime))); + ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'starttime' was not set, using value from MAPI %d (%s).", $appointment->starttime, Utils::FormatDateUtc($appointment->starttime,"yyyyMMdd'T'HHmmSS'Z'"))); } if (isset($existingstartendprops[$amapping["endtime"]]) && !isset($appointment->endtime)) { $appointment->endtime = $existingstartendprops[$amapping["endtime"]]; - ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'endtime' was not set, using value from MAPI %d (%s).", $appointment->endtime, gmstrftime("%Y%m%dT%H%M%SZ", $appointment->endtime))); - } + ZLog::Write(LOGLEVEL_WBXML, sprintf("MAPIProvider->setAppointment(): Parameter 'endtime' was not set, using value from MAPI %d (%s).", $appointment->endtime, Utils::FormatDateUtc($appointment->endtime,"yyyyMMdd'T'HHmmSS'Z'"))); + } } if (!isset($appointment->starttime) || !isset($appointment->endtime)) { throw new StatusException("MAPIProvider->setAppointment(): Error, start and/or end time not set and can not be retrieved from MAPI.", SYNC_STATUS_SYNCCANNOTBECOMPLETED); diff --git a/src/lib/core/streamer.php b/src/lib/core/streamer.php index df143006..6053abbd 100644 --- a/src/lib/core/streamer.php +++ b/src/lib/core/streamer.php @@ -462,9 +462,9 @@ private function formatDate($ts, $type) { } if($type == self::STREAMER_TYPE_DATE) - return gmstrftime("%Y%m%dT%H%M%SZ", $ts); + return Utils::FormatDateUtc($ts,"yyyyMMdd'T'HHmmSS'Z'"); else if($type == self::STREAMER_TYPE_DATE_DASHES) - return gmstrftime("%Y-%m-%dT%H:%M:%S.000Z", $ts); + return Utils::FormatDateUtc($ts,"yyyy-MM-dd'T'HH:mm:SS'.000Z'"); } /** diff --git a/src/lib/syncobjects/syncappointment.php b/src/lib/syncobjects/syncappointment.php index b4b27808..5004b474 100644 --- a/src/lib/syncobjects/syncappointment.php +++ b/src/lib/syncobjects/syncappointment.php @@ -266,12 +266,12 @@ public function Check($logAsDebug = false) { // Case 1, 3a (endtime won't be changed as it's set) if (!isset($this->starttime)) { $this->starttime = $calcstart; - ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'starttime' was not set, setting it to %d (%s).", $this->starttime, gmstrftime("%Y%m%dT%H%M%SZ", $this->starttime))); + ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'starttime' was not set, setting it to %d (%s).", $this->starttime, Utils::FormatDateUtc($this->starttime,"yyyyMMdd'T'HHmmSS'Z'"))); } // Case 1, 4 if (!isset($this->endtime)) { $this->endtime = $calcstart + 1800; // 30 min after calcstart - ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'endtime' was not set, setting it to %d (%s).", $this->endtime, gmstrftime("%Y%m%dT%H%M%SZ", $this->endtime))); + ZLog::Write(LOGLEVEL_WBXML, sprintf("SyncAppointment->Check(): Parameter 'endtime' was not set, setting it to %d (%s).", $this->endtime, Utils::FormatDateUtc($this->endtime,"yyyyMMdd'T'HHmmSS'Z'"))); } } diff --git a/src/lib/utils/utils.php b/src/lib/utils/utils.php index f0622cf8..e6826f75 100644 --- a/src/lib/utils/utils.php +++ b/src/lib/utils/utils.php @@ -1465,6 +1465,30 @@ public static function SafeGetContents($filename, $functName, $suppressWarnings, return $contents; } + + /** + * Creates a Compact DateTime from a UTC Timestamp - Formats used for ActiveSync yyyyMMddTHHmmSSZ and yyyy-MM-ddTHH:mm:SS.000Z + * + * @param timestamp $ts + * + * @param string $format + * + * @access public + * @return string + */ + public static function FormatDateUtc($ts,$format) { + + $dateFormatUtc = datefmt_create( + 'en_US', + IntlDateFormatter::FULL, + IntlDateFormatter::FULL, + 'UTC', + IntlDateFormatter::GREGORIAN, + $format + ); + return datefmt_format($dateFormatUtc, $ts); + } + } // TODO Win1252/UTF8 functions are deprecated and will be removed sometime From bcdb0c8211693ef724f782ecf2012932e2319860 Mon Sep 17 00:00:00 2001 From: liverpoolfcfan <2759714+liverpoolfc-fan@users.noreply.github.com> Date: Tue, 30 May 2023 16:04:14 +0100 Subject: [PATCH 2/2] Return empty string instead of setting it to null (#1) PHP 8.0 stopped allowing empty strings to be passed to gmstrftime. This led to the previously suggested change to replace the empty string with null. Unfortunately, that change collided with the gmstrftime also accepting null as a valid input where it would return the current time formatted as requested. This led to contacts who had empty Anniversary and Birthday fields getting their empty strings replaced by nulls, and subsequently getting passed to gmstrftime which would assign them values of the current time. The correct behaviour for the streamer in this instance is to just return the empty string --- src/lib/core/streamer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/core/streamer.php b/src/lib/core/streamer.php index 6053abbd..f4f4ea83 100644 --- a/src/lib/core/streamer.php +++ b/src/lib/core/streamer.php @@ -458,7 +458,7 @@ public function GetStreamerVars() { */ private function formatDate($ts, $type) { if ('' === $ts) { - $ts = null; + return $ts; } if($type == self::STREAMER_TYPE_DATE)