We have used a modified version of the core with basically the same changes since December and the email log does work for us, so probably the problem is with the hook (or the way the plugin is using it). I suggest that you switch the plugin off and wait for the changes to the core. As I mentioned above, I have not tested it much.
edit: I will add the same disclaimer to the plugin readme, but will leave the plugin there, because I think it is the only plugin available that shows how to use you own mailer code.
The way the hook return value is intended to work is to permit either augmentation of the existing behavior, or replacement of the existing behavior. If you return false from a hook callback, then any additional hooks are also called, and OJS permits the normal behavior of the system to continue (in this case, sending the email and logging the results). If you return true [ed: fixed!] from a hook callback, then OJS stops further hook processing, and where relevant, halting the normal handling of the action (sending and logging).
If you’re just looking to change the sender email address, you should (off the top of my head) be able to use the hook to reconfigure the SubmissionEmailTemplate object, then return false to permit normal execution (including logging) to continue, no?
Regards,
Alec Smecher
Public Knowledge Project Team
You wrote " If you return false from a hook callback" twice, which one is true?
The plugin above was just a quick test to solve the issue that is being fixed to the core anyway at some point. I’ve not used it in production but have something similar added to the core code at the moment, so I do not have that much interest in completing the plugin.
The reason I asked was just to find out how you can use the hook it uses and still have the emails being logged.
Ok, so basically if the hook here https://github.com/pkp/pkp-lib/blob/master/classes/mail/Mail.inc.php#L463 is called, it returns true and the email logging is stopped? So basically any plugin that uses that hook to send emails should have it’s own method of logging the sent emails to ojs db? (that is probably missed by most users of that hook).
As long as your hook callbacks return false, the call to HookRegistry::call will return false too. If one returns true, the rest will be skipped and the HookRegistry::call will return true.
Regards,
Alec Smecher
Public Knowledge Project Team
The bottom line: I can not see how you could create a plugin that would use that hook and succesfully let OJS log the sent emails? edit: unless you add the logging code to the plugin itself, that is.
Have a look at HookRegistry::call; I think the return value of that function isn’t what you’re expecting. It’s not success/failure, but more “do I continue working or do I stop”.
If it’s resulting in a true return, then that should suggest that some hook callback didn’t return false – or that something isn’t working properly. It’ll need some debugging.
Regards,
Alec Smecher
Public Knowledge Project Team
If the line https://github.com/pkp/pkp-lib/blob/master/classes/mail/Mail.inc.php#L463 would look something like if (HookRegistry::call('Mail::send', array($this, &$result))) return $result; I would understand how it could return the false from the plugin using the hook. But I just can not see how it currently returns anything else than true.
But yeah, I give up @bog I suggest that you stop using the plugin. I am not sure how I could fix it to support email logging if that seems to be a problem and unfortunately have my hands full of other work so can not look into the issue that much at the moment.
Basically now, when a sendmail is succesful, the plugi callback should return false and thus return to the hook call in the mail.inc.php which has the conditional return true for the hook call. And the code should then go on to log the email.
Feel free to try the modified code @bog, but note that I did not test it
we have tested the above code but it did not work as expected. What happens is that the system sends the Global Sender email and the usual email as well, which is logged in the email_log. This is not what we wanted, unfortunately. We will use it this way because it is very important to have Global Sender, but we would extremely appreciate if you could show us how to have a log with Global Sender.
We have also seen that there are PHP warnings from the Global Sender plugin, what may also be important, like the ones below.
Thanks in advance for your help,
Bogi
[13-Jan-2019 05:56:01 Europe/Budapest] PHP Warning: Illegal string
offset 'email' in
/var/www/html/cyberojs3114/plugins/generic/useGlobalSender/UseGlobalSenderPlugin.inc.php
on line 114
[13-Jan-2019 05:56:01 Europe/Budapest] PHP Warning: Illegal string
offset 'email' in
/var/www/html/cyberojs3114/plugins/generic/useGlobalSender/UseGlobalSenderPlugin.inc.php
on line 114
[13-Jan-2019 05:56:01 Europe/Budapest] PHP Warning: Illegal string
offset 'email' in
/var/www/html/cyberojs3114/plugins/generic/useGlobalSender/UseGlobalSenderPlugin.inc.php
on line 135
[13-Jan-2019 05:56:01 Europe/Budapest] PHP Warning: Illegal string
offset 'name' in
/var/www/html/cyberojs3114/plugins/generic/useGlobalSender/UseGlobalSenderPlugin.inc.php
on line 135
[13-Jan-2019 05:56:01 Europe/Budapest] PHP Warning: Illegal string
offset 'email' in
/var/www/html/cyberojs3114/plugins/generic/useGlobalSender/UseGlobalSenderPlugin.inc.php
on line 135
No, in email_log we can see the log of the “normal” email, with the sender as without the Global Sender plugin. In other words, there are two emails sent, the Global Sender one, which is still not logged, and the original email, which is logged.