Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When i use the textarea "Additionally only create newsletter edition if the following code returns true", cron.php returns this error:
"Fatal error: Cannot use object of type stdClass as array in /****/sites/all/modules/simplenews_scheduler/simplenews_scheduler.module on line 330".
The PHP code that i insert in this textarea is:
$view = views_get_view("newsletter");
$output = $view->preview("default");
$content = false;
foreach($view->result as $row) $content = true;
return $content;
Comments
Comment #1
joachim CreditAttribution: joachim commentedThis is because the variables in your code are overwriting the variables in the module code that calls the eval().
We should move the eval() to a helper function where it can't affect any variables; there's http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_eval/6 in core to help with that.
In the meantime, rewrite your code to not use $row. Though I don't really get why you are doing that loop:
If you want to say 'return TRUE if the view has a result', then use count(), like this:
or even:
BTW: Note that the PHP code evaluation has a bug on 2.1, as it does a 'break' rather than a 'continue' -- subsequent newsletter results will be ignored!
Comment #2
thalemn CreditAttribution: thalemn commentedI am using insert view and it works as designed. And just to clarify, if I use the php code snippet and it stops sending a new message because the view results are 0, then the next time the view results are > 0, the newsletter will not start sending again because of a bug? (I'm using 2.1 in Drupal 6).
Is there any other way around this bug?
Comment #3
joachim CreditAttribution: joachim commented> the next time the view results are > 0, the newsletter will not start sending again because of a bug
No, not the next time. The next in the loop, at that time -- if you have more than one schedule that the code is trying to test at that particular moment.
Comment #4
thalemn CreditAttribution: thalemn commentedOK - thank you for clarifying.
And thank you for your dedication to this module. It's really a great tool.
Comment #5
joachim CreditAttribution: joachim commented> BTW: Note that the PHP code evaluation has a bug on 2.1, as it does a 'break' rather than a 'continue' -- subsequent newsletter results will be ignored!
Note to self, and anyone else interested: this is fixed in the dev version.
Comment #6
joachim CreditAttribution: joachim commentedSwitching to using drupal_eval() will require the PHP code entered in the UI to use PHP tags. Which will require either an upgrade function to add them, or manual intervention.
Is it worth the effort write an update function, or should be just show a message telling admins to update their PHP code?
Comment #7
joachim CreditAttribution: joachim commentedMoving version to D7, as this needs fixing there too (where the function is php_eval() instead, but same principle).
Comment #8
jlballes CreditAttribution: jlballes commentedThanks joachim!!
Comment #9
thalemn CreditAttribution: thalemn commentedJoachim,
My view (daily_beat) is using 6 blocks so I can have different content showing in the newsletter. Each block will only show content if it has been created/updated in the last 24 hours (the schedule is to send 1 newsletter every 24 hours, only if there is new or updated content).
I put each of the blocks in the body field using Insert View (and the content is showing as expected):
However, I am stumped on how to write the PHP code to return true (and send a message). Here's what I've tried and it works when I have just one block inserted into the view (block_1):
Can you please help with how to tweak this php so it returns true if 1 of the 6 blocks returns true?
I was thinking that I could simply put the blocks in as an array:
But this isn't working (no message is sent).
Thank you for your assistance with this.
Comment #10
joachim CreditAttribution: joachim commentedThat's not to do with this specific bug -- something like that should go in a support request. Or ask on IRC ;)
Comment #11
thalemn CreditAttribution: thalemn commentedRight - sorry! I've posted it as support request.
Comment #12
dgtlmoon CreditAttribution: dgtlmoon commentedI think it would be fine to change it, as the 7.x version is still in dev mode.
so changing to drupal_eval is totally fine :)
Comment #13
dgtlmoon CreditAttribution: dgtlmoon commentedAlso there is a case to remove this all together
Comment #14
dgtlmoon CreditAttribution: dgtlmoon commentedMost people seem to use this for testing the output of a view.
Perhaps the whole eval thing can be replaced with a view execution and test result has >= 'n' results, as well as a drupal_alter / module hook ?
Comment #15
joachim CreditAttribution: joachim commentedYeah, I think Berdir was talking about changing this to a hook. But I'm not sure on the best architecture to use here, and I think that would be potentially a big restructuring.
That might be best left to a 3.x branch.
In the meantime there's no harm in having the PHP eval provided it's got a proper permission on it, which it does now (the security update on 6.x was accompanied by a corresponding commit on 7.x).
Comment #16
dgtlmoon CreditAttribution: dgtlmoon commentedI dont think its a lot of restructure, just a matter of making the decision, as it's still in 7x.-dev phase, i think its allowable if the long term outcome is better
Comment #17
dgtlmoon CreditAttribution: dgtlmoon commentedAt this point i think we need todo what ever we can to just make a solid release