]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15073 delete_records now truncates table if deleting all records, fixed some...
authorskodak <skodak>
Sat, 31 May 2008 15:32:28 +0000 (15:32 +0000)
committerskodak <skodak>
Sat, 31 May 2008 15:32:28 +0000 (15:32 +0000)
lib/accesslib.php
lib/datalib.php
lib/dml/moodle_database.php

index fa3753025cdbdb1363ec23e52ebbf087b2750534..0c35c7c17a2e1e798455f102d9c1d739040aa214 100755 (executable)
@@ -5175,8 +5175,6 @@ function build_context_path($force=false) {
                        WHERE temp.id={context}.id";
     }
 
-    $udelsql = "TRUNCATE TABLE {context_temp}";
-
     // Top level categories
     $sql = "UPDATE {context}
                SET depth=2, path=" . $DB->sql_concat("'$base/'", 'id') . "
@@ -5188,13 +5186,13 @@ function build_context_path($force=false) {
                    $emptyclause";
 
     $DB->execute($sql);
-    $DB->execute($udelsql);
+    $DB->delete_records('context_temp');
 
     // Deeper categories - one query per depthlevel
     $maxdepth = $DB->get_field_sql("SELECT MAX(depth)
                                FROM {course_categories}");
     for ($n=2; $n<=$maxdepth; $n++) {
-        $sql = "INSERT INTO {context}_temp (id, path, depth)
+        $sql = "INSERT INTO {context_temp} (id, path, depth)
                 SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", $n+1
                   FROM {context} ctx
                   JOIN {course_categories} c ON ctx.instanceid=c.id
@@ -5203,7 +5201,7 @@ function build_context_path($force=false) {
                        AND pctx.contextlevel=".CONTEXT_COURSECAT."
                        AND c.depth=$n
                        AND NOT EXISTS (SELECT 'x'
-                                       FROM {context}_temp temp
+                                       FROM {context_temp} temp
                                        WHERE temp.id = ctx.id)
                        $ctxemptyclause";
         $DB->execute($sql);
@@ -5211,11 +5209,11 @@ function build_context_path($force=false) {
         // this is needed after every loop
         // MDL-11532
         $DB->execute($updatesql);
-        $DB->execute($udelsql);
+        $DB->delete_records('context_temp');
     }
 
     // Courses -- except sitecourse
-    $sql = "INSERT INTO {context}_temp (id, path, depth)
+    $sql = "INSERT INTO {context_temp} (id, path, depth)
             SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1
               FROM {context} ctx
               JOIN {course} c ON ctx.instanceid=c.id
@@ -5224,16 +5222,16 @@ function build_context_path($force=false) {
                    AND c.id!=".SITEID."
                    AND pctx.contextlevel=".CONTEXT_COURSECAT."
                        AND NOT EXISTS (SELECT 'x'
-                                       FROM {context}_temp temp
+                                       FROM {context_temp} temp
                                        WHERE temp.id = ctx.id)
                    $ctxemptyclause";
     $DB->execute($sql);
 
     $DB->execute($updatesql);
-    $DB->execute($udelsql);
+    $DB->delete_records('context_temp');
 
     // Module instances
-    $sql = "INSERT INTO {context}_temp (id, path, depth)
+    $sql = "INSERT INTO {context_temp} (id, path, depth)
             SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1
               FROM {context} ctx
               JOIN {course_modules} cm ON ctx.instanceid=cm.id
@@ -5241,16 +5239,16 @@ function build_context_path($force=false) {
              WHERE ctx.contextlevel=".CONTEXT_MODULE."
                    AND pctx.contextlevel=".CONTEXT_COURSE."
                        AND NOT EXISTS (SELECT 'x'
-                                       FROM {context}_temp temp
+                                       FROM {context_temp} temp
                                        WHERE temp.id = ctx.id)
                    $ctxemptyclause";
     $DB->execute($sql);
 
     $DB->execute($updatesql);
-    $DB->execute($udelsql);
+    $DB->delete_records('context_temp');
 
     // Blocks - non-pinned course-view only
-    $sql = "INSERT INTO {context}_temp (id, path, depth)
+    $sql = "INSERT INTO {context_temp} (id, path, depth)
             SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1
               FROM {context} ctx
               JOIN {block_instance} bi ON ctx.instanceid = bi.id
@@ -5259,13 +5257,13 @@ function build_context_path($force=false) {
                    AND pctx.contextlevel=".CONTEXT_COURSE."
                    AND bi.pagetype='course-view'
                        AND NOT EXISTS (SELECT 'x'
-                                       FROM {context}_temp temp
+                                       FROM {context_temp} temp
                                        WHERE temp.id = ctx.id)
                    $ctxemptyclause";
     $DB->execute($sql);
 
     $DB->execute($updatesql);
-    $DB->execute($udelsql);
+    $DB->delete_records('context_temp');
 
     // Blocks - others
     $sql = "UPDATE {context}
index ad3488d7b5dfa8da83e25afa5b29a2ca52386ae8..07820717b52c0834a9a428be2bd5114b21e1c27a 100644 (file)
@@ -1519,7 +1519,7 @@ function update_timezone_records($timezones) {
     global $DB;
 
 /// Clear out all the old stuff
-    $DB->execute("TRUNCATE TABLE {timezone}");
+    $DB->delete_records('timezone');
 
 /// Insert all the new stuff
     foreach ($timezones as $timezone) {
index d7292798639a3d49e9e172d9e6efd5a1f61eb601..7389a97758c145fd64a6c0d8c7d82a63fca51fe4 100644 (file)
@@ -1032,12 +1032,16 @@ abstract class moodle_database {
 
     /**
      * Delete the records from a table where all the given conditions met.
+     * If conditions not specified, table is truncated.
      *
      * @param string $table the table to delete from.
      * @param array $conditions optional array $fieldname=>requestedvalue with AND in between
      * @return returns success.
      */
-    public function delete_records($table, array $conditions) {
+    public function delete_records($table, array $conditions=null) {
+        if (is_null($conditions)) {
+            return $this->execute("TRUNCATE TABLE {".$table."}");
+        }
         list($select, $params) = $this->where_clause($conditions);
         return $this->delete_records_select($table, $select, $params);
     }