When using hook_cronapi() we can use 'callback arguments'. But these arguments are not making it into the right function arguments.

Test with following code:

function my_module_cronapi() {
  $items = array();
  $items['my_module_action'] = array(
    'callback' => 'my_module_action',
    'callback arguments' => array('first',  'second'),
  );
  return $items;
}

function my_module_action($first, $second) {
  dpm($first, 'First argument');
  dpm($second, 'Second argument');
}

Instead of getting $first = 'first' and $second = 'second', I get:
$first = array('first', 'second')
$second = [empty]

In the file ultimate_cron.job.inc on line 328, there is the next line:

$arguments = array($this->hook['callback arguments']);

By removing the array() part and use just '$this->hook['callback arguments']' the problem for my specific case gets fixed, but it causes problems with other existing (ultimate_cron) code, where the arguments are probably taken from the first argument array which will break after the change above.

I'm not sure if this is a bug in the module, or if I just should take the arguments from the first argument array. But the last and current way feels kind of wrong...

Comments

ReneW created an issue.

joekrukosky’s picture

I realize it's been a while for this, but I just ran across this issue as well. I think some clarification might help others.

In version 2, there are 3 "callback" attributes:

'callback' => 'mymod_callback_function',
'callback arguments' => array($arg1, $arg2),
'pass job argument' => TRUE,

The 'pass job argument' defaults to true so most times the callback would be implemented as such:

function mymod_callback_function($job, $args) {
// $job is the full ultimate cron job class object
$arg1 = $args[0];
$arg2 = $args[1];
}

So it stems that if you set 'pass job argument' to false then you still have to treat the arguments the same:

function mymod_callback_function($args) {
$arg1 = $args[0];
$arg2 = $args[1];
}

This is a bit confusing because hooks typically implement the callback arguments as ReneW explains above, e.g. hook_menu's "page arguments".