PHP Error in updateStatistics() on some pages

Created on 30 August 2017, over 7 years ago
Updated 1 May 2023, over 1 year ago

Problem/Motivation

On some sub-pages such as /node/1/revisions/12/view the result of \Drupal::request()->attributes->get('node') is a string (node id) instead of a node object.
This causes a fatal Error: Call to a member function id() on string in Drupal\statistics_counter\EventSubscriber\StatisticsCounterSubscriber::updateStatistics() (line 41)

Proposed resolution

Check if $node is object before trying to get its id. We can safely assume that if we are on a sub-page where $node is not an object, we should not count node views.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria RumyanaRuseva

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇴Norway gisle Norway

    Patch in comment #9 fails to apply:

    Checking patch src/EventSubscriber/StatisticsCounterSubscriber.php...
    error: while searching for:
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use Symfony\Component\HttpKernel\KernelEvents;
    use Drupal\Core\Database\Database;

    /**
    * Subscribe to KernelEvents::TERMINATE events to recalculate nodes statistics.

    error: patch failed: src/EventSubscriber/StatisticsCounterSubscriber.php:7
    error: src/EventSubscriber/StatisticsCounterSubscriber.php: patch does not apply

    Rerolling for head.

    • mediabounds authored 20d517d8 on 8.x-1.x
      Issue #2905572 by mediabounds, RumyanaRuseva, saranya ashokkumar: Fixed...
  • Status changed to Fixed over 1 year ago
  • 🇳🇴Norway gisle Norway

    Committed to latest snapshot of 8.x-1.x-dev.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024