Passing function arguments to translation call

voxpelli - August 31, 2008 - 15:25
Project:Job queue
Version:6.x-3.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

At line 147 in job_queue.module the arguments that was added to a job is passed as a value to translation. This raised warnings in our code and can't really be the intended functionality?

#1

drumm - September 4, 2008 - 16:59

Can you paste the specific warnings? How did you call job_queue_add()?

This is intended since translation needs to be done on output. Arguments are useful to have, and re-using the function argument array seemed workable without adding another argument to job_queue_add().

#2

drumm - September 4, 2008 - 17:00
Status:active» postponed (maintainer needs more info)

#3

voxpelli - September 12, 2008 - 11:20
Status:postponed (maintainer needs more info)» active

The warning message was:

warning: preg_match() expects parameter 2 to be string, array given in E:\xampp\workspace\dinby\includes\bootstrap.inc on line 723.

The call was:

job_queue_add('func', t('Funcname'), array($data1, $data2), 'foobar', FALSE);

t() expects all values in an array to be string but not all values passed to job_queue_add needs to be strings so either non-string values needs to be filtered or translateable values will need to be passed in another fashion.

#4

voxpelli - November 27, 2008 - 07:35
Priority:minor» normal

Marked http://drupal.org/node/327949 as a duplicate of this. Since other are experiencing this error as well I'm raising the priority.

#5

fgm - February 27, 2009 - 17:11

#373882: Errors sending mails. is also basically a duplicate.

The problem is that the unserialize call on that line can return non-strings, causing this error.

#6

voidberg - March 23, 2009 - 10:55

The cause for this is that if you send parameters such as arrays or jobs to your job they will be passed as parameters to t() which expects only strings. Hence the error.

The proposed solution in #373882 is not good because it limits the translation of the jobs' description just to simple strings, without placeholders. So either:
1) Do something like watchdog does and add another array parameter for the placeholder values
2) Leave the translation of the job out of the module

The second is probably the safest in terms of backward compatibility although you can end up with a job queue full of mixed languages.

#7

voidberg - March 23, 2009 - 11:21

Also to note that there are multiple places where this can happen:
- job_queue_dequeue
- job_queue_list

Also, in job_queue_dequeue, there's a mismatch in terms of behaviour: if the function exists then it's called and an entry in watchdog gets created which attempts to translate the job description using the arguments supplied. However, if the function does not exist then the watchdog entry doesn't get a translated version of the job description.

For my application I chose the second solution taking care of translations outside of the module (i.e. passing an already translated job description). I am attaching a patch for it against the stable version of the module.

AttachmentSize
job_queue.patch 1.05 KB

#8

florent.jousseaume - April 30, 2009 - 15:41

Same problem, same patch

#9

derhasi - May 15, 2009 - 08:53
Version:6.x-3.0» 6.x-3.x-dev
Status:active» needs review

I patched the module with keeping the translation functionality by using a clean-up function _job_queue_t_args. Patch attached

AttachmentSize
job_queue-302305.patch 1.98 KB

#10

hass - June 28, 2009 - 18:21

I also have the issue that I have a string with a number inside.

The description in database is Scan node 87 having 501 links not yet added to linkchecker_links table. and if it's shown on "admin/reports/job_queue" it shows Scan node 87 having 5<em>87</em>1 links not yet added to linkchecker_links table.. Job_queue replaces my argument 0 => 87 (node id) in the string and make every "0" a "87".

#11

drumm - September 13, 2009 - 02:00
Status:needs review» duplicate

A clever fix from #373882: Errors sending mails. was committed.

 
 

Drupal is a registered trademark of Dries Buytaert.