Skip to content

Commit cac3488

Browse files
authored
Merge pull request #58911 from nextcloud/backport/58201/stable33
[stable33] fix: Remove deprecated RFC7231 constant to avoid warnings on PHP 8.5
2 parents 08b0a48 + 2c601fe commit cac3488

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace OCA\DAV\Provisioning\Apple;
88

99
use OCP\AppFramework\Utility\ITimeFactory;
10+
use OCP\Constants;
1011
use Sabre\DAV\Exception\Forbidden;
1112
use Sabre\DAV\INode;
1213
use Sabre\DAV\IProperties;
@@ -58,7 +59,7 @@ public function getProperties($properties) {
5859

5960
return [
6061
'{DAV:}getcontentlength' => 42,
61-
'{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC7231),
62+
'{DAV:}getlastmodified' => $datetime->format(Constants::DATE_RFC7231),
6263
];
6364
}
6465

lib/private/AppFramework/Middleware/NotModifiedMiddleware.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\AppFramework\Http;
1212
use OCP\AppFramework\Http\Response;
1313
use OCP\AppFramework\Middleware;
14+
use OCP\Constants;
1415
use OCP\IRequest;
1516

1617
class NotModifiedMiddleware extends Middleware {
@@ -29,7 +30,7 @@ public function afterController($controller, $methodName, Response $response) {
2930
}
3031

3132
$modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE');
32-
if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC7231)) {
33+
if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(Constants::DATE_RFC7231)) {
3334
$response->setStatus(Http::STATUS_NOT_MODIFIED);
3435
return $response;
3536
}

lib/public/AppFramework/Http/Response.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OCP\AppFramework\Http;
1111
use OCP\AppFramework\Utility\ITimeFactory;
12+
use OCP\Constants;
1213
use OCP\IConfig;
1314
use OCP\IRequest;
1415
use OCP\IUserSession;
@@ -98,7 +99,7 @@ public function cacheFor(int $cacheSeconds, bool $public = false, bool $immutabl
9899
$time = \OCP\Server::get(ITimeFactory::class);
99100
$expires->setTimestamp($time->getTime());
100101
$expires->add(new \DateInterval('PT' . $cacheSeconds . 'S'));
101-
$this->addHeader('Expires', $expires->format(\DateTimeInterface::RFC7231));
102+
$this->addHeader('Expires', $expires->format(Constants::DATE_RFC7231));
102103
} else {
103104
$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
104105
unset($this->headers['Expires']);
@@ -240,7 +241,7 @@ public function getHeaders() {
240241
];
241242

242243
if ($this->lastModified) {
243-
$mergeWith['Last-Modified'] = $this->lastModified->format(\DateTimeInterface::RFC7231);
244+
$mergeWith['Last-Modified'] = $this->lastModified->format(Constants::DATE_RFC7231);
244245
}
245246

246247
if ($this->ETag) {

lib/public/Constants.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,12 @@ class Constants {
5959
* cf. sharing.maxAutocompleteResults in config.sample.php.
6060
*/
6161
public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25;
62+
63+
/**
64+
* Replacement for the built-in `DATE_RFC7231` constant
65+
* deprecated since PHP 8.5.
66+
*
67+
* @since 33.0.1
68+
*/
69+
public const DATE_RFC7231 = 'D, d M Y H:i:s \G\M\T';
6270
}

tests/lib/AppFramework/Middleware/NotModifiedMiddlewareTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\AppFramework\Controller;
1313
use OCP\AppFramework\Http;
1414
use OCP\AppFramework\Http\Response;
15+
use OCP\Constants;
1516
use OCP\IRequest;
1617

1718
class NotModifiedMiddlewareTest extends \Test\TestCase {
@@ -44,13 +45,13 @@ public static function dataModified(): array {
4445
[null, '"etag"', null, '', false],
4546
['etag', '"etag"', null, '', true],
4647

47-
[null, '', $now, $now->format(\DateTimeInterface::RFC7231), true],
48+
[null, '', $now, $now->format(Constants::DATE_RFC7231), true],
4849
[null, '', $now, $now->format(\DateTimeInterface::ATOM), false],
49-
[null, '', null, $now->format(\DateTimeInterface::RFC7231), false],
50+
[null, '', null, $now->format(Constants::DATE_RFC7231), false],
5051
[null, '', $now, '', false],
5152

5253
['etag', '"etag"', $now, $now->format(\DateTimeInterface::ATOM), true],
53-
['etag', '"etag"', $now, $now->format(\DateTimeInterface::RFC7231), true],
54+
['etag', '"etag"', $now, $now->format(Constants::DATE_RFC7231), true],
5455
];
5556
}
5657

0 commit comments

Comments
 (0)