Working on the 6.x-1.x-dev version on Simplenews I came across the following:
An action defined to run on cron is not executed by the cron trigger ("Send single simplenews newsletter" see code below).
The defined action is listed on the cron triggers page (admin/build/trigger/cron).
When executing cron from the browser url the action is not executed.
function simplenews_action_info() {
return array(
'simplenews_send_newsletter_action' => array(
'description' => t('Send single simplenews newsletter'),
'type' => 'simplenews',
'configurable' => TRUE,
'hooks' => array(
'cron' => array('run'),
'user' => array('insert'),
),
),
...
(code will shortly be available in the latest Simplenews 6.x-1.x-dev version: http://drupal.org/node/234976)
System module defines a 'cron' hook with 'run' operation:
function system_hook_info() {
return array(
'system' => array(
'cron' => array(
'run' => array(
'runs when' => t('When cron runs'),
),
),
),
);
}
however trigger_cron() calls _trigger_get_hook_aids('cron') with an empty operation.
function trigger_cron() {
$aids = _trigger_get_hook_aids('cron');
$context = array(
'hook' => 'cron',
'op' => '',
);
...
_trigger_get_hook_aids() now queries {trigger_assignments} for a matching hook/operation pair (cron/ but finds none, since it is defined as cron/run
The attached patch uses operation 'run' to trigger_cron(). It works but I can not see it this is the right approach.
Alternatively defining the cron hook with empty op operation in simplenews_action_info() does not help because it is not recognized as a valid definition.
I have not found any implementation of a cron trigger in D6 core or contrib modules to use as a working example.
Comment | File | Size | Author |
---|---|---|---|
#42 | trigger-follow.patch | 708 bytes | andypost |
#38 | cron-trigger-D6.patch | 760 bytes | andypost |
#35 | cron-trigger3.patch | 3.99 KB | andypost |
#30 | cron-trigger2.patch | 3.9 KB | andypost |
#27 | cron-trigger.patch | 3.93 KB | andypost |
Comments
Comment #1
Sutharsan CreditAttribution: Sutharsan commentedThe attached patch needs review.
Comment #2
matt@antinomia CreditAttribution: matt@antinomia commentedI haven't reviewed this patch for 6.x, but in 5.x-2.5 it also appears to be broken. The attached patch fixes the issue in the same fashion as the patch in #1.
Comment #4
patrickharris CreditAttribution: patrickharris commentedThanks Sutharsan - your patch fixed this issue for me. How come this has remained broken for almost six months?
Comment #5
Sutharsan CreditAttribution: Sutharsan commentedI guess no one uses cron triggers.
Comment #6
Pedro Lozano CreditAttribution: Pedro Lozano commentedFixed the patch against HEAD.
This is unfixed in 6.x and 7.x.
Comment #7
Pedro Lozano CreditAttribution: Pedro Lozano commentedI forgot the patch.
Comment #8
webchickIt would be good to make sure we have a test case to verify that this trigger continues working as intended. There is a base to build from in modules/trigger/trigger.test that has tests for content actions currently.
Comment #9
Pedro Lozano CreditAttribution: Pedro Lozano commentedThe problem here is that (on the crontrary to content actions) there is no actions in Drupal core that are assignable to the cron trigger, so the test would be a little more complicated, maybe creating a temporary action.
Comment #10
patrickharris CreditAttribution: patrickharris commentedIt's getting close to a year, and cron actions still aren't working in Drupal 6. Sutharsan's small patch works fine for me.
Comment #11
mr.baileysAttached is a patch containing the fix from #7 (thanks Pedro Lozano) as well as a first attempt at a test case for this particular scenario.
The test adds a mock module, which I think is required because there are no actions availabe to be triggered by a cron run. The mock module adds an action called
Cron test action
. The test then tries to assign "Cron test action" to be run on the cron run trigger, and verifies that it actually did run (or not, in which case the test should fail).First attempt at writing tests, so all input welcome (that includes you, testbot!).
Comment #13
mr.baileysFixed an error in the test function.
Comment #14
mr.baileysAdded issue tags.
Comment #15
Pedro Lozano CreditAttribution: Pedro Lozano commentedReviewed and tested manually. The patch works and the test is correct.
Comment #16
sunPlease remove the comment. The modules are already stated clearly in the next line.
I do not see a 2nd test.
AFAIK, the quotes can be removed here.
Please remove this from the .info file.
Please remove the blank PHPDoc line here.
Can we find a one-line summary here and move the rest into the PHPDoc description?
1) typo in "persistent".
2) Can we remove the obvious parts in that comment and just stick to the important things? How + why would be interesting (instead).
Comment #17
mr.baileysThanks for reviewing this patch: I incorporated all the changes you suggested and re-rolled the patch. I also noticed I'd neglected to add
// $Id$
to the trigger_test.module file, which has also been fixed now.Comment #19
andypostRetest and subscribe, as for me applies cleanly
Comment #20
WorldFallz CreditAttribution: WorldFallz commentedrerolled against current head, applies cleanly. Giving testbot another shot
Comment #21
WorldFallz CreditAttribution: WorldFallz commentedtested along with the action added in #383220: Cron trigger needs an action -- also required #408434: Actions.inc: fatal error after DBTNG conversion to get past the actions error, works as intended.
Comment #23
WorldFallz CreditAttribution: WorldFallz commentedglancing at the test results, it looks like it's probably failing because of #408434: Actions.inc: fatal error after DBTNG conversion.
Comment #24
WorldFallz CreditAttribution: WorldFallz commentednot sure how the status got changed, but there's no point in retesting.
Comment #25
Anonymous (not verified) CreditAttribution: Anonymous commentedsubscribe
Comment #26
mr.baileysLooks like somewhere along the line the mock module that was required for the tests got removed from the patch. Re-added it to the re-rolled patch from #20, all tests now pass, back to needs review.
Comment #27
andypostMarked as duplicate #346262: Trigger module will not run actions assigned to cron runs
new patch against current HEAD but trigger_test.module placed to
modules/simpletest/tests
For 6.x proposed #383220: Cron trigger needs an action
Comment #28
andypostSo where to put trigger_test.module ?
Any thoughts...
Comment #29
webchickmodules/trigger/tests/trigger_test.module is the standard we're trying to adhere to, even though currently things are a total mess.
Comment #30
andypostSo here patch to place tests into trigger folder
Comment #32
webchickComment #33
andypostTests passed, so maybe someone review this to start ball
Comment #34
webchickJust some minor things...
Needs PHPDoc.
That comment doesn't seem to at all match the code below it. Maybe it's more PHPDoc?
Needs a period.
Could we get a one-liner comment here?
Comment #35
andypostComments fixed, waiting for testing bot...
Please review comments, English is not my native
Comment #36
andypostJust a status
Comment #37
webchickAwesome. Committed to HEAD!
Needs back-port to 6.x.
Comment #38
andypostHere the patch for d6, quickFix
Comment #39
andypostforget to change status
Comment #40
webchickSince this is the same fix that was committed to HEAD, marking RTBC.
Comment #41
tobiasbgetinfo isn't static
just add "public static" to function getInfo()
error msg
Strict warning: Non-static method TriggerCronTestCase::getInfo() cannot be called statically in simpletest_categorize_tests() (line 264 of ...\drupal7\modules\simpletest\simpletest.module).
Comment #42
andypostpatch for #41
Comment #43
andypostComment #44
webchickBah! Thanks, Razorraser! Committed follow-up.
Back to 6.x for #38.
Comment #45
mr.baileysremoving my name as andypost has this under control :)
Comment #46
andypostAnd addition< that already commited to d7 #383220: Cron trigger needs an action
Comment #47
Gábor HojtsyThanks, committed to Drupal 6!