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') . "
$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
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);
// 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
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
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
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}
/**
* 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);
}