Replace usages of the deprecated REQUEST_TIME for Core modules

Comments

Satyanarayan Reddy created an issue. See original summary.

satyanarayan reddy’s picture

Status: Active » Needs review
StatusFileSize
new23.41 KB

Replace usages of the deprecated REQUEST_TIME for modules

cilefen’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

berdir’s picture

Component: other » base system
Status: Needs review » Needs work
  1. +++ b/core/modules/aggregator/src/Controller/AggregatorController.php
    @@ -116,16 +116,17 @@ public function adminOverview() {
           $row = [];
           $row[] = $feed->toLink()->toString();
    +      $request_time = \Drupal::time()->getRequestTime();
           $row[] = $this->formatPlural($entity_type_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
    
    +++ b/core/modules/views/views.api.php
    @@ -659,9 +659,10 @@ function hook_field_views_data_views_data_alter(array &$data, \Drupal\field\Fiel
         '***LANGUAGE_language_content***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(),
         PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => \Drupal::languageManager()->getDefaultLanguage()->getId(),
    

    this one could be injected

  2. +++ b/core/modules/user/src/Controller/UserController.php
    @@ -208,7 +208,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 = REQUEST_TIME;
    +    $current = \Drupal::time()->getRequestTime();
    

    Those in this file too.

  3. +++ b/core/modules/user/src/EventSubscriber/UserRequestSubscriber.php
    @@ -55,11 +55,12 @@ public function __construct(AccountInterface $account, EntityTypeManagerInterfac
        */
       public function onKernelTerminate(PostResponseEvent $event) {
    -    if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
    +    $request_time = \Drupal::time()->getRequestTime();
    +    if ($this->account->isAuthenticated() && $request_time - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
           // Do that no more than once per 180 seconds.
    

    Same.

  4. +++ 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, REQUEST_TIME);
    +      return date($this->argFormat, \Drupal::time()->getRequestTime());
    

    Same.

  5. +++ b/core/modules/views/src/ViewExecutable.php
    @@ -1675,7 +1675,7 @@ public function preExecute($args = []) {
         views_set_current_view($this);
         $display_id = $this->current_display;
    -
    +    $request_time = \Drupal::time()->getRequestTime();
         // Prepare the view with the information we have, but only if we were
         // passed arguments, as they may have been set previously.
         if ($args) {
    

    This in theory too, but it's tricky, through a factory service and there are 17 existing \Drupal:: calls, so I don't think we need to push that here.

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new32.5 KB

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kristen pol’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

megachriz’s picture

This looks like a duplicate of #3112298: Replace REQUEST_TIME in classes with direct container access, although that other issue only addresses classes and this one handles the following other files:

  • /core/core.api.php (no longer an issue)
  • /core/modules/file/file.module
  • /core/modules/image/image.admin.inc
  • /core/modules/system/system.install
  • /core/modules/update/update.fetch.inc
  • /core/modules/user/user.module
  • /core/modules/views/views.api.php
  • /core/modules/views/views.theme.inc
  • /core/modules/views/views.views_execution.inc
  • /core/rebuild.php (not sure if this is still an issue)

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new143 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Status: Needs work » Closed (outdated)
Related issues: +#2902895: [meta][no patch] Replace uses of REQUEST_TIME and time() with time service