Skip to content

Commit 4054060

Browse files
committed
Issue #3112283 by ravi.shankar, mpdonadio, andregp, daffie, jhedstrom, alexpott, andypost, pifagor, vladbo, JeroenT, voleger, cliddell: Replace REQUEST_TIME in non-OO and non-module code
1 parent 1693614 commit 4054060

8 files changed

+16
-33
lines changed

core.api.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
* // Find out when cron was last run; the key is 'system.cron_last'.
189189
* $time = $state->get('system.cron_last');
190190
* // Set the cron run time to the current request time.
191-
* $state->set('system.cron_last', REQUEST_TIME);
191+
* $state->set('system.cron_last', \Drupal::time()->getRequestTime());
192192
* @endcode
193193
*
194194
* For more on the State API, see https://www.drupal.org/developing/api/8/state
@@ -1919,10 +1919,11 @@ function hook_cron() {
19191919
// Short-running operation example, not using a queue:
19201920
// Delete all expired records since the last cron run.
19211921
$expires = \Drupal::state()->get('mymodule.last_check', 0);
1922+
$request_time = \Drupal::time()->getRequestTime();
19221923
\Drupal::database()->delete('mymodule_table')
19231924
->condition('expires', $expires, '>=')
19241925
->execute();
1925-
\Drupal::state()->set('mymodule.last_check', REQUEST_TIME);
1926+
\Drupal::state()->set('mymodule.last_check', $request_time);
19261927

19271928
// Long-running operation example, leveraging a queue:
19281929
// Queue news feeds for updates once their refresh interval has elapsed.
@@ -1931,13 +1932,13 @@ function hook_cron() {
19311932
foreach (Feed::loadMultiple($ids) as $feed) {
19321933
if ($queue->createItem($feed)) {
19331934
// Add timestamp to avoid queueing item more than once.
1934-
$feed->setQueuedTime(REQUEST_TIME);
1935+
$feed->setQueuedTime($request_time);
19351936
$feed->save();
19361937
}
19371938
}
19381939
$ids = \Drupal::entityQuery('mymodule_feed')
19391940
->accessCheck(FALSE)
1940-
->condition('queued', REQUEST_TIME - (3600 * 6), '<')
1941+
->condition('queued', $request_time - (3600 * 6), '<')
19411942
->execute();
19421943
if ($ids) {
19431944
$feeds = Feed::loadMultiple($ids);

includes/bootstrap.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function drupal_valid_test_ua($new_prefix = NULL) {
252252
}
253253
// The file properties add more entropy not easily accessible to others.
254254
$key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
255-
$time_diff = REQUEST_TIME - $time;
255+
$time_diff = time() - $time;
256256
$test_hmac = Crypt::hmacBase64($check_string, $key);
257257
// Since we are making a local request a 600 second time window is allowed,
258258
// and the HMAC must match.

includes/common.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ function drupal_flush_all_caches($kernel = NULL) {
532532
*/
533533
function _drupal_flush_css_js() {
534534
// The timestamp is converted to base 36 in order to make it more compact.
535-
Drupal::state()->set('system.css_js_query_string', base_convert(REQUEST_TIME, 10, 36));
535+
Drupal::state()->set('system.css_js_query_string', base_convert(\Drupal::time()->getRequestTime(), 10, 36));
536536
}
537537

538538
/**

includes/install.core.inc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,12 @@ function install_display_output($output, $install_state) {
10541054

10551055
$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
10561056
$response = $bare_html_page_renderer->renderBarePage($output, $output['#title'], 'install_page', $regions);
1057+
$request_time = \Drupal::time()->getRequestTime();
10571058
$default_headers = [
10581059
'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',
1059-
'Last-Modified' => gmdate(DATE_RFC1123, REQUEST_TIME),
1060+
'Last-Modified' => gmdate(DATE_RFC1123, $request_time),
10601061
'Cache-Control' => 'no-cache, must-revalidate',
1061-
'ETag' => '"' . REQUEST_TIME . '"',
1062+
'ETag' => '"' . $request_time . '"',
10621063
];
10631064
$response->headers->add($default_headers);
10641065
$response->send();
@@ -1881,7 +1882,7 @@ function install_finished(&$install_state) {
18811882
\Drupal::messenger()->addStatus($success_message);
18821883

18831884
// Record when this install ran.
1884-
\Drupal::state()->set('install_time', $_SERVER['REQUEST_TIME']);
1885+
\Drupal::state()->set('install_time', \Drupal::time()->getRequestTime());
18851886
}
18861887

18871888
/**

phpstan-baseline.neon

-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
5-
count: 1
6-
path: includes/bootstrap.inc
7-
8-
-
9-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
10-
count: 1
11-
path: includes/common.inc
12-
133
-
144
message: "#^Function format_size\\(\\) should return Drupal\\\\Core\\\\StringTranslation\\\\TranslatableMarkup but return statement is missing\\.$#"
155
count: 1
166
path: includes/common.inc
177

18-
-
19-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
20-
count: 2
21-
path: includes/install.core.inc
22-
238
-
249
message: "#^Function install_config_download_translations\\(\\) should return string but return statement is missing\\.$#"
2510
count: 1
@@ -2618,7 +2603,6 @@ parameters:
26182603
count: 1
26192604
path: modules/system/tests/modules/service_provider_test/src/TestFileUsage.php
26202605

2621-
26222606
-
26232607
message: "#^Access to an undefined property Drupal\\\\Tests\\\\system\\\\Functional\\\\Entity\\\\EntityListBuilderTest\\:\\:\\$webUser\\.$#"
26242608
count: 1
@@ -3524,7 +3508,6 @@ parameters:
35243508
count: 1
35253509
path: modules/workspaces/src/WorkspacePublisher.php
35263510

3527-
35283511
-
35293512
message: "#^Access to an undefined property Drupal\\\\Tests\\\\workspaces\\\\Kernel\\\\EntityReferenceSupportedNewEntitiesConstraintValidatorTest\\:\\:\\$entityTypeManager\\.$#"
35303513
count: 2
@@ -3540,11 +3523,6 @@ parameters:
35403523
count: 5
35413524
path: profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php
35423525

3543-
-
3544-
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:10\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
3545-
count: 1
3546-
path: rebuild.php
3547-
35483526
-
35493527
message: "#^Access to an undefined property Drupal\\\\BuildTests\\\\Framework\\\\BuildTestBase\\:\\:\\$phpFinder\\.$#"
35503528
count: 1

phpstan.neon.dist

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ parameters:
1818
- ../*/node_modules/*
1919
- */tests/fixtures/*.php
2020
- */tests/fixtures/*.php.gz
21+
# Skip Drupal 6 & 7 code.
22+
- core/scripts/generate-d6-content.sh
23+
- core/scripts/generate-d7-content.sh
2124
# Skip data files.
2225
- lib/Drupal/Component/Transliteration/data/*.php
2326
# Below extends on purpose a non existing class for testing.

rebuild.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
if (Settings::get('rebuild_access', FALSE) ||
4040
($request->query->get('token') && $request->query->get('timestamp') &&
41-
((REQUEST_TIME - $request->query->get('timestamp')) < 300) &&
41+
(($request->server->getInt('REQUEST_TIME') - $request->query->get('timestamp')) < 300) &&
4242
hash_equals(Crypt::hmacBase64($request->query->get('timestamp'), Settings::get('hash_salt')), $request->query->get('token'))
4343
)) {
4444
// Clear user cache for all major platforms.

scripts/generate-d7-content.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ for ($i = 0; $i < 12; $i++) {
237237
$node->status = intval($i / 2) % 2;
238238
$node->revision = 1;
239239
$node->promote = $i % 2;
240-
$node->created = REQUEST_TIME + $i * 43200;
240+
$node->created = $_SERVER['REQUEST_TIME'] + $i * 43200;
241241
$node->runtime = 0;
242242
$node->active = 1;
243243
$node->log = "added $i poll";

0 commit comments

Comments
 (0)