diff --git a/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php index f241a5f188..26ed07f79e 100644 --- a/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php @@ -192,7 +192,7 @@ public function deleteAll() { $delete_stale = function ($uri) { // Default stale file threshold is 30 days. - if (\Drupal::time()->getRequestTime() - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { + if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { $this->fileSystem->delete($uri); } }; diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php index d591a0e8a1..dc66652b6c 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php @@ -194,7 +194,7 @@ public function deleteAll() { $this->state->delete('system.js_cache_files'); $delete_stale = function ($uri) { // Default stale file threshold is 30 days. - if (\Drupal::time()->getRequestTime() - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { + if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) { $this->fileSystem->delete($uri); } }; diff --git a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php index 19314c3aa9..99d0e14f54 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php @@ -40,12 +40,11 @@ public function render(array $js_assets) { $elements = []; // A dummy query-string is added to filenames, to gain control over - // browser-caching. The string changes on every update or full cache flush, - // forcing browsers to load a new copy of the files, as the URL changed. - // Files that should not be cached get - // \Drupal::time()->getRequestTime() as query-string instead, - // to enforce reload on every page request. - $default_query_string = $this->state->get('system.css_js_query_string') ?: '0'; + // browser-caching. The string changes on every update or full cache + // flush, forcing browsers to load a new copy of the files, as the + // URL changed. Files that should not be cached get REQUEST_TIME as + // query-string instead, to enforce reload on every page request. + $default_query_string = $this->state->get('system.css_js_query_string', '0'); // Defaults for each SCRIPT element. $element_defaults = [ @@ -79,7 +78,7 @@ public function render(array $js_assets) { // Only add the cache-busting query string if this isn't an aggregate // file. if (!isset($js_asset['preprocessed'])) { - $element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : \Drupal::time()->getRequestTime()); + $element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME); } break; diff --git a/core/lib/Drupal/Core/Batch/BatchStorage.php b/core/lib/Drupal/Core/Batch/BatchStorage.php index 097d26c469..69efc1b9bb 100644 --- a/core/lib/Drupal/Core/Batch/BatchStorage.php +++ b/core/lib/Drupal/Core/Batch/BatchStorage.php @@ -109,7 +109,7 @@ public function cleanup() { try { // Cleanup the batch table and the queue for failed batches. $this->connection->delete('batch') - ->condition('timestamp', \Drupal::time()->getRequestTime() - 864000, '<') + ->condition('timestamp', REQUEST_TIME - 864000, '<') ->execute(); } catch (\Exception $e) { @@ -152,7 +152,7 @@ protected function doCreate(array $batch) { $this->connection->insert('batch') ->fields([ 'bid' => $batch['id'], - 'timestamp' => \Drupal::time()->getRequestTime(), + 'timestamp' => REQUEST_TIME, 'token' => $this->csrfToken->get($batch['id']), 'batch' => serialize($batch), ]) diff --git a/core/lib/Drupal/Core/Cache/ApcuBackend.php b/core/lib/Drupal/Core/Cache/ApcuBackend.php index ad04efce8b..6014fb8bff 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackend.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackend.php @@ -145,7 +145,7 @@ protected function prepareItem($cache, $allow_invalid) { $cache->tags = $cache->tags ? explode(' ', $cache->tags) : []; // Check expire time. - $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= \Drupal::time()->getRequestTime(); + $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the entry's tags. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { @@ -235,7 +235,7 @@ public function invalidate($cid) { */ public function invalidateMultiple(array $cids) { foreach ($this->getMultiple($cids) as $cache) { - $this->set($cache->cid, $cache, \Drupal::time()->getRequestTime() - 1); + $this->set($cache->cid, $cache, REQUEST_TIME - 1); } } @@ -245,7 +245,7 @@ public function invalidateMultiple(array $cids) { public function invalidateAll() { foreach ($this->getAll() as $data) { $cid = str_replace($this->binPrefix, '', $data['key']); - $this->set($cid, $data['value'], \Drupal::time()->getRequestTime() - 1); + $this->set($cid, $data['value'], REQUEST_TIME - 1); } } diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 16ec1297b5..cb8b099c18 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -151,7 +151,7 @@ protected function prepareItem($cache, $allow_invalid) { $cache->tags = $cache->tags ? explode(' ', $cache->tags) : []; // Check expire time. - $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= \Drupal::time()->getRequestTime(); + $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the items's tags. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { @@ -336,7 +336,7 @@ public function invalidateMultiple(array $cids) { // Update in chunks when a large array is passed. foreach (array_chunk($cids, 1000) as $cids_chunk) { $this->connection->update($this->bin) - ->fields(['expire' => \Drupal::time()->getRequestTime() - 1]) + ->fields(['expire' => REQUEST_TIME - 1]) ->condition('cid', $cids_chunk, 'IN') ->execute(); } @@ -352,7 +352,7 @@ public function invalidateMultiple(array $cids) { public function invalidateAll() { try { $this->connection->update($this->bin) - ->fields(['expire' => \Drupal::time()->getRequestTime() - 1]) + ->fields(['expire' => REQUEST_TIME - 1]) ->execute(); } catch (\Exception $e) { @@ -383,7 +383,7 @@ public function garbageCollection() { $this->connection->delete($this->bin) ->condition('expire', Cache::PERMANENT, '<>') - ->condition('expire', \Drupal::time()->getRequestTime(), '<') + ->condition('expire', REQUEST_TIME, '<') ->execute(); } catch (\Exception $e) { diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index e1899ddfb1..d402d70b54 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -196,12 +196,12 @@ public function removeBin() { } /** - * Wrapper method for $_SERVER['REQUEST_TIME']. + * Wrapper method for REQUEST_TIME constant. * * @return int */ protected function getRequestTime() { - return \Drupal::hasContainer() ? \Drupal::time()->getRequestTime() : (int) $_SERVER['REQUEST_TIME']; + return defined('REQUEST_TIME') ? REQUEST_TIME : (int) $_SERVER['REQUEST_TIME']; } /** diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index 174360f45f..e4628781b2 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -126,7 +126,7 @@ protected function prepareItem($cache, $allow_invalid) { } // Check expire time. - $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= \Drupal::time()->getRequestTime(); + $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the item's tags. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { @@ -195,7 +195,7 @@ public function invalidate($cid) { */ protected function invalidatebyHash($cidhash) { if ($item = $this->getByHash($cidhash)) { - $item->expire = \Drupal::time()->getRequestTime() - 1; + $item->expire = REQUEST_TIME - 1; $this->writeItem($cidhash, $item); } } diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 9bcff72aaa..747262c849 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -248,8 +248,8 @@ protected function setResponseCacheable(Response $response, Request $request) { // In order to support HTTP cache-revalidation, ensure that there is a // Last-Modified and an ETag header on the response. if (!$response->headers->has('Last-Modified')) { - $timestamp = \Drupal::time()->getRequestTime(); - $response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC7231, \Drupal::time()->getRequestTime()))); + $timestamp = REQUEST_TIME; + $response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC7231, REQUEST_TIME))); } else { $timestamp = $response->getLastModified()->getTimestamp(); diff --git a/core/lib/Drupal/Core/Flood/DatabaseBackend.php b/core/lib/Drupal/Core/Flood/DatabaseBackend.php index 80fcdacf06..afb295546c 100644 --- a/core/lib/Drupal/Core/Flood/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Flood/DatabaseBackend.php @@ -83,8 +83,8 @@ protected function doInsert($name, $window, $identifier) { ->fields([ 'event' => $name, 'identifier' => $identifier, - 'timestamp' => \Drupal::time()->getRequestTime(), - 'expiration' => \Drupal::time()->getRequestTime() + $window, + 'timestamp' => REQUEST_TIME, + 'expiration' => REQUEST_TIME + $window, ]) ->execute(); } @@ -118,7 +118,7 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) $number = $this->connection->select(static::TABLE_NAME, 'f') ->condition('event', $name) ->condition('identifier', $identifier) - ->condition('timestamp', \Drupal::time()->getRequestTime() - $window, '>') + ->condition('timestamp', REQUEST_TIME - $window, '>') ->countQuery() ->execute() ->fetchField(); @@ -136,7 +136,7 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) public function garbageCollection() { try { $return = $this->connection->delete(static::TABLE_NAME) - ->condition('expiration', \Drupal::time()->getRequestTime(), '<') + ->condition('expiration', REQUEST_TIME, '<') ->execute(); } catch (\Exception $e) { diff --git a/core/lib/Drupal/Core/Flood/MemoryBackend.php b/core/lib/Drupal/Core/Flood/MemoryBackend.php index b60ec8494f..9899e35e7e 100644 --- a/core/lib/Drupal/Core/Flood/MemoryBackend.php +++ b/core/lib/Drupal/Core/Flood/MemoryBackend.php @@ -38,8 +38,8 @@ public function register($name, $window = 3600, $identifier = NULL) { if (!isset($identifier)) { $identifier = $this->requestStack->getCurrentRequest()->getClientIp(); } - // We can't use \Drupal::time()->getRequestTime() here, because that would - // not guarantee uniqueness. + // We can't use REQUEST_TIME here, because that would not guarantee + // uniqueness. $time = microtime(TRUE); $this->events[$name][$identifier][$time + $window] = $time; } diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php index abc213a1fa..f9c9b4c17a 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php @@ -59,7 +59,7 @@ public function get($collection) { */ public function garbageCollection() { $this->connection->delete('key_value_expire') - ->condition('expire', \Drupal::time()->getRequestTime(), '<') + ->condition('expire', REQUEST_TIME, '<') ->execute(); } diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index 495ef82a20..5673f6627b 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -332,12 +332,12 @@ protected function pathAliasWhitelistRebuild($path = NULL) { } /** - * Wrapper method for \Drupal::time()->getRequestTime(). + * Wrapper method for REQUEST_TIME constant. * * @return int */ protected function getRequestTime() { - return \Drupal::hasContainer() ? \Drupal::time()->getRequestTime() : (int) $_SERVER['REQUEST_TIME']; + return defined('REQUEST_TIME') ? REQUEST_TIME : (int) $_SERVER['REQUEST_TIME']; } } diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index 0213060ac7..784042aa68 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -76,7 +76,7 @@ public function write($sid, $value) { 'uid' => $request->getSession()->get('uid', 0), 'hostname' => $request->getClientIP(), 'session' => $value, - 'timestamp' => \Drupal::time()->getRequestTime(), + 'timestamp' => REQUEST_TIME, ]; $this->connection->merge('sessions') ->keys(['sid' => Crypt::hashBase64($sid)]) @@ -125,7 +125,7 @@ public function gc($lifetime) { // to '1814400'. At that value, only after a user doesn't log in after // three weeks (1814400 seconds) will their session be removed. $this->connection->delete('sessions') - ->condition('timestamp', \Drupal::time()->getRequestTime() - $lifetime, '<') + ->condition('timestamp', REQUEST_TIME - $lifetime, '<') ->execute(); return TRUE; } diff --git a/core/lib/Drupal/Core/Session/SessionManager.php b/core/lib/Drupal/Core/Session/SessionManager.php index c63b59dc62..27e05809ad 100644 --- a/core/lib/Drupal/Core/Session/SessionManager.php +++ b/core/lib/Drupal/Core/Session/SessionManager.php @@ -232,7 +232,7 @@ public function regenerate($destroy = FALSE, $lifetime = NULL) { if (isset($old_session_id)) { $params = session_get_cookie_params(); - $expire = $params['lifetime'] ? \Drupal::time()->getRequestTime() + $params['lifetime'] : 0; + $expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0; setcookie($this->getName(), $this->getId(), $expire, $params['path'], $params['domain'], $params['secure'], $params['httponly']); $this->migrateStoredSession($old_session_id); } @@ -265,7 +265,7 @@ public function destroy() { // setcookie() can only be called when headers are not yet sent. if ($cookies->has($session_name) && !headers_sent()) { $params = session_get_cookie_params(); - setcookie($session_name, '', \Drupal::time()->getRequestTime() - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']); + setcookie($session_name, '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']); $cookies->remove($session_name); } } diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index e85f19d65b..5beb15441c 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -120,12 +120,12 @@ public function adminOverview() { $last_checked = $feed->getLastCheckedTime(); $refresh_rate = $feed->getRefreshRate(); - $row[] = ($last_checked ? $this->t('@time ago', ['@time' => $this->dateFormatter->formatInterval(\Drupal::time()->getRequestTime() - $last_checked)]) : $this->t('never')); + $row[] = ($last_checked ? $this->t('@time ago', ['@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked)]) : $this->t('never')); if (!$last_checked && $refresh_rate) { $next_update = $this->t('imminently'); } elseif ($last_checked && $refresh_rate) { - $next_update = $next = $this->t('%time left', ['%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - \Drupal::time()->getRequestTime())]); + $next_update = $next = $this->t('%time left', ['%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME)]); } else { $next_update = $this->t('never'); diff --git a/core/modules/aggregator/src/FeedStorage.php b/core/modules/aggregator/src/FeedStorage.php index 5dc7cbdcdf..fc5eddeae7 100644 --- a/core/modules/aggregator/src/FeedStorage.php +++ b/core/modules/aggregator/src/FeedStorage.php @@ -17,7 +17,7 @@ class FeedStorage extends SqlContentEntityStorage implements FeedStorageInterfac */ public function getFeedIdsToRefresh() { return $this->database->query('SELECT fid FROM {' . $this->getBaseTable() . '} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', [ - ':time' => \Drupal::time()->getRequestTime(), + ':time' => REQUEST_TIME, ':never' => static::CLEAR_NEVER, ])->fetchCol(); } diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index caa360d2ac..5f0eade44e 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -257,7 +257,7 @@ public function postProcess(FeedInterface $feed) { if ($aggregator_clear != FeedStorageInterface::CLEAR_NEVER) { // Delete all items that are older than flush item timer. - $age = \Drupal::time()->getRequestTime() - $aggregator_clear; + $age = REQUEST_TIME - $aggregator_clear; $result = $this->itemStorage->getQuery() ->condition('fid', $feed->id()) ->condition('timestamp', $age, '<') diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index b8197c8648..48c72712df 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -284,7 +284,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { $comment->setCreatedTime($form_state->getValue('date')->getTimestamp()); } else { - $comment->setCreatedTime(\Drupal::time()->getRequestTime()); + $comment->setCreatedTime(REQUEST_TIME); } // Empty author ID should revert to anonymous. $author_id = $form_state->getValue('uid'); diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index 32867fe210..1bcb22a38b 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -136,9 +136,8 @@ public function create(FieldableEntityInterface $entity, $fields) { // EntityOwnerInterface or author is not set. $last_comment_uid = $this->currentUser->id(); } - // Default to \Drupal::time()->getRequestTime() when entity does not have - // a changed property. - $last_comment_timestamp = \Drupal::time()->getRequestTime(); + // Default to REQUEST_TIME when entity does not have a changed property. + $last_comment_timestamp = REQUEST_TIME; // @todo Make comment statistics language aware and add some tests. See // https://www.drupal.org/node/2318875 if ($entity instanceof EntityChangedInterface) { @@ -259,8 +258,8 @@ public function update(CommentInterface $comment) { 'cid' => 0, 'comment_count' => 0, // Use the changed date of the entity if it's set, or default to - // \Drupal::time()->getRequestTime(). - 'last_comment_timestamp' => ($entity instanceof EntityChangedInterface) ? $entity->getChangedTimeAcrossTranslations() : \Drupal::time()->getRequestTime(), + // REQUEST_TIME. + 'last_comment_timestamp' => ($entity instanceof EntityChangedInterface) ? $entity->getChangedTimeAcrossTranslations() : REQUEST_TIME, 'last_comment_name' => '', 'last_comment_uid' => $last_comment_uid, ]) diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 8373515663..44dea176d5 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -521,14 +521,14 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En '#description' => t('Leave blank for %anonymous.', ['%anonymous' => \Drupal::config('user.settings')->get('anonymous')]), ]; - $date = $new_translation ? \Drupal::time()->getRequestTime() : $metadata->getCreatedTime(); + $date = $new_translation ? REQUEST_TIME : $metadata->getCreatedTime(); $form['content_translation']['created'] = [ '#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', [ - '%time' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), 'custom', 'Y-m-d H:i:s O'), - '%timezone' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), 'custom', 'O'), + '%time' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'), + '%timezone' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'O'), ]), '#default_value' => $new_translation || !$date ? '' : $this->dateFormatter->format($date, 'custom', 'Y-m-d H:i:s O'), ]; @@ -678,7 +678,7 @@ public function entityFormEntityBuild($entity_type, EntityInterface $entity, arr $metadata = $this->manager->getTranslationMetadata($entity); $metadata->setAuthor(!empty($values['uid']) ? User::load($values['uid']) : User::load(0)); $metadata->setPublished(!empty($values['status'])); - $metadata->setCreatedTime(!empty($values['created']) ? strtotime($values['created']) : \Drupal::time()->getRequestTime()); + $metadata->setCreatedTime(!empty($values['created']) ? strtotime($values['created']) : REQUEST_TIME); $metadata->setOutdated(!empty($values['outdated'])); if (!empty($values['retranslate'])) { @@ -725,7 +725,7 @@ public function entityFormSubmit($form, FormStateInterface $form_state) { // handler as well and have the same logic like in the Form API. if ($entity->hasField('content_translation_changed')) { $metadata = $this->manager->getTranslationMetadata($entity); - $metadata->setChangedTime(\Drupal::time()->getRequestTime()); + $metadata->setChangedTime(REQUEST_TIME); } } diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index c9eb61b4fa..5d48cc0533 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -88,7 +88,7 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter // Update the translation author to current user, as well the translation // creation time. $metadata->setAuthor($user); - $metadata->setCreatedTime(\Drupal::time()->getRequestTime()); + $metadata->setCreatedTime(REQUEST_TIME); $metadata->setSource($source_langcode); } diff --git a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php index a01b1b21d8..02288da1c4 100644 --- a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php +++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php @@ -81,7 +81,7 @@ public function query() { // Hey, Drupal kills old history, so nodes that haven't been updated // since HISTORY_READ_LIMIT are bzzzzzzzt outta here! - $limit = \Drupal::time()->getRequestTime() - HISTORY_READ_LIMIT; + $limit = REQUEST_TIME - HISTORY_READ_LIMIT; $this->ensureMyTable(); $field = "$this->tableAlias.$this->realField"; diff --git a/core/modules/locale/src/Form/TranslationStatusForm.php b/core/modules/locale/src/Form/TranslationStatusForm.php index 2986ea9c91..a6d914afe9 100644 --- a/core/modules/locale/src/Form/TranslationStatusForm.php +++ b/core/modules/locale/src/Form/TranslationStatusForm.php @@ -280,7 +280,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // translation updates. If the status is expired we clear it an run a batch to // update the status and then fetch the translation updates. $last_checked = $this->state->get('locale.translation_last_checked'); - if ($last_checked < \Drupal::time()->getRequestTime() - LOCALE_TRANSLATION_STATUS_TTL) { + if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) { locale_translation_clear_status(); $batch = locale_translation_batch_update_build([], $langcodes, $options); batch_set($batch); diff --git a/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php index 74072e721a..5be85c42f2 100644 --- a/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php @@ -244,7 +244,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { batch_set($batch); $form_state->setRedirect(''); $this->store->set('step', 'overview'); - $this->state->set('migrate_drupal_ui.performed', \Drupal::time()->getRequestTime()); + $this->state->set('migrate_drupal_ui.performed', REQUEST_TIME); } /** diff --git a/core/modules/search/search.services.yml b/core/modules/search/search.services.yml index 4ba5ba929b..49ec2acb7b 100644 --- a/core/modules/search/search.services.yml +++ b/core/modules/search/search.services.yml @@ -9,4 +9,4 @@ services: search.index: class: Drupal\search\SearchIndex - arguments: ['@config.factory', '@database','@database.replica', '@cache_tags.invalidator', '@datetime.time'] + arguments: ['@config.factory', '@database','@database.replica', '@cache_tags.invalidator'] diff --git a/core/modules/search/src/SearchIndex.php b/core/modules/search/src/SearchIndex.php index f0d56a9c69..e5655d4974 100644 --- a/core/modules/search/src/SearchIndex.php +++ b/core/modules/search/src/SearchIndex.php @@ -2,7 +2,6 @@ namespace Drupal\search; -use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; @@ -42,13 +41,6 @@ class SearchIndex implements SearchIndexInterface { */ protected $cacheTagsInvalidator; - /** - * The time service. - * - * @var \Drupal\Component\Datetime\TimeInterface - */ - protected $time; - /** * SearchIndex constructor. * @@ -60,15 +52,12 @@ class SearchIndex implements SearchIndexInterface { * The database replica connection. * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator * The cache tags invalidator. - * @param \Drupal\Component\Datetime\TimeInterface $time - * The time service. */ - public function __construct(ConfigFactoryInterface $config_factory, Connection $connection, Connection $replica, CacheTagsInvalidatorInterface $cache_tags_invalidator, TimeInterface $time) { + public function __construct(ConfigFactoryInterface $config_factory, Connection $connection, Connection $replica, CacheTagsInvalidatorInterface $cache_tags_invalidator) { $this->configFactory = $config_factory; $this->connection = $connection; $this->replica = $replica; $this->cacheTagsInvalidator = $cache_tags_invalidator; - $this->time = $time; } /** @@ -267,7 +256,7 @@ public function markForReindex($type = NULL, $sid = NULL, $langcode = NULL) { try { $query = $this->connection->update('search_dataset') - ->fields(['reindex' => $this->time->getRequestTime()]) + ->fields(['reindex' => REQUEST_TIME]) // Only mark items that were not previously marked for reindex, so that // marked items maintain their priority by request time. ->condition('reindex', 0); diff --git a/core/modules/system/src/DateFormatListBuilder.php b/core/modules/system/src/DateFormatListBuilder.php index cf65b21c13..0c94a64197 100644 --- a/core/modules/system/src/DateFormatListBuilder.php +++ b/core/modules/system/src/DateFormatListBuilder.php @@ -64,7 +64,7 @@ public function buildHeader() { */ public function buildRow(EntityInterface $entity) { $row['label'] = $entity->label(); - $row['pattern'] = $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $entity->id()); + $row['pattern'] = $this->dateFormatter->format(REQUEST_TIME, $entity->id()); return $row + parent::buildRow($entity); } diff --git a/core/modules/system/src/Form/DateFormatDeleteForm.php b/core/modules/system/src/Form/DateFormatDeleteForm.php index 39fd6dbb86..1558032825 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -45,7 +45,7 @@ public static function create(ContainerInterface $container) { public function getQuestion() { return t('Are you sure you want to delete the format %name : %format?', [ '%name' => $this->entity->label(), - '%format' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $this->entity->id()), + '%format' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id()), ]); } diff --git a/core/modules/system/src/Form/DateFormatEditForm.php b/core/modules/system/src/Form/DateFormatEditForm.php index 083b117492..d6ad88e8ea 100644 --- a/core/modules/system/src/Form/DateFormatEditForm.php +++ b/core/modules/system/src/Form/DateFormatEditForm.php @@ -17,7 +17,7 @@ class DateFormatEditForm extends DateFormatFormBase { public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - $now = t('Displayed as %date', ['%date' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $this->entity->id())]); + $now = t('Displayed as %date', ['%date' => $this->dateFormatter->format(REQUEST_TIME, $this->entity->id())]); $form['date_format_pattern']['#field_suffix'] = ' ' . $now . ''; $form['date_format_pattern']['#default_value'] = $this->entity->getPattern(); diff --git a/core/modules/toolbar/src/Controller/ToolbarController.php b/core/modules/toolbar/src/Controller/ToolbarController.php index 494d0f34bf..c94e35b307 100644 --- a/core/modules/toolbar/src/Controller/ToolbarController.php +++ b/core/modules/toolbar/src/Controller/ToolbarController.php @@ -34,7 +34,7 @@ public function subtreesAjax() { $response->setMaxAge($max_age); $expires = new \DateTime(); - $expires->setTimestamp(\Drupal::time()->getRequestTime() + $max_age); + $expires->setTimestamp(REQUEST_TIME + $max_age); $response->setExpires($expires); return $response; diff --git a/core/modules/update/src/UpdateProcessor.php b/core/modules/update/src/UpdateProcessor.php index fd62e4c275..25dfc7a004 100644 --- a/core/modules/update/src/UpdateProcessor.php +++ b/core/modules/update/src/UpdateProcessor.php @@ -118,7 +118,7 @@ public function createFetchTask($project) { if (empty($this->fetchTasks[$project['name']])) { $this->fetchQueue->createItem($project); $this->fetchTaskStore->set($project['name'], $project); - $this->fetchTasks[$project['name']] = \Drupal::time()->getRequestTime(); + $this->fetchTasks[$project['name']] = REQUEST_TIME; } } @@ -139,9 +139,9 @@ public function fetchData() { public function processFetchTask($project) { global $base_url; - // This can be in the middle of a long-running batch, - // so \Drupal::time()->getRequestTime() won't necessarily be valid. - $request_time_difference = \Drupal::time()->getCurrentTime() - \Drupal::time()->getRequestTime(); + // This can be in the middle of a long-running batch, so REQUEST_TIME won't + // necessarily be valid. + $request_time_difference = time() - REQUEST_TIME; if (empty($this->failed)) { // If we have valid data about release history XML servers that we have // failed to fetch from on previous attempts, load that. @@ -179,14 +179,14 @@ public function processFetchTask($project) { } $frequency = $this->updateSettings->get('check.interval_days'); - $available['last_fetch'] = \Drupal::time()->getRequestTime() + $request_time_difference; + $available['last_fetch'] = REQUEST_TIME + $request_time_difference; $this->availableReleasesTempStore->setWithExpire($project_name, $available, $request_time_difference + (60 * 60 * 24 * $frequency)); // Stash the $this->failed data back in the DB for the next 5 minutes. $this->tempStore->setWithExpire('fetch_failures', $this->failed, $request_time_difference + (60 * 5)); // Whether this worked or not, we did just (try to) check for updates. - $this->stateStore->set('update.last_check', \Drupal::time()->getRequestTime() + $request_time_difference); + $this->stateStore->set('update.last_check', REQUEST_TIME + $request_time_difference); // Now that we processed the fetch task for this project, clear out the // record for this task so we're willing to fetch again. diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index da7cc672c5..7516da93c6 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -225,7 +225,7 @@ public function getResetPassForm(Request $request, $uid) { */ public function resetPassLogin($uid, $timestamp, $hash) { // The current user is not logged in, so check the parameters. - $current = \Drupal::time()->getRequestTime(); + $current = REQUEST_TIME; /** @var \Drupal\user\UserInterface $user */ $user = $this->userStorage->load($uid); @@ -337,7 +337,7 @@ public function logout() { public function confirmCancel(UserInterface $user, $timestamp = 0, $hashed_pass = '') { // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds. $timeout = 86400; - $current = \Drupal::time()->getRequestTime(); + $current = REQUEST_TIME; // Basic validation of arguments. $account_data = $this->userData->get('user', $user->id()); diff --git a/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php b/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php index bf5cc57640..bf0e621ac1 100644 --- a/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php +++ b/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php @@ -55,11 +55,11 @@ public function __construct(AccountInterface $account, EntityTypeManagerInterfac * The event to process. */ public function onKernelTerminate(PostResponseEvent $event) { - if ($this->account->isAuthenticated() && \Drupal::time()->getRequestTime() - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { + if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) { // Do that no more than once per 180 seconds. /** @var \Drupal\user\UserStorageInterface $storage */ $storage = $this->entityTypeManager->getStorage('user'); - $storage->updateLastAccessTimestamp($this->account, \Drupal::time()->getRequestTime()); + $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME); } } diff --git a/core/modules/views/src/Plugin/views/argument/Date.php b/core/modules/views/src/Plugin/views/argument/Date.php index 8d994e26a7..852e21f04b 100644 --- a/core/modules/views/src/Plugin/views/argument/Date.php +++ b/core/modules/views/src/Plugin/views/argument/Date.php @@ -107,7 +107,7 @@ public function defaultArgumentForm(&$form, FormStateInterface $form_state) { */ public function getDefaultArgument($raw = FALSE) { if (!$raw && $this->options['default_argument_type'] == 'date') { - return date($this->argFormat, \Drupal::time()->getRequestTime()); + return date($this->argFormat, REQUEST_TIME); } elseif (!$raw && in_array($this->options['default_argument_type'], ['node_created', 'node_changed'])) { $node = $this->routeMatch->getParameter('node'); diff --git a/core/modules/views/src/Plugin/views/cache/Time.php b/core/modules/views/src/Plugin/views/cache/Time.php index 2f31a59096..962693d921 100644 --- a/core/modules/views/src/Plugin/views/cache/Time.php +++ b/core/modules/views/src/Plugin/views/cache/Time.php @@ -156,7 +156,7 @@ protected function getLifespan($type) { protected function cacheExpire($type) { $lifespan = $this->getLifespan($type); if ($lifespan) { - $cutoff = \Drupal::time()->getRequestTime() - $lifespan; + $cutoff = REQUEST_TIME - $lifespan; return $cutoff; } else { diff --git a/core/modules/views/src/Plugin/views/field/Date.php b/core/modules/views/src/Plugin/views/field/Date.php index 0d2b45eae2..639bc2329a 100644 --- a/core/modules/views/src/Plugin/views/field/Date.php +++ b/core/modules/views/src/Plugin/views/field/Date.php @@ -85,7 +85,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $date_formats = []; foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) { - $date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(\Drupal::time()->getRequestTime(), $machine_name)]); + $date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]); } $form['date_format'] = [ @@ -145,7 +145,7 @@ public function render(ResultRow $values) { $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL; // Will be positive for a datetime in the past (ago), and negative for a // datetime in the future (hence). - $time_diff = \Drupal::time()->getRequestTime() - $value; + $time_diff = REQUEST_TIME - $value; switch ($format) { case 'raw time ago': return $this->dateFormatter->formatTimeDiffSince($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2]);