From 2abc0d001d73c930644d0514ca3ba51857dfd6db Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 20 Aug 2008 08:56:38 +0000 Subject: [PATCH] MDL-15605 merge problem. --- admin/health.php | 101 ----------------------------------------------- 1 file changed, 101 deletions(-) diff --git a/admin/health.php b/admin/health.php index c8a9a025455..66d7b67f957 100644 --- a/admin/health.php +++ b/admin/health.php @@ -619,107 +619,6 @@ class problem_000014 extends problem_base { } } -class problem_000015 extends problem_base { - function title() { - return 'Question categories should belong to a valid context'; - } - function exists() { - global $CFG; - return record_exists_sql(" - SELECT qc.*, (SELECT COUNT(1) FROM {$CFG->prefix}question q WHERE q.category = qc.id) AS numquestions - FROM {$CFG->prefix}question_categories qc - LEFT JOIN {$CFG->prefix}context con ON qc.contextid = con.id - WHERE con.id IS NULL"); - } - function severity() { - return SEVERITY_ANNOYANCE; - } - function description() { - global $CFG; - $problemcategories = get_records_sql(" - SELECT qc.id, qc.name, qc.contextid, (SELECT COUNT(1) FROM {$CFG->prefix}question q WHERE q.category = qc.id) AS numquestions - FROM {$CFG->prefix}question_categories qc - LEFT JOIN {$CFG->prefix}context con ON qc.contextid = con.id - WHERE con.id IS NULL - ORDER BY numquestions DESC, qc.name"); - $table = '' . - "\n"; - $maxnumquestions = 0; - if ($problemcategories) { - foreach ($problemcategories as $cat) { - $table .= "\n"; - if ($maxnumquestions < $cat->numquestions) { - $maxnumquestions = $cat->numquestions; - } - } - } - $table .= '
Cat idCategory nameContext idNum Questions
$cat->id/td>" . s($cat->name) . "" . - $cat->contextid ."$cat->numquestions
'; - return '

All question categories are linked to a context id, and, ' . - 'the context they are linked to must exist. The following categories ' . - 'belong to a non-existant category:

' . $table . '

Any of these ' . - 'categories that contain no questions can just be deleted form the database. ' . - 'Other categories will require more thought.

'; - } - function solution() { - global $CFG; - return '

You can delete the empty categories by executing the following SQL:

-DELETE FROM ' . $CFG->prefix . 'question_categories
-WHERE
-    NOT EXIST (SELECT * FROM ' . $CFG->prefix . 'question q WHERE q.category = qc.id)
-AND NOT EXIST (SELECT * FROM ' . $CFG->prefix . 'context context WHERE qc.contextid = con.id)
-        

Any remaining categories that contain questions will require more thought. ' . - 'People in the Quiz forum may be able to help.

'; - } -} - -class problem_000016 extends problem_base { - function title() { - return 'Question categories should belong to the same context as their parent'; - } - function exists() { - global $CFG; - return record_exists_sql(" - SELECT parent_qc.id AS parent, child_qc.id AS child, child_qc.contextid - FROM {$CFG->prefix}question_categories child_qc - JOIN {$CFG->prefix}question_categories parent_qc ON child_qc.parent = parent_qc.id - WHERE child_qc.contextid <> parent_qc.contextid"); - } - function severity() { - return SEVERITY_ANNOYANCE; - } - function description() { - global $CFG; - $problemcategories = get_records_sql(" - SELECT - parent_qc.id AS parentid, parent_qc.name AS parentname, parent_qc.contextid AS parentcon, - child_qc.id AS childid, child_qc.name AS childname, child_qc.contextid AS childcon - FROM {$CFG->prefix}question_categories child_qc - JOIN {$CFG->prefix}question_categories parent_qc ON child_qc.parent = parent_qc.id - WHERE child_qc.contextid <> parent_qc.contextid"); - $table = '' . - '' . - '' . - "\n"; - if ($problemcategories) { - foreach ($problemcategories as $cat) { - $table .= "\n"; - } - } - $table .= '
Child categoryParent category
IdNameContext idIdNameContext id
$cat->childid/td>" . s($cat->childname) . - "$cat->childcon$cat->parentid/td>" . s($cat->parentname) . - "$cat->parentcon
'; - return '

When one question category is the parent of another, then they ' . - 'should both belong to the same context. This is not true for the following categories:

' . - $table; - } - function solution() { - return '

An automated solution is difficult. It depends whether the ' . - 'parent or child category is in the wrong pace.' . - 'People in the Quiz forum may be able to help.

'; - } -} - class problem_00000x extends problem_base { function title() { return '';