[5.4] Fix null user check in ActionLogPlugin to prevent PHP warnings#46599
Conversation
@Shauryan0207 I'd prefer to have instructions for a real test, not just code review. Providing reproducible test instructions would also show that you have tested the changes from your PR yourself before submitting it, which is a mandatory requirement for contributing here. Could you provide instructions? Thanks in advance. |
|
@Shauryan0207 - I am trying to test your PR and I read the Testing Instructions of "PHP warnings when ActionLog runs without authenticated user" but I must admit not understanding what you meant as I can't think of anything that triggers an ActionLog without a user being authenticated (but that could just be ME not thinking through all of the cases)... I could imagine maybe this happening if a Session timeout happened during an action, but that's not so easy to trigger. Looking forward to specific use case that I can test for you. |
|
Hey @richard67 php test_actionlog_null.php Expected output: |
|
Hey @exlemor ,Thanks for reviewing this while it’s rare, this can happen during things like command-line scripts, scheduled tasks, system maintenance, or guest API requests, where actions are logged even though no user is logged in. |
administrator/components/com_actionlogs/src/Plugin/ActionLogPlugin.php
Outdated
Show resolved
Hide resolved
a7b1fd7 to
998963d
Compare
|
I have tested this item ✅ successfully on 998963d This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46599. |
|
@Shauryan0207 Could you adjust the testing instructions in the description (initial post) of this PR to the latest code changes? Thanks in advance. |
@richard67 Done ! Thanks |
|
@Shauryan0207 I'm probably doing something incorrectly but I'm not matching the BEFORE condition of a PHP error. I created the php file: test_actionlog_null.php in the root of the sub-folder where Joomla 5.4 is installed, /_j540/ What did I screw up? ;( |
|
I looked at this PR and I am not happy with it. The quoted test would just show the desired behaviour. It does not test Joomla. Various CLI commands such as This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46599. |
|
I have tested this item ✅ successfully on 998963d
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46599. |
@ceford The code review shows that the object |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46599. |
|
@muhme Haven't looked at the details, but some questions raise:
|
@joomdonation These are valid questions, but I cannot answer them. Perhaps you or someone else can answer them? thx |
|
The fix is valid despite the questions. About the questions. The CLI app does not have an User. |
|
Thank you @Fedik for stepping in and answering the questions. |
|
Thanks @Shauryan0207 for this PR, and thanks @Fedik and @muhme for testing, and again @Fedik for advice and support. |
Summary of Changes
Added a check for the $user object in ActionLogPlugin to prevent PHP warnings when getIdentity() returns null.
Testing Instructions
Since reproducing a scenario where getIdentity() returns null via the UI is difficult please use the following script to verify the fix:
Create a test file test_actionlog_null.php
php test_actionlog_null.php
Expected output:
TEST 1 shows a PHP error when accessing properties on null
TEST 2 shows no warnings and handles null safely
Actual result BEFORE applying this Pull Request
PHP warnings when ActionLog runs without authenticated user.
Expected result AFTER applying this Pull Request
No PHP warnings; gracefully handles null user.
Link to documentations