Using messaging-6.x-2.4 and token-6.x-1.17, I am getting these:

warning: preg_match_all() expects parameter 2 to be string, array given in …/sites/all/modules/contrib/token/token.module on line 701.

This is related to the fact that messaging uses token_replace_multiple() in a way that was never supported (see #1307890: token_replace() performance when there are no tokens).

CommentFileSizeAuthor
#3 messaging-1329024-3.patch862 bytesBoobaa
#1 messaging-1329024-1.patch840 bytesBoobaa
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Boobaa’s picture

Status: Active » Needs review
FileSize
840 bytes

Attached is a patch to solve this.

Dave Reid’s picture

+++ messaging.module	2011-11-02 08:32:26.896992847 +0100
@@ -896,9 +896,21 @@ function messaging_text_replace($text, $
+    if (is_array($text)) {
+      foreach ($text as &$line) {
+        $line = token_logic_replace_multiple($line, $objects);

Note that this foreach by reference is not supported on PHP 4. Is PHP 5 a dependency for Messaging? It doesn't look like it in the .info file.

Boobaa’s picture

FileSize
862 bytes

Patch updated to avoid foreach by reference.

trilobite540’s picture

Thanks - that patch sorted out my problems...

vectoroc’s picture

Dane Powell’s picture

Dane Powell’s picture

Status: Needs review » Fixed

I've committed a much cleaner (IMHO) version of #3 to 6.x-2.x and 6.x-4.x:
http://drupal.org/commitlog/commit/5046/4cb5f834e1b36b3e3df1f986fccf8826...
http://drupal.org/commitlog/commit/5046/e6012b401e8edbcd4e2457cc437ffaa6...

Please try the development releases that roll tonight and make sure that these work.

oriol_e9g’s picture

I can confirm that the problem is solved in dev.

Steel Rat’s picture

This is marked as "fixed", but it's only fixed in the dev version. Shouldn't this remain open until the fix has been made in production? I don't feel comfortable putting a dev module on my production sites.

Thanks.

Dane Powell’s picture

'Fixed' is the appropriate status. A new release might be warranted, but I think that would be webflo's call... he's the only maintainer who has access to both Notifications and Messaging AFAIK.

You can always apply the appropriate patch to your otherwise stable release. Just follow the links I posted, click on the commit number to view the changes, and click 'patch'. For instance, here's the patch for 6.x-4.x: http://drupalcode.org/project/messaging.git/patch/e6012b4

Steel Rat’s picture

Thanks Dane,

I don't know how to apply patches, tried searching for a how-to, but never found one. If you have a link to such a thing I'd be grateful.

Dane Powell’s picture

@Steel Rat: it depends on your working environment. If you have Git, just go to the root directory of the messaging module and run git apply -v [patchname.patch].

If you are using Drush Make files to build your site (which I HIGHLY recommend), you can just include lines like the following:

projects[messaging][version] = 2.4
projects[messaging][patch][] = http://drupalcode.org/project/messaging.git/patch/e6012b4
Vayira’s picture

I don't have git or drush but I do have this problem.

Is 6.x-2.x-dev 2011-Nov-12 safe to use without any other consequences?

Dane Powell’s picture

@Vayira - I can't really say, I don't use 6.x-2.x. Looking through the commit history for the 2.x branch might help you determine if it's safe. I would also recommend learning how to apply patches - if you Google it you'll find plenty of info. Git/Drush aren't necessarily required, although I'd recommend checking them out as well.

oriol_e9g’s picture

I'm using 2.x versión in a production drupal with 23 sites and it's working fine with no related issues from my users (more than 2000)

Ela’s picture

I have only had the issue on Forum, the patch worked. Thank you.

Vayira’s picture

I tried running "patch" which I already had installed in my ubuntu but it didn't like that file. In the end I just patched it by hand removed the two wrong lines & pasted in the others. It seemed less work than installing programs, learning how to use them etc etc.

I didn't get any error messages but messages were blank so I installed the dev version & that seems to work for me.

Steel Rat’s picture

Looks like the patch is fairly small, so I'll do it by hand as Vayira did. I do appreciate the help, though.

Steel Rat’s picture

Ok, I'm confused (big surprise there!).

The patch here: http://drupalcode.org/project/messaging.git/patch/e6012b4 appears to be for messaging_template.module, not messaging.module. The lines to delete don't exist in the version I've got, 6.x-2.4

What am I missing?

Steel Rat’s picture

Never mind. I eventually found the 6.x-2.4 patch by clicking through the commit link higher up the thread. I've manually made the patch and all seems well in the universe.

Sorry for my confusion and clogging up the issue!

Thanks !!!

Jeff

clemens.tolboom’s picture

Version: 6.x-2.4 » 6.x-2.x-dev
Status: Fixed » Needs work

I changed version as the fix is not done in 6.x-2.4 which confuses people.

(I'd like to make it critical as our open atrium is now behaving badly)

The commit from http://drupalcode.org/project/messaging.git/commitdiff/e6012b401e8edbcd4... is bad code

$text[$part] = call_user_func_array($function, $param_arr);

and not inline with the patch from #3

I suppose this is to obfuscate reviewers :p

But seriously it is neither clear nor useful. Performance wise it's bad too.

+++ messaging.module	2011-11-04 10:32:32.912570145 +0100
@@ -896,9 +896,21 @@ function messaging_text_replace($text, $
+        $text[$no] = token_logic_replace_multiple($line, $objects);

This code is much better.

So 'needs work'.

izmeez’s picture

Can anyone explain what is the current status of this?
The 6.x-2.x-dev release fixes the watchdog messages for us.
But comment #21 raises questions.

eric_sea’s picture

I am running OpenAtrium 1.2 with everything up to date. Messaging.module is 6.x-2.4.

I am getting the following error when posting blog with notification:

user notice: The messaging_text_replace() function called token replacement with an array rather than a string for $text in [..]/public_html/profiles/openatrium/modules/contrib/token/token.module on line 263.

I tried applying #3 above -- the patch: http://drupal.org/files/messaging-1329024-3.patch.
I also tried #7 above --http://drupalcode.org/project/messaging.git/blobdiff/d7b0e675e8e47dd1a8b...

No luck with either one.
Haven't tried message.template changes mentioned above as the discussion seems to indicate that the problem must be in messaging.modules.

Still getting same notice x3 for each blog post with notifications.

Other suggestions?

dblais’s picture

eric_sea
It's only a user notice. I think token module is only giving you a warning but everything is ok... Just hide theses warning.

clemens.tolboom’s picture

Status: Needs work » Needs review

@dblais this is a real API change done by token module.

See #1327960: Invalid use of token_replace API - causes preg_match_all errors in token module #27 http://drupal.org/node/1327960#comment-5220700 where Dave Reid explains his err.

See also http://drupal.org/project/issues/token?text=called+token+replacement+wit...

So messaging needs to fix this.

Set to needs review as a developer needs to check why patch versus commit do not match as commented in #21 :)

IreneKraus’s picture

I'm sorry, but I'm pretty confused by all of the different posts, etc. as I have no clue as to how to apply patches. Not that I would want to do this on a production site anyway, but my users are asking for some kind of fix to get rid of all of the MySQL errors being triggered on the site whenever content is generated (because of notices being sent). Is the current dev release the one we're supposed to be using to get rid of this problem?

s.Daniel’s picture

@Irene Kraus
For information about patches in general (outdated but I think still relevant) see: https://drupal.org/node/60108

Without checking: You should be able to hide the message here: /admin/settings/error-reporting which I think is generally a good idea for production sites. However I am not sure weather this applies to this message.

Kiki1597’s picture

What is the current status of this issue?

I am running Open Atrium 1.4 (http://openatrium.com/node/49)

I am using:
Token 6.x-1.18
Messaging 6.x-2.4
Mailfix 6.x-1.6

I am getting the same error when trying to comment on a project, clicking to send to multiple people... I get the error:
user notice: The messaging_text_replace() function called token replacement with an array rather than a string for $text in /home/commgroup/html/profiles/openatrium/modules/contrib/token/token.module on line 263.

I'm new to Open Atrium and Drupal, and would appreciate any help! So far, no emails have come through - so I'm assuming if I hide the error messages from the screen, it's not going to do anything except make it seem error-free, when indeed it still has errors and doesn't send the emails.

Thanks!

paskainos’s picture

@Steel Rat, @Vayira [et al]: no offense, but if you're working with Drupal at this (dev vs. user, etc.) level, you'd do well to familiarize yourself with the ins and outs of patching (programatically, not manually). It'll save you lots of time, frustration - and hair... Here's a link to the d.o reference page on applying patches.

@clemens.tolboom: your comments (herein), while helpful (and anecdotal?) are nonetheless somewhat cryptic and ethereal (perhaps inside jokes the rest of us aren't privy to?).

@eric_sea: what version of Token is your OA install using? Also, by, "...I also tried #7..." do you mean you applied the 6.x-2.x patch in #7 to your 6.x-2.4 version? If so, did you try simply replacing the 6.x-2.4 version with the 6.x-2.x (dev) version? I'm sure this goes without saying (Murphy says) but since you're running OA I'll ask; do you have more than one instance of the messaging module (for example: one in /sites/all/modules and another in /profiles/openatrium/modules/contrib)? Obviously there should only be one instance. Lastly, if none of that helps, I can confirm the patch in #3 and the 6.x-2.x (dev) version both fix the problem in OA 1.4.

@Kiki1597: same as (directly) above - I can confirm the patch in #3 and the 6.x-2.x (dev) version both fix the problem in OA 1.4, so there's no need to modify your error reporting settings. Just apply the patch or update to the 6.x-2.x (dev) version.

clemens.tolboom’s picture

@paskainos thanks for the feedback.

My comment from #21 was about bad code style. There is no need for call_user_func_array (6.x-2.x-dev) ... the patch from #3 has none either.

In #25 I see no jokes. It tried to XRef to the API change of token.

According to your last line in #29 the issue seems to be fixed? But I guess not in an official release? Otherwise this should be RTBC right?

bendiy’s picture

Status: Needs review » Reviewed & tested by the community

+1 for #3.

Now how about an updated release? :)

mynameiscorey’s picture

+1 for #3

Z2222’s picture

I'm having a problem with Messaging 6.x-2.4. My entire site is running very slowly, and I'm not sure if it's this module, but the log is full of these error messages:

The messaging_text_replace() function called token replacement with an array rather than a string for $text in /home/*******/public_html/sites/all/modules/token/token.module on line 263

(There are 20,000 forum posts, so I think it is sending a lot of notifications.)

The patch in message #3 seems to have stopped it for now though. Thanks for posting that...

AlfTheCat’s picture

Status: Reviewed & tested by the community » Needs work

I applied patch #3 to version 2.4 but I did encounter serious performance issues. It took down a medium sized VPS several times before I rolled back the patch and things are now looking normal again.

I couldn't do serious debugging, because of the urgency of the performance issues but I interpreted #21 as such that the patch from #3 would not have the performance issue seen in #7 , but that assumption is clearly wrong.

Hence, -1 for #3, unfortunately I think more work is required.