moodleou / moodle-mod_forumng

ForumNG forum module for Moodle
19 stars 20 forks source link

Fatal error when student viewing discussions page #47

Closed nadavkav closed 9 years ago

nadavkav commented 9 years ago

Our MySQL server was "sensitive" to the 'read' in '', fr.time AS read", so... to workaround it I changed it to "tread". but I guess some other part of the code needs it, as it is. (I will find out and update this issue report)

Here is the debug info:

Debug info: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read FROM mdl_forumng_posts fp INNER JOIN mdl_user u ON fp.userid = u.id' at line 16

SELECT fp.*, u.id as u_id,u.username as u_username,u.picture as u_picture,u.url as u_url,u.imagealt as u_imagealt,u.email as u_email,u.maildisplay as u_maildisplay,u.mailformat as u_mailformat,u.maildigest as u_maildigest,u.emailstop as u_emailstop,u.deleted as u_deleted,u.auth as u_auth,u.timezone as u_timezone,u.lang as u_lang,u.idnumber as u_idnumber,u.firstnamephonetic as u_firstnamephonetic,u.lastnamephonetic as u_lastnamephonetic,u.middlename as u_middlename,u.alternatename as u_alternatename,u.firstname as u_firstname,u.lastname as u_lastname, eu.id as eu_id,eu.username as eu_username,eu.picture as eu_picture,eu.url as eu_url,eu.imagealt as eu_imagealt,eu.idnumber as eu_idnumber,eu.email as eu_email,eu.firstnamephonetic as eu_firstnamephonetic,eu.lastnamephonetic as eu_lastnamephonetic,eu.middlename as eu_middlename,eu.alternatename as eu_alternatename,eu.firstname as eu_firstname,eu.lastname as eu_lastname, du.id as du_id,du.username as du_username,du.picture as du_picture,du.url as du_url,du.imagealt as du_imagealt,du.idnumber as du_idnumber,du.email as du_email,du.firstnamephonetic as du_firstnamephonetic,du.lastnamephonetic as du_lastnamephonetic,du.middlename as du_middlename,du.alternatename as du_alternatename,du.firstname as du_firstname,du.lastname as du_lastname , (SELECT AVG(rating) FROM mdl_forumng_ratings WHERE postid = fp.id) AS averagerating, (SELECT COUNT(1) FROM mdl_forumng_ratings WHERE postid = fp.id) AS numratings, (SELECT rating FROM mdl_forumng_ratings WHERE postid = fp.id AND userid = ?) AS ownrating , ff.flagged

, fr.time AS read FROM mdl_forumng_posts fp INNER JOIN mdl_user u ON fp.userid = u.id LEFT JOIN mdl_user eu ON fp.edituserid = eu.id LEFT JOIN mdl_user du ON fp.deleteuserid = du.id

LEFT JOIN mdl_forumng_flags ff ON ff.postid = fp.id AND ff.userid = ?

LEFT JOIN mdl_forumng_read_posts fr ON fr.postid = fp.id AND fr.userid = ? WHERE fp.discussionid=? AND fp.oldversion=0 ORDER BY fp.created

[array ( 0 => '11692', 1 => '11692', 2 => '11692', 3 => '1322', )] Error code: dmlreadexception Stack trace: line 443 of /lib/dml/moodle_database.php: dml_read_exception thrown line 1014 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end() line 1036 of /mod/forumng/mod_forumng_post.php: call to mysqli_native_moodle_database->get_records_sql() line 661 of /mod/forumng/mod_forumng_discussion.php: call to mod_forumng_post::query_posts() line 2548 of /mod/forumng/mod_forumng_discussion.php: call to mod_forumng_discussion->get_root_post() line 273 of /mod/forumng/type/general/forumngtype_general.php: call to mod_forumng_discussion->display_unread_skip_link() line 104 of /mod/forumng/discuss.php: call to forumngtype_general->print_discussion_page()

aspark21 commented 9 years ago

@nadavkav looks identical to #44 but do you get this occurring on all student accounts? This only seemed to occur on a limited number of accounts (3) and I "resolved" by disabling those accounts & regenerating new ones for those users. What MDL & MySQL versions are you on?

nadavkav commented 9 years ago

Indeed you are right. (after making some more test throughout the day) It seems only a few users experience this kind of behavior.

We are using MySQL 5.5.37 and PHP 5.4.32 and Moodle 2.7.2

The users are very active in those forums and I do not think I can disable their accounts at the moment. Anyways, It all seems back to normal after this workaround. Although I need to find the right piece of code that was expecting the "read" variable. (I will follow the stack trace...)

echiffre commented 9 years ago

I think I found the cause of the error. It occurs because the line $readquery = 'fr.time AS read'; in function query_posts (file : mod_forumng_post.php) "read" appears to be a key word, at least for Maria DB, I don't know about Mysql.

In MariaDB, if I execute the query with "read", there is the error. If I replace "read" with "yyyy", it's OK.

The error doesn't appear at all users because this snippet of code is in the structure "if/else" so it is not written and executed for all.

jason-platts commented 9 years ago

Thanks for the info everyone.

I've made a change to the query and places in that file that refer to the result so that 'read' is no longer used in the query.

Will be upstream to master in next push (which should be soon!).