Problem/Motivation
I found an annoying bug in statistics module - it crashes the site page rendering if you somehow have nid for non-existing node in the node_counter table. I don't know how it happened and I could not make it happen at will, but reference to a deleted node has not been removed from the table. That causes use of NULL instead if the node object and the site page rendering breaks - on every page that has StatisticsPopularBlock. The fix is simple - just 2 lines to modify in the function StatisticsPopularBlock::nodeTitleList(). I can supply a patch for the fix, it is pretty obvious on lines 195 and 196 in StatisticsPopularBlock.php file.
Steps to reproduce
Proposed resolution
TBD
Remaining tasks
Update patch
Add a test
Review
Commit
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 2987952-25.patch | 1.24 KB | shubham chandra |
| #24 | interdiff_22_24.txt | 1.07 KB | rassoni |
| #24 | 2987952-24.patch | 1.24 KB | rassoni |
| #22 | reroll_diff_15-22.txt | 1.22 KB | pooja saraah |
| #22 | 2987952-22.patch | 1010 bytes | pooja saraah |
Issue fork drupal-2987952
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
calmforce commentedI have created a patch. The change was even easier than I thought: only one line in StatisticsPopularBlock.php needs to be changed to ignore those node IDs in the node_counter table that do not have nodes anymore.
Comment #3
calmforce commentedI have attached exactly the same patch (only changed the patch file name) to this comment, so the patch file name matches the comment number.
Comment #4
timmillwoodNice find, and yes, super simple fix.
Comment #5
catchI think we should not load the nodes here, since this never gets used.
Instead maybe check the return value here?
Comment #6
timmillwood@catch The initial node load is used as the param in
getTranslationFromContext().Comment #7
tstoecklerWell, instead of doing the workaround of iterating over the keys we could just do
foreach ($nodes as $node), though, right?Comment #8
calmforce commented@catch The nodes need to be loaded because getTranslationFromContext() requires an entity as a first argument.
@tstoeckler yes, you are right - the iteration over
$nodeswould do the fix as well, I just tested. I did iteration over the keys because that requires changing the only one line instead of two. However, iteration over$nodesmay provide better code readability. If so, I can suggest another patch - with iteration over$nodesarray. The new patch is attached.Comment #9
calmforce commentedComment #10
borisson_The change in #8 is great, thanks for the suggestion @tstoeckler and the implementation @calmforce! This was already set to RTBC by @timmillwood before without it having tests, so setting this back to rtbc based on that.
I also think that writing a test for this would be really hard to get right.
Comment #11
catchI think the reason this was originally written looping over the $nids was to avoid overwriting $node, which this now does. I think we should probably rename the variable to $translation or something?
Comment #12
timmillwood@catch - I believe you're wrong,
$nodehas always been the translation.Comment #13
catchThat's not the point I was making, but got my selection in dreditor wrong so it wasn't clear maybe:
$node = $this->entityRepository->getTranslationFromContext($node);There's no need to reassign $node here, we should use a different variable name, this wasn't a problem with the previous code.
Or in other words, $node was always the translation, now it starts as not being the translation, then becomes the translation.
Comment #14
calmforce commented@catch your demands sound arbitrary and capricious. You do not explain why we "should" use a different variable name. The code works perfectly well (I tested it extensively) in its final form, it was reviewed and approved by the module maintainer, @timmillwood. I think we should finish this debate.
Comment #15
timmillwood@calmforce - @catch's view always outweighs the module maintainer. From knowing @catch for nearly 10 years his thoughts and ideas always end up being for the better.
So here's a patch adding the
$translationvariable.Comment #16
catchSo the patch in #8 is overwriting the value of $node in the foreach. Because the objects are by reference in PHP, this means that after that foreach loop, all of the array values would be the translations. Would need to double check, but it might even affect what gets loaded by Node::load() and Node::loadMultiple() later in the request, because that also returns by ref.
By assigning to a different variable name instead of overwriting as in #15, we're not changing the contents of the array in the foreach loop or anywhere else - i.e. $node remains exactly the same object.
An old issue that covered some of this is #154859: Document that cached entity objects are not necessarily cloned any more.
Comment #21
quietone commentedThis looks like an edge case and the code has not changed. It is still looping on the passed in value $nids.
This needs a reroll and a test.
Comment #22
pooja saraah commentedAttached Reroll patch against 10.0.x
Comment #23
immaculatexavier commented#22 patch failed to apply, Need reroll.
Comment #24
rassoni commentedAttached Reroll patch against 10.0.x with fixing failed testing patch issues.
Also take care #16 node suggestion part
Comment #25
shubham chandra commentedApplied Patch against #24 in Drupal 10.x.1.
Comment #27
quietone commentedStatistics is approved for removal. See #3266457: [Policy] Deprecate Statistics module in D10 and move to contrib in D11
This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
It will be moved to a contributed Statistics project once the project is created and the Drupal 11 branch is open.
Comment #29
quietone commented