email_to_user( ) change in moodle 2.6

email_to_user( ) change in moodle 2.6

by Joseph Rézeau -
Number of replies: 4
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi all,

The Questionnaire plugin uses the moodlelib email_to_useregg function in a non-standard way. Upon submission, an email notification is (optionally) sent to one or more email addresses entered in the appropriate Submission options field.

Up to Moodle 2.5 included, this worked well, as email_to_useregg checked the following:

if (empty($user) || empty($user->email))

where, obviously, a valid email was provided and it worked fine.

But in Moodle 2.6, the check has changed to:

if (empty($user) or empty($user->id))

which of course returns an error message, because Questionnaire is not sending a valid $user->id to email_to_useregg.

I wonder why that change was made?

What should I do? As a workaround, I can always send a "dummy" value for $user->id, e.g. 99999. I have tested and it works. Any other suggestions?

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: email_to_user( ) change in moodle 2.6

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

I don't have an answer, obviously, but it is nice (or perhaps frustrating depending on your point of view) to see that the emoticons filter is working heresmile

In reply to Mary Cooch

Re: email_to_user( ) change in moodle 2.6

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

"frustrating" is the word.

I do hate it when things that I did not intend to be filtered are automatically filtered. If I want to insert a smiley, I click on the smiley button in the editor. I do not want that stupid automatic filter to do things for me. angry

In reply to Joseph Rézeau

Re: email_to_user( ) change in moodle 2.6

by Yuliya Bozhko -

Hi Joseph,

Have you tried using core_user::get_noreply_user() to send emails to the users? This method generates a dummy user object that can be used for sending emails. 

Another thing is that I would recommend using message_send() instead of email_to_user() as this way messages will be going through various checks taking into account user preferences and global site settings about getting emails and notification

Yuliya

In reply to Yuliya Bozhko

Re: email_to_user( ) change in moodle 2.6

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Thanks for your suggestions, Yuliya.

I will re-think how e-mail notification is sent out in Questionnaire anyway.

Joseph