MDL-32780: Use Moodle functions for building SQL in assignment upgrade tool
authorDamyon Wiese <damyon.wiese@netspot.com.au>
Fri, 4 May 2012 07:35:51 +0000 (15:35 +0800)
committerDamyon Wiese <damyon.wiese@netspot.com.au>
Mon, 7 May 2012 02:54:24 +0000 (10:54 +0800)
Fixed functions:
tool_assignmentupgrade_load_all_upgradable_assignmentids() and
tool_assignmentupgrade_any_upgradable_assignments()

admin/tool/assignmentupgrade/locallib.php

index 89e0e24..5b81485 100644 (file)
@@ -131,16 +131,11 @@ function tool_assignmentupgrade_any_upgradable_assignments() {
             $upgradabletypes[] = $shorttype;
         }
     }
-    $paramlist = '?';
-    foreach ($upgradabletypes as $index => $upgradabletype) {
-        if ($index > 0) {
-            $paramlist .= ', ?';
-        }
-    }
+    list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
 
-    $record = $DB->get_record_sql('SELECT COUNT(id) as count from {assignment} where assignmenttype in (' . $paramlist . ')', $upgradabletypes);
+    $count = $DB->count_records_sql('SELECT COUNT(id) from {assignment} where assignmenttype ' . $sql, $params);
 
-    return $record->count > 0;
+    return $count > 0;
 }
 
 /**
@@ -161,14 +156,10 @@ function tool_assignmentupgrade_load_all_upgradable_assignmentids() {
             $upgradabletypes[] = $shorttype;
         }
     }
-    $paramlist = '?';
-    foreach ($upgradabletypes as $index => $upgradabletype) {
-        if ($index > 0) {
-            $paramlist .= ', ?';
-        }
-    }
 
-    $records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype in (' . $paramlist . ')', $upgradabletypes);
+    list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
+
+    $records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype ' . $sql, $params);
     $ids = array();
     foreach ($records as $record) {
         $ids[] = $record->id;