mirror of
https://github.com/nextcloud/server.git
synced 2026-04-26 00:27:49 -04:00
Some (well all except sqlite) database platforms support timezone configuration. The problem is that we expect everything in UTC, but some servers might have set some different default (e.g. in database configuration or even just because of `TZ` environment variable). This causes incorrect values when expecting `NOW()` to return the current time in UTC. For PHP we already enforce UTC as timezone, this PR adds a middleware that enforces UTC also as the database connection / session timezone. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
25 lines
540 B
PHP
25 lines
540 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
namespace OC\DB\Middleware;
|
|
|
|
use Doctrine\DBAL\Driver;
|
|
use Doctrine\DBAL\Driver\Middleware;
|
|
|
|
/**
|
|
* Custom doctrine middleware to ensure that the session timezone is set to UTC.
|
|
*
|
|
* @since 34.0.0
|
|
*/
|
|
final class UtcTimezoneMiddleware implements Middleware {
|
|
|
|
#[\Override]
|
|
public function wrap(Driver $driver): Driver {
|
|
return new UtcTimezoneMiddlewareDriver($driver);
|
|
}
|
|
}
|