Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In my previous project, I found that when there's a drupal_set_message('something') in hook_cron, it will display messages to the user who actually triggered the cron by javascript. I know usually it's not a good practice to write drupal_set_message in hook_cron but it does existed in core modules, for example aggregator_cron. It calls aggregator_refresh which contains drupal_set_message.
Here below is the patch I created to fix this issue:
Comment | File | Size | Author |
---|---|---|---|
#3 | poormanscron.module.patch | 731 bytes | andyhu |
#2 | poormanscron.module.patch | 561 bytes | andyhu |
#1 | poormanscron.module.patch | 418 bytes | andyhu |
poormanscron.module.patch | 765 bytes | andyhu | |
Comments
Comment #1
andyhu CreditAttribution: andyhu commentedChanged the patch a bit, it's better but still not ideal.
Comment #2
andyhu CreditAttribution: andyhu commentedChanged the patch again, now it should work!
I used session_write_close before cron runs so that any changes for $_SESSION will not be saved during running cron.
Here's the code to prove the concept, we may write it in a page call back or execute it in devel php:
Comment #3
andyhu CreditAttribution: andyhu commentedHere is another patch which fix the issue I found together with the issue here http://drupal.org/node/793590
Comment #4
Dave ReidThe latest 6.x-2.x code changes the session to the anonymous user and uses the same exact thing that the Drupal 7 cron feature does.