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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan’s picture

Status: Active » Needs review

The attached patch needs review.

matt@antinomia’s picture

FileSize
492 bytes

I 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.

Status: Needs review » Needs work

Patch failed to apply. More information can be found at http://testing.drupal.org/node/14360. If you need help with creating patches please look at http://drupal.org/patch/create

patrickharris’s picture

Thanks Sutharsan - your patch fixed this issue for me. How come this has remained broken for almost six months?

Sutharsan’s picture

I guess no one uses cron triggers.

Pedro Lozano’s picture

Version: 6.2 » 7.x-dev
Status: Needs work » Reviewed & tested by the community

Fixed the patch against HEAD.

This is unfixed in 6.x and 7.x.

Pedro Lozano’s picture

FileSize
726 bytes

I forgot the patch.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

It 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.

Pedro Lozano’s picture

The 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.

patrickharris’s picture

It's getting close to a year, and cron actions still aren't working in Drupal 6. Sutharsan's small patch works fine for me.

mr.baileys’s picture

Assigned: Unassigned » mr.baileys
Status: Needs work » Needs review
FileSize
4.16 KB

Attached 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!).

Status: Needs review » Needs work

The last submitted patch failed testing.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.87 KB

Fixed an error in the test function.

mr.baileys’s picture

Issue tags: +actions, +cron, +triggers

Added issue tags.

Pedro Lozano’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested manually. The patch works and the test is correct.

sun’s picture

Status: Reviewed & tested by the community » Needs work
+    // Enable the trigger-module, as well as the 'trigger_test' mock module.
+    parent::setUp('trigger', 'trigger_test');

Please remove the comment. The modules are already stated clearly in the next line.

+    // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire.

I do not see a 2nd test.

+name = "Trigger Test"
+description = "Support module for Trigger tests."

AFAIK, the quotes can be removed here.

+version = VERSION

Please remove this from the .info file.

+ * @file
+ *
+ * Mock module to aid in testing trigger.module.

Please remove the blank PHPDoc line here.

+ * Action to be assigned to the trigger "cron run" in order to
+ * be able to test cron run action triggers.

Can we find a one-line summary here and move the rest into the PHPDoc description?

+  // Set a peristent variable so the test can verify that this action
+  // was triggered.

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).

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.7 KB

Thanks 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.

Status: Needs review » Needs work

The last submitted patch failed testing.

andypost’s picture

Status: Needs work » Needs review

Retest and subscribe, as for me applies cleanly

WorldFallz’s picture

FileSize
2.22 KB

rerolled against current head, applies cleanly. Giving testbot another shot

WorldFallz’s picture

tested 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.

Status: Needs review » Needs work

The last submitted patch failed testing.

WorldFallz’s picture

Status: Needs work » Needs review

glancing at the test results, it looks like it's probably failing because of #408434: Actions.inc: fatal error after DBTNG conversion.

WorldFallz’s picture

Status: Needs review » Needs work

not sure how the status got changed, but there's no point in retesting.

Anonymous’s picture

subscribe

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
3.69 KB

Looks 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.

andypost’s picture

Issue tags: +Needs backport to D6
FileSize
3.93 KB

Marked 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

andypost’s picture

So where to put trigger_test.module ?
Any thoughts...

webchick’s picture

modules/trigger/tests/trigger_test.module is the standard we're trying to adhere to, even though currently things are a total mess.

andypost’s picture

FileSize
3.9 KB

So here patch to place tests into trigger folder

Status: Needs review » Needs work

The last submitted patch failed testing.

webchick’s picture

Status: Needs work » Needs review
andypost’s picture

Tests passed, so maybe someone review this to start ball

webchick’s picture

Status: Needs review » Needs work

Just some minor things...

+class TriggerCronTestCase extends DrupalWebTestCase {

Needs PHPDoc.

+    // Assign an action to a trigger, then pull the trigger, and make sure the actions fire.
+    $test_user = $this->drupalCreateUser(array('administer actions'));
+    $this->drupalLogin($test_user);

That comment doesn't seem to at all match the code below it. Maybe it's more PHPDoc?

+    // Force a cron run

Needs a period.

+    $action_run = variable_get('trigger_test_system_cron_action', FALSE);
+    $this->assertTrue($action_run, t('Check that the cron run triggered the test action.'));

Could we get a one-liner comment here?

andypost’s picture

FileSize
3.99 KB

Comments fixed, waiting for testing bot...

Please review comments, English is not my native

andypost’s picture

Status: Needs work » Needs review

Just a status

webchick’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs review » Patch (to be ported)

Awesome. Committed to HEAD!

Needs back-port to 6.x.

andypost’s picture

Issue tags: +Quick fix
FileSize
760 bytes

Here the patch for d6, quickFix

andypost’s picture

Status: Patch (to be ported) » Needs review

forget to change status

webchick’s picture

Status: Needs review » Reviewed & tested by the community

Since this is the same fix that was committed to HEAD, marking RTBC.

tobiasb’s picture

getinfo isn't static

just add "public static" to function getInfo()

  public static 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).

andypost’s picture

FileSize
708 bytes

patch for #41

andypost’s picture

Version: 6.x-dev » 7.x-dev
webchick’s picture

Version: 7.x-dev » 6.x-dev

Bah! Thanks, Razorraser! Committed follow-up.

Back to 6.x for #38.

mr.baileys’s picture

Assigned: mr.baileys » Unassigned

removing my name as andypost has this under control :)

andypost’s picture

And addition< that already commited to d7 #383220: Cron trigger needs an action

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed to Drupal 6!

Status: Fixed » Closed (fixed)
Issue tags: -Needs backport to D6, -Quick fix, -actions, -cron, -triggers

Automatically closed -- issue fixed for 2 weeks with no activity.