From 4d707fd355412f2bbdc8be9216760dd73c063aac Mon Sep 17 00:00:00 2001 From: David Dreschner Date: Mon, 9 Feb 2026 16:26:04 +0100 Subject: [PATCH] fix: Remove deprecated RFC7231 constant to avoid warnings on PHP 8.5 Signed-off-by: David Dreschner --- apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php | 3 ++- .../AppFramework/Middleware/NotModifiedMiddleware.php | 3 ++- lib/public/AppFramework/Http/Response.php | 5 +++-- lib/public/Constants.php | 8 ++++++++ .../AppFramework/Middleware/NotModifiedMiddlewareTest.php | 7 ++++--- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php index 845c87cfce1cd..74c69a467ae13 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php @@ -9,6 +9,7 @@ namespace OCA\DAV\Provisioning\Apple; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Constants; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\INode; use Sabre\DAV\IProperties; @@ -60,7 +61,7 @@ public function getProperties($properties) { return [ '{DAV:}getcontentlength' => 42, - '{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC7231), + '{DAV:}getlastmodified' => $datetime->format(Constants::DATE_RFC7231), ]; } diff --git a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php index e2514916d7da6..60cf06f7b9c77 100644 --- a/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php +++ b/lib/private/AppFramework/Middleware/NotModifiedMiddleware.php @@ -11,6 +11,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; +use OCP\Constants; use OCP\IRequest; class NotModifiedMiddleware extends Middleware { @@ -27,7 +28,7 @@ public function afterController($controller, $methodName, Response $response) { } $modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE'); - if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC7231)) { + if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(Constants::DATE_RFC7231)) { $response->setStatus(Http::STATUS_NOT_MODIFIED); return $response; } diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 6edd32a1f8b69..2e69c93755986 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -9,6 +9,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Constants; use OCP\IConfig; use OCP\IRequest; use OCP\IUserSession; @@ -98,7 +99,7 @@ public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutabl $time = \OCP\Server::get(ITimeFactory::class); $expires->setTimestamp($time->getTime()); $expires->add(new \DateInterval('PT' . $cacheSeconds . 'S')); - $this->addHeader('Expires', $expires->format(\DateTimeInterface::RFC7231)); + $this->addHeader('Expires', $expires->format(Constants::DATE_RFC7231)); } else { $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); unset($this->headers['Expires']); @@ -240,7 +241,7 @@ public function getHeaders() { ]; if ($this->lastModified) { - $mergeWith['Last-Modified'] = $this->lastModified->format(\DateTimeInterface::RFC7231); + $mergeWith['Last-Modified'] = $this->lastModified->format(Constants::DATE_RFC7231); } if ($this->ETag) { diff --git a/lib/public/Constants.php b/lib/public/Constants.php index 8d38ade7baf70..bf53591149fbd 100644 --- a/lib/public/Constants.php +++ b/lib/public/Constants.php @@ -59,4 +59,12 @@ class Constants { * cf. sharing.maxAutocompleteResults in config.sample.php. */ public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25; + + /** + * Replacement for the built-in `DATE_RFC7231` constant + * deprecated since PHP 8.5. + * + * @since 33.0.1 + */ + public const DATE_RFC7231 = 'D, d M Y H:i:s \G\M\T'; } diff --git a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php index 7dcb28a2af4b3..6e4c847ed247f 100644 --- a/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php @@ -12,6 +12,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Response; +use OCP\Constants; use OCP\IRequest; class NotModifiedMiddlewareTest extends \Test\TestCase { @@ -44,13 +45,13 @@ public static function dataModified(): array { [null, '"etag"', null, '', false], ['etag', '"etag"', null, '', true], - [null, '', $now, $now->format(\DateTimeInterface::RFC7231), true], + [null, '', $now, $now->format(Constants::DATE_RFC7231), true], [null, '', $now, $now->format(\DateTimeInterface::ATOM), false], - [null, '', null, $now->format(\DateTimeInterface::RFC7231), false], + [null, '', null, $now->format(Constants::DATE_RFC7231), false], [null, '', $now, '', false], ['etag', '"etag"', $now, $now->format(\DateTimeInterface::ATOM), true], - ['etag', '"etag"', $now, $now->format(\DateTimeInterface::RFC7231), true], + ['etag', '"etag"', $now, $now->format(Constants::DATE_RFC7231), true], ]; }