Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Problem/Motivation
All hooks have to invoke via the 'module_handler' service. If it isn't call via the call_user_func function.
I ran into a problem when hook_cron invisible for the Ultimate Cron.
Steps to reproduce
- Install the Hux module.
- Add hook_cron via attribute (like write in README of the Hux module). Make sure that this issue was merged or just apply patch.
- Click Discover Job button
- Try to run this cron.
Proposed resolution
We have to check if it hook and invoke via the 'module_handler' service.
Issue fork ultimate_cron-3320908
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 #3
miroslav-leeComment #4
miroslav-leeComment #5
berdirRelated issues: #3274089: hook_event_dispatcher compatability and #3414863: Support CronSubscribers (and the related core issue).
Interesting solution but it's trying to be a little bit too generic I think. Whether or not something is/has certain hook is just a naming convention, with that logic, any module-prefixed callback is going to be recognized as a hook.
Instead, we should do this only if it the cron hook. Meaning, isCallbackHook() should just check $this->getHookName() === 'cron', at this point we can of need to expect that it exists.
Hopefully, the long-term solution is the core issue that I created to make cron tasks/jobs their own thing that can be discovered and not hooks. Feedback/reviews there would definitely be welcome.
Comment #6
berdirDrupal 11.1 now has #Hook, implemented something quite similar to this in #3489356: Support #Hook cron implementations including a new special syntax instead of assuming based on the function name, that would have worked too I guess, forgot about this issue actually.