diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 5288a3fd068..e8ced14154b 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -163,12 +163,13 @@ function aggregator_entity_extra_field_info() { */ function aggregator_cron() { $queue = \Drupal::queue('aggregator_feeds'); + $request_time = \Drupal::time()->getRequestTime(); $ids = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->getFeedIdsToRefresh(); 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(); } } @@ -176,7 +177,7 @@ function aggregator_cron() { // Delete queued timestamp after 6 hours assuming the update has failed. $ids = \Drupal::entityQuery('aggregator_feed') ->accessCheck(FALSE) - ->condition('queued', REQUEST_TIME - (3600 * 6), '<') + ->condition('queued', $request_time - (3600 * 6), '<') ->execute(); if ($ids) { diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8b3e026ba72..caf6a7a89e2 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -35,9 +35,9 @@ use Drupal\user\UserInterface; * Comments changed after this time may be marked new, updated, or read, * depending on their state for the current user. Defaults to 30 days ago. * - * @todo Remove when https://www.drupal.org/node/1029708 lands. + * @todo Remove when https://www.drupal.org/node/2006632 lands. */ -define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60); +define('COMMENT_NEW_LIMIT', ((int) $_SERVER['REQUEST_TIME']) - 30 * 24 * 60 * 60); /** * Implements hook_help(). diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 8e3f7e09884..b43532e6110 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -648,7 +648,7 @@ function file_cron() { $fids = Drupal::entityQuery('file') ->accessCheck(FALSE) ->condition('status', FileInterface::STATUS_PERMANENT, '<>') - ->condition('changed', REQUEST_TIME - $age, '<') + ->condition('changed', \Drupal::time()->getRequestTime() - $age, '<') ->range(0, 100) ->execute(); $files = $file_storage->loadMultiple($fids); diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 02dd964fd7c..d7ca78246a4 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -20,8 +20,10 @@ use Drupal\user\UserInterface; * * Entities changed within this time may be marked as new, updated, or read, * depending on their state for the current user. Defaults to 30 days ago. + * + * @todo Remove when https://www.drupal.org/node/2006632 lands. */ -define('HISTORY_READ_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60); +define('HISTORY_READ_LIMIT', ((int) $_SERVER['REQUEST_TIME']) - 30 * 24 * 60 * 60); /** * Implements hook_help(). @@ -109,16 +111,17 @@ function history_write($nid, $account = NULL) { } if ($account->isAuthenticated()) { + $request_time = \Drupal::time()->getRequestTime(); \Drupal::database()->merge('history') ->keys([ 'uid' => $account->id(), 'nid' => $nid, ]) - ->fields(['timestamp' => REQUEST_TIME]) + ->fields(['timestamp' => $request_time]) ->execute(); // Update static cache. $history = &drupal_static('history_read_multiple', []); - $history[$nid] = REQUEST_TIME; + $history[$nid] = $request_time; } } diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc index 178e5464b17..9921e7b94b3 100644 --- a/core/modules/image/image.admin.inc +++ b/core/modules/image/image.admin.inc @@ -27,7 +27,7 @@ function template_preprocess_image_style_preview(&$variables) { $variables['style_name'] = $style->label(); // Cache bypass token. - $variables['cache_bypass'] = REQUEST_TIME; + $variables['cache_bypass'] = \Drupal::time()->getRequestTime(); // Sample image info. $sample_width = 160; diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index 106bc62b7ae..2b956e87353 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -119,7 +119,7 @@ function locale_translation_batch_status_finished($success, $results) { if (!isset($results['failed_files']) && !isset($results['files'])) { \Drupal::messenger()->addStatus(t('Nothing to check.')); } - \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); + \Drupal::state()->set('locale.translation_last_checked', \Drupal::time()->getRequestTime()); } else { \Drupal::messenger()->addError(t('An error occurred trying to check available interface translation updates.')); @@ -219,7 +219,7 @@ function locale_translation_batch_fetch_import($project, $langcode, $options, &$ function locale_translation_batch_fetch_finished($success, $results) { \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.bulk'); if ($success) { - \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); + \Drupal::state()->set('locale.translation_last_checked', \Drupal::time()->getRequestTime()); } return locale_translate_batch_finished($success, $results); } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 611d44b85d6..4afd06e4c0b 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -275,6 +275,7 @@ function locale_translate_batch_import($file, array $options, &$context) { */ function locale_translate_batch_import_save($context) { if (isset($context['results']['files'])) { + $request_time = \Drupal::time()->getRequestTime(); foreach ($context['results']['files'] as $file) { // Update the file history if both project and version are known. This // table is used by the automated translation update function which tracks @@ -282,7 +283,7 @@ function locale_translate_batch_import_save($context) { // translation files are not tracked and are therefore not stored in this // table. if ($file->project && $file->version) { - $file->last_checked = REQUEST_TIME; + $file->last_checked = $request_time; locale_translation_update_file_history($file); } } diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 9b0209fd57a..a4dcf3a575a 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -191,7 +191,7 @@ function locale_translation_check_projects($projects = [], $langcodes = []) { else { // Retrieve and save the status of local translations only. locale_translation_check_projects_local($projects, $langcodes); - \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); + \Drupal::state()->set('locale.translation_last_checked', \Drupal::time()->getRequestTime()); } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 1fffee3bcfa..1a30d0bfc18 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -912,6 +912,7 @@ function locale_translation_status_save($project, $langcode, $type, $data) { // Merge the new status data with the existing status. if (isset($status[$project][$langcode])) { + $request_time = \Drupal::time()->getRequestTime(); switch ($type) { case LOCALE_TRANSLATION_REMOTE: case LOCALE_TRANSLATION_LOCAL: @@ -923,14 +924,14 @@ function locale_translation_status_save($project, $langcode, $type, $data) { if (isset($data->timestamp) && $data->timestamp) { if ($data->timestamp > $status[$project][$langcode]->timestamp) { $status[$project][$langcode]->timestamp = $data->timestamp; - $status[$project][$langcode]->last_checked = REQUEST_TIME; + $status[$project][$langcode]->last_checked = $request_time; $status[$project][$langcode]->type = $type; } } break; case LOCALE_TRANSLATION_CURRENT: - $data->last_checked = REQUEST_TIME; + $data->last_checked = $request_time; $status[$project][$langcode]->timestamp = $data->timestamp; $status[$project][$langcode]->last_checked = $data->last_checked; $status[$project][$langcode]->type = $type; @@ -939,7 +940,7 @@ function locale_translation_status_save($project, $langcode, $type, $data) { } \Drupal::keyValue('locale.translation_status')->set($project, $status[$project]); - \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME); + \Drupal::state()->set('locale.translation_last_checked', $request_time); } } diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index efd1aad13be..c879139653d 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -331,7 +331,8 @@ function locale_cron_fill_queue() { $config = \Drupal::config('locale.settings'); // Determine which project+language should be updated. - $last = REQUEST_TIME - $config->get('translation.update_interval_days') * 3600 * 24; + $request_time = \Drupal::time()->getRequestTime(); + $last = $request_time - $config->get('translation.update_interval_days') * 3600 * 24; $projects = \Drupal::service('locale.project')->getAll(); $projects = array_filter($projects, function ($project) { return $project['status'] == 1; @@ -348,7 +349,7 @@ function locale_cron_fill_queue() { // Update the last_checked timestamp of the project+language that will // be checked for updates. $connection->update('locale_file') - ->fields(['last_checked' => REQUEST_TIME]) + ->fields(['last_checked' => $request_time]) ->condition('project', $file->project) ->condition('langcode', $file->langcode) ->execute(); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index f7e282fb72d..936a939994d 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -726,10 +726,11 @@ function system_requirements($phase) { // Determine severity based on time since cron last ran. $severity = REQUIREMENT_INFO; - if (REQUEST_TIME - $cron_last > $threshold_error) { + $request_time = \Drupal::time()->getRequestTime(); + if ($request_time - $cron_last > $threshold_error) { $severity = REQUIREMENT_ERROR; } - elseif (REQUEST_TIME - $cron_last > $threshold_warning) { + elseif ($request_time - $cron_last > $threshold_warning) { $severity = REQUIREMENT_WARNING; } diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index 4c0a83e43bb..8076c4abaea 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -54,17 +54,18 @@ function system_token_info() { $date_formatter = \Drupal::service('date.formatter'); // Date related tokens. + $request_time = \Drupal::time()->getRequestTime(); $date['short'] = [ 'name' => t("Short format"), - 'description' => t("A date in 'short' format. (%date)", ['%date' => $date_formatter->format(REQUEST_TIME, 'short')]), + 'description' => t("A date in 'short' format. (%date)", ['%date' => $date_formatter->format($request_time, 'short')]), ]; $date['medium'] = [ 'name' => t("Medium format"), - 'description' => t("A date in 'medium' format. (%date)", ['%date' => $date_formatter->format(REQUEST_TIME, 'medium')]), + 'description' => t("A date in 'medium' format. (%date)", ['%date' => $date_formatter->format($request_time, 'medium')]), ]; $date['long'] = [ 'name' => t("Long format"), - 'description' => t("A date in 'long' format. (%date)", ['%date' => $date_formatter->format(REQUEST_TIME, 'long')]), + 'description' => t("A date in 'long' format. (%date)", ['%date' => $date_formatter->format($request_time, 'long')]), ]; $date['custom'] = [ 'name' => t("Custom format"), @@ -72,11 +73,11 @@ function system_token_info() { ]; $date['since'] = [ 'name' => t("Time-since"), - 'description' => t("A date in 'time-since' format. (%date)", ['%date' => $date_formatter->formatTimeDiffSince(REQUEST_TIME - 360)]), + 'description' => t("A date in 'time-since' format. (%date)", ['%date' => $date_formatter->formatTimeDiffSince($request_time - 360)]), ]; $date['raw'] = [ 'name' => t("Raw timestamp"), - 'description' => t("A date in UNIX timestamp format (%date)", ['%date' => REQUEST_TIME]), + 'description' => t("A date in UNIX timestamp format (%date)", ['%date' => $request_time]), ]; return [ @@ -157,7 +158,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe elseif ($type == 'date') { if (empty($data['date'])) { - $date = REQUEST_TIME; + $date = \Drupal::time()->getRequestTime(); // We depend on the current request time, so the tokens are not cacheable // at all. $bubbleable_metadata->setCacheMaxAge(0); diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index b1ab4196689..4ae279da241 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -33,6 +33,7 @@ function _update_cron_notify() { $notify_list = $update_config->get('notification.emails'); if (!empty($notify_list)) { $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); + $request_time = \Drupal::time()->getRequestTime(); foreach ($notify_list as $target) { if ($target_user = user_load_by_mail($target)) { $target_langcode = $target_user->getPreferredLangcode(); @@ -44,7 +45,7 @@ function _update_cron_notify() { // Track when the last mail was successfully sent to avoid sending // too many emails. if ($message['result']) { - \Drupal::state()->set('update.last_email_notification', REQUEST_TIME); + \Drupal::state()->set('update.last_email_notification', $request_time); } } } diff --git a/core/modules/update/update.module b/core/modules/update/update.module index b3e1a589697..84e02d97180 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -177,7 +177,8 @@ function update_cron() { $frequency = $update_config->get('check.interval_days'); $interval = 60 * 60 * 24 * $frequency; $last_check = \Drupal::state()->get('update.last_check', 0); - if ((REQUEST_TIME - $last_check) > $interval) { + $request_time = \Drupal::time()->getRequestTime(); + if (($request_time - $last_check) > $interval) { // If the configured update interval has elapsed, we want to invalidate // the data for all projects, attempt to re-fetch, and trigger any // configured notifications about the new status. @@ -190,7 +191,7 @@ function update_cron() { update_get_available(TRUE); } $last_email_notice = \Drupal::state()->get('update.last_email_notification', 0); - if ((REQUEST_TIME - $last_email_notice) > $interval) { + if (($request_time - $last_email_notice) > $interval) { // If configured time between notifications elapsed, send email about // updates possibly available. \Drupal::moduleHandler()->loadInclude('update', 'inc', 'update.fetch'); @@ -702,8 +703,8 @@ function update_delete_file_if_stale($path) { if (file_exists($path)) { $filectime = filectime($path); $max_age = \Drupal::config('system.file')->get('temporary_maximum_age'); - - if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) { + $request_time = \Drupal::time()->getRequestTime(); + if ($request_time - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && $request_time - $filectime > 300)) { try { \Drupal::service('file_system')->deleteRecursive($path); return TRUE; diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 6a37e07e0f6..5eb8c521881 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -459,7 +459,7 @@ function user_login_finalize(UserInterface $account) { \Drupal::logger('user')->notice('Session opened for %name.', ['%name' => $account->getAccountName()]); // Update the user table timestamp noting user has logged in. // This is also used to invalidate one-time login links. - $account->setLastLoginTime(REQUEST_TIME); + $account->setLastLoginTime(\Drupal::time()->getRequestTime()); \Drupal::entityTypeManager() ->getStorage('user') ->updateLastLoginTimestamp($account); @@ -521,7 +521,7 @@ function user_user_logout(AccountInterface $account) { * they can change their password. */ function user_pass_reset_url($account, $options = []) { - $timestamp = REQUEST_TIME; + $timestamp = \Drupal::time()->getRequestTime(); $langcode = $options['langcode'] ?? $account->getPreferredLangcode(); return Url::fromRoute('user.reset', [ @@ -554,7 +554,7 @@ function user_pass_reset_url($account, $options = []) { * @see \Drupal\user\Controller\UserController::confirmCancel() */ function user_cancel_url(UserInterface $account, $options = []) { - $timestamp = REQUEST_TIME; + $timestamp = \Drupal::time()->getRequestTime(); $langcode = $options['langcode'] ?? $account->getPreferredLangcode(); $url_options = ['absolute' => TRUE, 'language' => \Drupal::languageManager()->getLanguage($langcode)]; return Url::fromRoute('user.cancel_confirm', [ @@ -579,7 +579,7 @@ function user_cancel_url(UserInterface $account, $options = []) { * @param \Drupal\user\UserInterface $account * An object containing the user account. * @param int $timestamp - * A UNIX timestamp, typically REQUEST_TIME. + * A UNIX timestamp, typically \Drupal::time()->getRequestTime(). * * @return string * A string that is safe for use in URLs and SQL statements. @@ -1141,9 +1141,10 @@ function user_modules_uninstalled($modules) { * An array of key/value pairs to be saved into a cookie. */ function user_cookie_save(array $values) { + $request_time = \Drupal::time()->getRequestTime(); foreach ($values as $field => $value) { // Set cookie for 365 days. - setrawcookie('Drupal.visitor.' . $field, rawurlencode($value), REQUEST_TIME + 31536000, '/'); + setrawcookie('Drupal.visitor.' . $field, rawurlencode($value), $request_time + 31536000, '/'); } } @@ -1154,7 +1155,7 @@ function user_cookie_save(array $values) { * A cookie name such as 'homepage'. */ function user_cookie_delete($cookie_name) { - setrawcookie('Drupal.visitor.' . $cookie_name, '', REQUEST_TIME - 3600, '/'); + setrawcookie('Drupal.visitor.' . $cookie_name, '', \Drupal::time()->getRequestTime() - 3600, '/'); } /** diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 3c4b2ad148d..9c35ae662b2 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -661,7 +661,7 @@ function hook_views_query_substitutions(ViewExecutable $view) { // Example from views_views_query_substitutions(). return [ '***CURRENT_VERSION***' => \Drupal::VERSION, - '***CURRENT_TIME***' => REQUEST_TIME, + '***CURRENT_TIME***' => \Drupal::time()->getRequestTime(), '***LANGUAGE_language_content***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(), PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => \Drupal::languageManager()->getDefaultLanguage()->getId(), ]; diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 499d860ef65..d2cb65e402e 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -956,7 +956,7 @@ function template_preprocess_views_view_opml(&$variables) { } $variables['title'] = $title; $variables['items'] = $items; - $variables['updated'] = gmdate(DATE_RFC2822, REQUEST_TIME); + $variables['updated'] = gmdate(DATE_RFC2822, \Drupal::time()->getRequestTime()); // During live preview we don't want to output the header since the contents // of the feed are being displayed inside a normal HTML page. diff --git a/core/modules/views/views.views_execution.inc b/core/modules/views/views.views_execution.inc index 60b1adc04c6..3647f52abcc 100644 --- a/core/modules/views/views.views_execution.inc +++ b/core/modules/views/views.views_execution.inc @@ -20,7 +20,7 @@ use Drupal\views\Plugin\views\PluginBase; function views_views_query_substitutions(ViewExecutable $view) { $substitutions = [ '***CURRENT_VERSION***' => \Drupal::VERSION, - '***CURRENT_TIME***' => REQUEST_TIME, + '***CURRENT_TIME***' => \Drupal::time()->getRequestTime(), ] + PluginBase::queryLanguageSubstitutions(); return $substitutions;