Verified Commit 960480f0 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3112283 by ravi.shankar, mpdonadio, andregp, daffie, jhedstrom,...

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

(cherry picked from commit debf7027)
parent dff57737
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@
 * // Find out when cron was last run; the key is 'system.cron_last'.
 * $time = $state->get('system.cron_last');
 * // Set the cron run time to the current request time.
 * $state->set('system.cron_last', REQUEST_TIME);
 * $state->set('system.cron_last', \Drupal::time()->getRequestTime());
 * @endcode
 *
 * For more on the State API, see https://www.drupal.org/developing/api/8/state
@@ -1923,10 +1923,11 @@ function hook_cron() {
  // Short-running operation example, not using a queue:
  // Delete all expired records since the last cron run.
  $expires = \Drupal::state()->get('mymodule.last_check', 0);
  $request_time = \Drupal::time()->getRequestTime();
  \Drupal::database()->delete('mymodule_table')
    ->condition('expires', $expires, '>=')
    ->execute();
  \Drupal::state()->set('mymodule.last_check', REQUEST_TIME);
  \Drupal::state()->set('mymodule.last_check', $request_time);

  // Long-running operation example, leveraging a queue:
  // Queue news feeds for updates once their refresh interval has elapsed.
@@ -1935,13 +1936,13 @@ function hook_cron() {
  foreach (Feed::loadMultiple($ids) as $feed) {
    if ($queue->createItem($feed)) {
      // Add timestamp to avoid queueing item more than once.
      $feed->setQueuedTime(REQUEST_TIME);
      $feed->setQueuedTime($request_time);
      $feed->save();
    }
  }
  $ids = \Drupal::entityQuery('aggregator_feed')
    ->accessCheck(FALSE)
    ->condition('queued', REQUEST_TIME - (3600 * 6), '<')
    ->condition('queued', $request_time - (3600 * 6), '<')
    ->execute();
  if ($ids) {
    $feeds = Feed::loadMultiple($ids);
+1 −1
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ function drupal_valid_test_ua($new_prefix = NULL) {
    }
    // The file properties add more entropy not easily accessible to others.
    $key = $private_key . filectime(__FILE__) . fileinode(__FILE__);
    $time_diff = REQUEST_TIME - $time;
    $time_diff = time() - $time;
    $test_hmac = Crypt::hmacBase64($check_string, $key);
    // Since we are making a local request a 600 second time window is allowed,
    // and the HMAC must match.
+1 −1
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ function drupal_flush_all_caches($kernel = NULL) {
 */
function _drupal_flush_css_js() {
  // The timestamp is converted to base 36 in order to make it more compact.
  Drupal::state()->set('system.css_js_query_string', base_convert(REQUEST_TIME, 10, 36));
  Drupal::state()->set('system.css_js_query_string', base_convert(\Drupal::time()->getRequestTime(), 10, 36));
}

/**
+4 −3
Original line number Diff line number Diff line
@@ -1056,11 +1056,12 @@ function install_display_output($output, $install_state) {

  $bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
  $response = $bare_html_page_renderer->renderBarePage($output, $output['#title'], 'install_page', $regions);
  $request_time = \Drupal::time()->getRequestTime();
  $default_headers = [
    'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',
    'Last-Modified' => gmdate(DATE_RFC1123, REQUEST_TIME),
    'Last-Modified' => gmdate(DATE_RFC1123, $request_time),
    'Cache-Control' => 'no-cache, must-revalidate',
    'ETag' => '"' . REQUEST_TIME . '"',
    'ETag' => '"' . $request_time . '"',
  ];
  $response->headers->add($default_headers);
  $response->send();
@@ -1883,7 +1884,7 @@ function install_finished(&$install_state) {
  \Drupal::messenger()->addStatus($success_message);

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

/**
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@

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