From a2ed10a5e7baa1bd8369838cc3b3cfedc57ef0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yolanda=20Ord=C3=B3=C3=B1ez=20Rufat?= Date: Tue, 30 Sep 2014 12:44:18 +0200 Subject: [PATCH 1/2] MDL-47466 calendar: use get_in_or_equal() in function calendar_get_events to fix problem with ORA-01795 --- calendar/lib.php | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 8bb2a63ffb4..cc77f9c6cf0 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -683,19 +683,18 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur global $DB; $whereclause = ''; + $params = array(); // Quick test if(is_bool($users) && is_bool($groups) && is_bool($courses)) { return array(); } - if(is_array($users) && !empty($users)) { + if((is_array($users) && !empty($users)) or is_numeric($users)) { // Events from a number of users if(!empty($whereclause)) $whereclause .= ' OR'; - $whereclause .= ' (userid IN ('.implode(',', $users).') AND courseid = 0 AND groupid = 0)'; - } else if(is_numeric($users)) { - // Events from one user - if(!empty($whereclause)) $whereclause .= ' OR'; - $whereclause .= ' (userid = '.$users.' AND courseid = 0 AND groupid = 0)'; + list($insqlusers, $inparamsusers) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED); + $whereclause .= " (userid $insqlusers AND courseid = 0 AND groupid = 0)"; + $params = array_merge($params, $inparamsusers); } else if($users === true) { // Events from ALL users if(!empty($whereclause)) $whereclause .= ' OR'; @@ -704,14 +703,12 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur // No user at all, do nothing } - if(is_array($groups) && !empty($groups)) { + if((is_array($groups) && !empty($groups)) or is_numeric($groups)) { // Events from a number of groups if(!empty($whereclause)) $whereclause .= ' OR'; - $whereclause .= ' groupid IN ('.implode(',', $groups).')'; - } else if(is_numeric($groups)) { - // Events from one group - if(!empty($whereclause)) $whereclause .= ' OR '; - $whereclause .= ' groupid = '.$groups; + list($insqlgroups, $inparamsgroups) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED); + $whereclause .= " groupid $insqlgroups "; + $params = array_merge($params, $inparamsgroups); } else if($groups === true) { // Events from ALL groups if(!empty($whereclause)) $whereclause .= ' OR '; @@ -719,15 +716,11 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur } // boolean false (no groups at all): we don't need to do anything - if(is_array($courses) && !empty($courses)) { - if(!empty($whereclause)) { - $whereclause .= ' OR'; - } - $whereclause .= ' (groupid = 0 AND courseid IN ('.implode(',', $courses).'))'; - } else if(is_numeric($courses)) { - // One course + if((is_array($courses) && !empty($courses)) or is_numeric($courses)) { if(!empty($whereclause)) $whereclause .= ' OR'; - $whereclause .= ' (groupid = 0 AND courseid = '.$courses.')'; + list($insqlcourses, $inparamscourses) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED); + $whereclause .= " (groupid = 0 AND courseid $insqlcourses)"; + $params = array_merge($params, $inparamscourses); } else if ($courses === true) { // Events from ALL courses if(!empty($whereclause)) $whereclause .= ' OR'; @@ -761,7 +754,7 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur $whereclause .= ' AND visible = 1'; } - $events = $DB->get_records_select('event', $whereclause, null, 'timestart'); + $events = $DB->get_records_select('event', $whereclause, $params, 'timestart'); if ($events === false) { $events = array(); } From c3f51a3c79b81e87f8cb1050a07190107017eb70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yolanda=20Ord=C3=B3=C3=B1ez=20Rufat?= Date: Tue, 14 Oct 2014 14:58:05 +0200 Subject: [PATCH 2/2] MDL-47466 calendar: fixed error ORA-01795 in calendar_get_events --- calendar/lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index cc77f9c6cf0..c64b14a8228 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -689,7 +689,7 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur return array(); } - if((is_array($users) && !empty($users)) or is_numeric($users)) { + if ((is_array($users) && !empty($users)) or is_numeric($users)) { // Events from a number of users if(!empty($whereclause)) $whereclause .= ' OR'; list($insqlusers, $inparamsusers) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED); @@ -703,7 +703,7 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur // No user at all, do nothing } - if((is_array($groups) && !empty($groups)) or is_numeric($groups)) { + if ((is_array($groups) && !empty($groups)) or is_numeric($groups)) { // Events from a number of groups if(!empty($whereclause)) $whereclause .= ' OR'; list($insqlgroups, $inparamsgroups) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED); @@ -716,7 +716,7 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur } // boolean false (no groups at all): we don't need to do anything - if((is_array($courses) && !empty($courses)) or is_numeric($courses)) { + if ((is_array($courses) && !empty($courses)) or is_numeric($courses)) { if(!empty($whereclause)) $whereclause .= ' OR'; list($insqlcourses, $inparamscourses) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED); $whereclause .= " (groupid = 0 AND courseid $insqlcourses)";