]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14451 removed pre 1.9 upgrade code - question upgrade related
authorskodak <skodak>
Sun, 11 May 2008 19:03:24 +0000 (19:03 +0000)
committerskodak <skodak>
Sun, 11 May 2008 19:03:24 +0000 (19:03 +0000)
admin/report/question/index.php
question/type/multichoice/db/upgrade.php
question/upgrade.php

index 67ab0779ee114d3a4b5416be6acee80d9e455c1c..070c91e4be2607d8b227f4b462e52443ce81760e 100644 (file)
@@ -1,7 +1,6 @@
 <?php // $Id$
 
     require_once('../../../config.php');
-    require_once($CFG->dirroot.'/question/upgrade.php');
     require_once($CFG->libdir.'/adminlib.php');
 
     admin_externalpage_setup('reportquestion');
@@ -9,65 +8,6 @@
     admin_externalpage_print_header();
     print_heading(get_string('adminreport', 'question'));
 
-    $probstr = '';
-    $contextupgradeversion = 2007081000;
-    if ($CFG->version < $contextupgradeversion){
-        ///cwrqpfs issue
-        $probstr = print_heading(get_string('cwrqpfs', 'question'), '', 3, 'main', true);
-
-        if ($updates = question_cwqpfs_to_update()){
-
-            $probstr .=get_string('cwrqpfsinfo', 'question');
-            $probstr .= '<ul>';
-            $catlist = join(array_keys($updates), ',');
-            //get info about cateogries and no of questions used outside category's course
-            $categories = get_records_sql('SELECT qc.*, c.fullname as coursename FROM '.$CFG->prefix.'question_categories as qc, '
-                        .$CFG->prefix.'course as c WHERE qc.course = c.id AND qc.id IN ('.$catlist.')');
-            foreach ($updates as $id => $publish){
-                $categories[$id]->caturl = "$CFG->wwwroot/question/category.php?sesskey=".sesskey().
-                            "&amp;edit=$id&amp;courseid=".$categories[$id]->course;
-                if ($categories[$id]->publish){
-                    $categories[$id]->changefrom = get_string('published', 'question');
-                    $categories[$id]->changeto = get_string('unpublished', 'question');
-                } else {
-                    $categories[$id]->changefrom = get_string('unpublished', 'question');
-                    $categories[$id]->changeto = get_string('published', 'question');
-                }
-                $probstr .= '<li>'.get_string('changepublishstatuscat', 'question', $categories[$id]);
-                if ($questions = get_records_sql('SELECT q.*, qui.id as quizid, qui.name as quizname, cm.id as cmid, '
-                               .'qui.course, c.fullname as coursename FROM '.$CFG->prefix.'question q, '
-                               .$CFG->prefix.'quiz_question_instances qqi, '
-                               .$CFG->prefix.'quiz qui, '
-                               .$CFG->prefix.'course_modules cm, '
-                               .$CFG->prefix.'modules m, '
-                               .$CFG->prefix.'course c '
-                            .'WHERE (q.category = '.$id.' AND qqi.question = q.id '
-                            .'AND qqi.quiz = qui.id '
-                            .'AND qui.course = c.id '
-                            .'AND cm.instance = qui.id '
-                            .'AND cm.module = m.id '
-                            .'AND m.name = \'quiz\''
-                            .'AND ('.$categories[$id]->course.' <> qui.course)) ORDER BY qui.id ASC')){
-
-                    $probstr .= '<ul>';
-                    foreach ($questions as $question){
-                        $question->quizurl = "$CFG->wwwroot/mod/quiz/edit.php?cmid=".$question->cmid;
-                        $question->qurl = "$CFG->wwwroot/question/question.php?cmid={$question->cmid}&amp;id={$question->id}&amp;returnurl=".urlencode($FULLME);
-                        $probstr .= '<li>'.get_string('questionaffected', 'question', $question).'</li>';
-                    }
-                    $probstr .= '</ul>';
-                }
-                $probstr .= '</li>';
-            }
-            $probstr .= '</ul>';
-        } else {
-            $probstr .=('<p>'.get_string('cwrqpfsnoprob', 'question').'</p>');
-        }
-    }
-    if ($probstr) {
-        print_box($probstr);
-    } else {
-        print_box(get_string('noprobs', 'question'), 'boxwidthnarrow boxaligncenter generalbox');
-    }
+    print_box(get_string('noprobs', 'question'), 'boxwidthnarrow boxaligncenter generalbox');
     admin_externalpage_print_footer();
 ?>
index 49ffc787dffa6416fd02e2cf9422cf954d1140f9..ec2c5ed8fc67fc6c193ac047caebce46fb111014 100644 (file)
 
 function xmldb_qtype_multichoice_upgrade($oldversion=0) {
 
-    global $CFG, $THEME, $db;
+    global $CFG, $THEME, $DB;
 
     $result = true;
 
-    // This upgrade actually belongs to the description question type,
-    // but that does not have a DB upgrade script. Therefore, multichoice
-    // is doing it.
-    // The need for this is that for a while, descriptions were being created
-    // with a defaultgrade of 1, when it shoud be 0. We need to reset them all to 0.
-    // See MDL-7925. 
-    if ($result && $oldversion < 2006121500) {
-        $result = $result && set_field('question', 'defaultgrade', 0,
-                'qtype', DESCRIPTION, 'defaultgrade', 1);
-    }
-
-    // Add a field so that question authors can choose whether and how the Choices are numbered.
-    // Subsequently changed to not create an enum constraint, because it was causing problems -
-    // See 2007081700 update.
-    if ($result && $oldversion < 2007041300) {
-        $table = new XMLDBTable('question_multichoice');
-        $field = new XMLDBField('answernumbering');
-        $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'abc', 'incorrectfeedback');
-        $result = $result && add_field($table, $field);
-    }
-
-    // This upgrade actually belongs to the description question type,
-    // but that does not have a DB upgrade script. Therefore, multichoice
-    // is doing it.
-    // The need for this is that for a while, descriptions were being created
-    // with a defaultgrade of 1, when it shoud be 0. We need to reset them all to 0.
-    // This is re-occurrence of MDL-7925, so we need to do it again. 
-    if ($result && $oldversion < 2007072000) {
-        $result = $result && set_field('question', 'defaultgrade', 0,
-                'qtype', DESCRIPTION, 'defaultgrade', 1);
-    }
-
-    // Drop enum constraint on 'answernumbering' column, and change ABC to ABCD becuase MySQL
-    // sometimes can't cope with things that differ only by case.
-    if ($result && $oldversion < 2007081700) {
-        if ($result && $oldversion >= 2007041300) {
-            $table = new XMLDBTable('question_multichoice');
-            $field = new XMLDBField('answernumbering');
-            $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'abc', 'incorrectfeedback');
-            $result = $result && change_field_enum($table, $field);
-        }
-        $result = $result && set_field('question_multichoice', 'answernumbering', 'ABCD', 'answernumbering', 'ABC');
-    }
-
     return $result;
 }
 
index f9a049cd9c9a92532ace187fd6acfd57d9f56560..d7d6c03b37ea6dfff6f53f10861374aa3af33f08 100644 (file)
  * @package questionbank
  */
 
-/**
- * This test is becuase the RQP question type was included in core
- * up to and including Moodle 1.8, and was removed before Moodle 1.9.
- *
- * Therefore, we want to check whether any rqp questions exist in the database
- * before doing the upgrade. However, the check is not relevant if that
- * question type was never installed, or if the person has chosen to
- * manually reinstall the rqp question type from contrib.
- *
- * @param $result the result object that can be modified.
- * @return null if the test is irrelevant, or true or false depending on whether the test passes.
- */
-function question_check_no_rqp_questions($result) {
-    global $CFG;
-
-    if (empty($CFG->qtype_rqp_version) || is_dir($CFG->dirroot . '/question/type/rqp')) {
-        return null;
-    } else {
-        $result->setStatus(count_records('question', 'qtype', 'rqp') == 0);
-    }
-    return $result;
-}
-
-function question_remove_rqp_qtype() {
-    global $CFG;
-
-    $result = true;
-
-    // Only remove the question type if the code is gone.
-    if (!is_dir($CFG->dirroot . '/question/type/rqp')) {
-        $table = new XMLDBTable('question_rqp_states');
-        $result = $result && drop_table($table);
-
-        $table = new XMLDBTable('question_rqp');
-        $result = $result && drop_table($table);
-
-        $table = new XMLDBTable('question_rqp_types');
-        $result = $result && drop_table($table);
-
-        $table = new XMLDBTable('question_rqp_servers');
-        $result = $result && drop_table($table);
-
-        $result = $result && unset_config('qtype_rqp_version');
-    }
-
-    return $result;
-}
-
-function question_remove_rqp_qtype_config_string() {
-    global $CFG;
-
-    $result = true;
-
-    // An earlier, buggy version of the previous function missed out the unset_config call.
-    if (!empty($CFG->qtype_rqp_version) && !is_dir($CFG->dirroot . '/question/type/rqp')) {
-        $result = $result && unset_config('qtype_rqp_version');
-    }
-
-    return $result;
-}
-
-/**
- * @param $result the result object that can be modified.
- * @return null if the test is irrelevant, or true or false depending on whether the test passes.
- */
-function question_random_check($result){
-    global $CFG;
-    if (!empty($CFG->running_installer) //no test on first installation, no questions to test yet
-            || $CFG->version >= 2007081000){//no test after upgrade seperates question cats into contexts.
-        return null;
-    }
-    if (!$toupdate = question_cwqpfs_to_update()){
-        $result->setStatus(true);//pass test
-    } else {
-        //set the feedback string here and not in xml file since we need something
-        //more complex than just a string picked from admin.php lang file
-        $a = new object();
-        $a->reporturl = "{$CFG->wwwroot}/{$CFG->admin}/report/question/";
-        $lang = str_replace('_utf8', '', current_language());
-        $a->docsurl = "{$CFG->docroot}/$lang/admin/report/question/index";
-        $result->setFeedbackStr(array('questioncwqpfscheck', 'admin', $a));
-        $result->setStatus(false);//fail test
-    }
-    return $result;
-}
-/*
- * Delete all 'random' questions that are not been used in a quiz.
- */
-function question_delete_unused_random(){
-    global $CFG;
-    $tofix = array();
-    $result = true;
-    //delete all 'random' questions that are not been used in a quiz.
-    if ($qqis = get_records_sql("SELECT q.* FROM {$CFG->prefix}question q LEFT JOIN ".
-                                    "{$CFG->prefix}quiz_question_instances qqi ".
-                                    "ON q.id = qqi.question WHERE q.qtype='random' AND qqi.question IS NULL")){
-        $qqilist = join(array_keys($qqis), ',');
-        $result = $result && delete_records_select('question', "id IN ($qqilist)");
-    }
-    return $result;
-}
-function question_cwqpfs_to_update($categories = null){
-    global $CFG;
-
-    $tofix = array();
-    $result = true;
-
-    //any cats with questions picking from subcats?
-    if (!$cwqpfs = get_records_sql_menu("SELECT DISTINCT qc.id, 1 ".
-                                    "FROM {$CFG->prefix}question q, {$CFG->prefix}question_categories qc ".
-                                    "WHERE q.qtype='random' AND qc.id = q.category AND ".
-                                     sql_compare_text('q.questiontext'). " = '1'")){
-        return array();
-    } else {
-        if ($categories === null){
-            $categories = get_records('question_categories');
-        }
-        $categorychildparents = array();
-        foreach ($categories as $id => $category){
-            $categorychildparents[$category->course][$id] = $category->parent;
-        }
-        foreach ($categories as $id => $category){
-            if (FALSE !== array_key_exists($category->parent, $categorychildparents[$category->course])){
-                //this is not a top level cat
-                continue;//go to next category
-            } else{
-                $tofix += question_cwqpfs_check_children($id, $categories, $categorychildparents[$category->course], $cwqpfs);
-            }
-        }
-    }
-
-    return $tofix;
-}
-
-function question_cwqpfs_check_children($checkid, $categories, $categorychildparents, $cwqpfs){
-    $tofix = array();
-    if (array_key_exists($checkid, $cwqpfs)){//cwqpfs in this cat
-        $getchildren = array();
-        $getchildren[] = $checkid;
-        //search down tree and find all children
-        while ($nextid = array_shift($getchildren)){//repeat until $getchildren
-                                                    //empty;
-            $childids = array_keys($categorychildparents, $nextid);
-            foreach ($childids as $childid){
-                if ($categories[$childid]->publish != $categories[$checkid]->publish){
-                    $tofix[$childid] = $categories[$checkid]->publish;
-                }
-            }
-            $getchildren = array_merge($getchildren, $childids);
-        }
-    } else { // check children for cwqpfs
-        $childrentocheck = array_keys($categorychildparents, $checkid);
-        foreach ($childrentocheck as $childtocheck){
-            $tofix += question_cwqpfs_check_children($childtocheck, $categories, $categorychildparents, $cwqpfs);
-        }
-    }
-    return $tofix;
-}
-
-function question_category_next_parent_in($contextid, $question_categories, $id){
-    $nextparent = $question_categories[$id]->parent;
-    if ($nextparent == 0){
-        return 0;
-    } elseif (!array_key_exists($nextparent, $question_categories)){
-        //finished searching up the category hierarchy. For some reason
-        //the top level items is not 0. We'll return 0 though.
-        return 0;
-    } elseif ($contextid == $question_categories[$nextparent]->contextid){
-        return $nextparent;
-    } else {
-        //parent is not in the same context look further up.
-        return question_category_next_parent_in($contextid, $question_categories, $nextparent);
-    }
-}
-
-
-/**
- * Check that either category parent is 0 or a category shared in the same context.
- * Fix any categories to point to grand or grand grand parent etc in the same context or 0.
- */
-function question_category_checking($question_categories){
-    //make an array that is easier to search
-    $newparents = array();
-    foreach ($question_categories as $id => $category){
-        $newparents[$id] = question_category_next_parent_in($category->contextid, $question_categories, $id);
-    }
-    foreach (array_Keys($question_categories) as $id){
-        $question_categories[$id]->parent = $newparents[$id];
-    }
-    return $question_categories;
-}
-
-function question_upgrade_context_etc(){
-    global $CFG;
-    $result = true;
-    $result = $result && question_delete_unused_random();
-
-    $question_categories = get_records('question_categories');
-    if ($question_categories){
-        //prepare content for new db structure
-        $tofix = question_cwqpfs_to_update($question_categories);
-        foreach ($tofix as $catid => $publish){
-            $question_categories[$catid]->publish = $publish;
-        }
-
-        foreach ($question_categories as $id => $question_category){
-            $course = $question_categories[$id]->course;
-            unset($question_categories[$id]->course);
-            if ($question_categories[$id]->publish){
-                $context = get_context_instance(CONTEXT_SYSTEM);
-                //new name with old course name in brackets
-                $coursename = get_field('course', 'shortname', 'id', $course);
-                $question_categories[$id]->name .= " ($coursename)";
-            } else {
-                $context = get_context_instance(CONTEXT_COURSE, $course);
-            }
-            $question_categories[$id]->contextid = $context->id;
-            unset($question_categories[$id]->publish);
-
-        }
-
-        $question_categories = question_category_checking($question_categories);
-    }
-
-/// Define index course (not unique) to be dropped form question_categories
-    $table = new XMLDBTable('question_categories');
-    $index = new XMLDBIndex('course');
-    $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
-
-/// Launch drop index course
-    $result = $result && drop_index($table, $index);
-
-/// Define field course to be dropped from question_categories
-    $field = new XMLDBField('course');
-
-/// Launch drop field course
-    $result = $result && drop_field($table, $field);
-
-/// Define field context to be added to question_categories
-    $field = new XMLDBField('contextid');
-    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'name');
-    $field->comment = 'context that this category is shared in';
-
-/// Launch add field context
-    $result = $result && add_field($table, $field);
-
-/// Define index context (not unique) to be added to question_categories
-    $index = new XMLDBIndex('contextid');
-    $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid'));
-    $index->comment = 'links to context table';
-
-/// Launch add index context
-    $result = $result && add_index($table, $index);
-
-    $field = new XMLDBField('publish');
-
-/// Launch drop field publish
-    $result = $result && drop_field($table, $field);
-
-
-    /// update table contents with previously calculated new contents.
-    if ($question_categories){
-        foreach ($question_categories as $question_category) {
-            $question_category->name = addslashes($question_category->name);
-            $question_category->info = addslashes($question_category->info);
-            if (!$result = update_record('question_categories', $question_category)){
-                notify('Couldn\'t update question_categories "'. $question_category->name .'"!');
-            }
-        }
-    }
-
-/// Define field timecreated to be added to question
-    $table = new XMLDBTable('question');
-    $field = new XMLDBField('timecreated');
-    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'hidden');
-
-/// Launch add field timecreated
-    $result = $result && add_field($table, $field);
-
-/// Define field timemodified to be added to question
-    $table = new XMLDBTable('question');
-    $field = new XMLDBField('timemodified');
-    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timecreated');
-
-/// Launch add field timemodified
-    $result = $result && add_field($table, $field);
-
-/// Define field createdby to be added to question
-    $table = new XMLDBTable('question');
-    $field = new XMLDBField('createdby');
-    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'timemodified');
-
-/// Launch add field createdby
-    $result = $result && add_field($table, $field);
-
-/// Define field modifiedby to be added to question
-    $table = new XMLDBTable('question');
-    $field = new XMLDBField('modifiedby');
-    $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'createdby');
-
-/// Launch add field modifiedby
-    $result = $result && add_field($table, $field);
-
-/// Define key createdby (foreign) to be added to question
-    $table = new XMLDBTable('question');
-    $key = new XMLDBKey('createdby');
-    $key->setAttributes(XMLDB_KEY_FOREIGN, array('createdby'), 'user', array('id'));
-
-/// Launch add key createdby
-    $result = $result && add_key($table, $key);
-
-/// Define key modifiedby (foreign) to be added to question
-    $table = new XMLDBTable('question');
-    $key = new XMLDBKey('modifiedby');
-    $key->setAttributes(XMLDB_KEY_FOREIGN, array('modifiedby'), 'user', array('id'));
-
-/// Launch add key modifiedby
-    $result = $result && add_key($table, $key);
-
-    return $result;
-}
-
 /**
  * In Moodle, all random questions should have question.parent set to be the same
  * as question.id. One effect of MDL-5482 is that this will not be true for questions that