]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16410 Implement the delete question type functionality on the question type admin...
authortjhunt <tjhunt>
Thu, 11 Sep 2008 11:01:20 +0000 (11:01 +0000)
committertjhunt <tjhunt>
Thu, 11 Sep 2008 11:01:20 +0000 (11:01 +0000)
admin/modules.php
admin/qtypes.php
admin/report/capability/index.php
lang/en_utf8/admin.php
lib/moodlelib.php
lib/weblib.php

index 1d3c566df5649bc19ab49c5a7c1631b3b675524e..5eedcaf508c160c379001ab924d7393e815e00e5 100644 (file)
             }
 
             // And the module configuration records
-            if (!$DB->execute("DELETE FROM {config} WHERE name LIKE ?", array("{$module->name}_%"))) {
-                notify("Error occurred while deleting the $strmodulename records from the config table");
+            if (!unset_all_config_for_plugin($module->name)) {
+                notify(get_string('errordeletingconfig', 'admin', $strmodulename));
             }
 
             // cleanup the gradebook
index 95060de8b626464c5b42b7e5bbd96361179ec7da..7c10ea1826f342107be36240c9f6f589272b0895 100644 (file)
 
     admin_externalpage_setup('manageqtypes');
 
-/// If data submitted, then process and store.
-    $delete  = optional_param('delete', '', PARAM_SAFEDIR);
-    $confirm = optional_param('confirm', '', PARAM_BOOL);
-
-    if (!empty($delete) and confirm_sesskey()) {
-        // TODO
-//        admin_externalpage_print_header();
-//        print_heading($stractivities);
-//
-//        $strmodulename = get_string("modulename", "$delete");
-//
-//        if (!$confirm) {
-//            notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
-//                         "modules.php?delete=$delete&amp;confirm=1&amp;sesskey=$USER->sesskey",
-//                         "modules.php");
-//            admin_externalpage_print_footer();
-//            exit;
-//
-//        } else {  // Delete everything!!
-//
-//            if ($delete == "forum") {
-//                print_error("cannotdeleteforummudule", 'forum');
-//            }
-//
-//            if (!$module = $DB->get_record("modules", array("name"=>$delete))) {
-//                print_error('moduledoesnotexist', 'error');
-//            }
-//
-//            // OK, first delete all the relevant instances from all course sections
-//            if ($coursemods = $DB->get_records("course_modules", array("module"=>$module->id))) {
-//                foreach ($coursemods as $coursemod) {
-//                    if (! delete_mod_from_section($coursemod->id, $coursemod->section)) {
-//                        notify("Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section");
-//                    }
-//                }
-//            }
-//
-//            // delete calendar events
-//            if (!$DB->delete_records("event", array("modulename"=>$delete))) {
-//                notify("Error occurred while deleting all $strmodulename records in calendar event table");
-//            }
-//
-//            // clear course.modinfo for courses
-//            // that used this module...
-//            $sql = "UPDATE {course}
-//                       SET modinfo=''
-//                     WHERE id IN (SELECT DISTINCT course
-//                                    FROM {course_modules}
-//                                   WHERE module=?)";
-//            $DB->execute($sql, array($module->id));
-//
-//            // Now delete all the course module records
-//            if (!$DB->delete_records("course_modules", array("module"=>$module->id))) {
-//                notify("Error occurred while deleting all $strmodulename records in course_modules table");
-//            }
-//
-//            // Then delete all the logs
-//            if (!$DB->delete_records("log", array("module"=>$module->name))) {
-//                notify("Error occurred while deleting all $strmodulename records in log table");
-//            }
-//
-//            // And log_display information
-//            if (!$DB->delete_records("log_display", array("module"=>$module->name))) {
-//                notify("Error occurred while deleting all $strmodulename records in log_display table");
-//            }
-//
-//            // And the module entry itself
-//            if (!$DB->delete_records("modules", array("name"=>$module->name))) {
-//                notify("Error occurred while deleting the $strmodulename record from modules table");
-//            }
-//
-//            // And the module configuration records
-//            if (!$DB->execute("DELETE FROM {config} WHERE name LIKE ?", array("{$module->name}_%"))) {
-//                notify("Error occurred while deleting the $strmodulename records from the config table");
-//            }
-//
-//            // cleanup the gradebook
-//            require_once($CFG->libdir.'/gradelib.php');
-//            grade_uninstalled_module($module->name);
-//
-//            // Then the tables themselves
-//            drop_plugin_tables($module->name, "$CFG->dirroot/mod/$module->name/db/install.xml", false);
-//
-//            // Delete the capabilities that were defined by this module
-//            capabilities_cleanup('mod/'.$module->name);
-//
-//            // remove entent handlers and dequeue pending events
-//            events_uninstall('mod/'.$module->name);
-//
-//            // Perform any custom uninstall tasks
-//            if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) {
-//                require_once($CFG->dirroot . '/mod/' . $module->name . '/lib.php');
-//                $uninstallfunction = $module->name . '_uninstall';
-//                if (function_exists($uninstallfunction)) {
-//                    if (! $uninstallfunction() ) {
-//                        notify('Encountered a problem running uninstall function for '. $module->name.'!');
-//                    }
-//                }
-//            }
-//
-//            $a->module = $strmodulename;
-//            $a->directory = "$CFG->dirroot/mod/$delete";
-//            notice(get_string("moduledeletefiles", "", $a), "modules.php");
-//        }
-    }
-
 /// Get some data we will need.
     $counts = $DB->get_records_sql("
             SELECT qtype, COUNT(1) as numquestions, SUM(hidden) as numhidden
         $needed[$qtypename] = $counts[$qtypename]->numquestions > 0;
         $counts[$qtypename]->numquestions -= $counts[$qtypename]->numhidden;
     }
+    $needed['missingtype'] = true; // The system needs the missing question type.
     foreach ($QTYPES as $qtypename => $qtype) {
         foreach ($qtype->requires_qtypes() as $reqtype) {
             $needed[$reqtype] = true;
         }
     }
 
+    // Process any actions.
+    $delete  = optional_param('delete', '', PARAM_SAFEDIR);
+    $confirm = optional_param('confirm', '', PARAM_BOOL);
+    if (!empty($delete) and confirm_sesskey()) {
+        // Check it is OK to delete this question type.
+        if ($delete == 'missingtype') {
+            print_error('cannotdeletemissingqtype', 'admin', admin_url('qtypes.php'));
+        }
+
+        if (!isset($QTYPES[$delete])) {
+            print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $delete);
+        }
+
+        $qtypename = $QTYPES[$delete]->local_name();
+        if ($counts[$delete]->numquestions + $counts[$delete]->numhidden > 0) {
+            print_error('cannotdeleteqtypeinuse', 'admin', admin_url('qtypes.php'), $qtypename);
+        }
+
+        if ($needed[$delete] > 0) {
+            print_error('cannotdeleteqtypeneeded', 'admin', admin_url('qtypes.php'), $qtypename);
+        }
+
+        // If not yet confirmed, display a confirmation message.
+        if (!$confirm) {
+            $qytpename = $QTYPES[$delete]->local_name();
+            admin_externalpage_print_header();
+            print_heading(get_string('deleteqtypeareyousure', 'admin', $qytpename));
+            notice_yesno(get_string('deleteqtypeareyousuremessage', 'admin', $qytpename),
+                    admin_url('qtypes.php?delete=' . $delete . '&amp;confirm=1&amp;sesskey=' . sesskey()),
+                    admin_url('qtypes.php'), NULL, NULL, 'post', 'get');
+            admin_externalpage_print_footer();
+            exit;
+        }
+
+        // Do the deletion.
+        admin_externalpage_print_header();
+        print_heading(get_string('deletingqtype', 'admin', $qtypename));
+
+        // Delete any configuration records.
+        if (!unset_all_config_for_plugin('qtype_' . $delete)) {
+            notify(get_string('errordeletingconfig', 'admin', 'qtype_' . $delete));
+        }
+
+        // Then the tables themselves
+        if (!drop_plugin_tables($delete, $QTYPES[$delete]->plugin_dir() . '/db/install.xml', false)) {
+            
+        }
+
+        // Delete the capabilities that were defined by this module
+        capabilities_cleanup('qtype/' . $delete);
+
+        // Remove event handlers and dequeue pending events
+        events_uninstall('qtype/' . $delete);
+
+        $a->qtype = $qtypename;
+        $a->directory = $QTYPES[$delete]->plugin_dir();
+        print_box(get_string('qtypedeletefiles', 'admin', $a), 'generalbox', 'notice');
+        print_continue(admin_url('qtypes.php'));
+        admin_externalpage_print_footer();
+        exit;
+    }
+
 /// Print the page heading.
     admin_externalpage_print_header();
     print_heading(get_string('manageqtypes', 'admin'));
 
-/// Print the table of all modules.
-
 /// Set up the table.
     $table = new flexible_table('qtypeadmintable');
     $table->define_columns(array('questiontype', 'numquestions', 'version', 'requires',
             $a = new stdClass;
             $a->roles = $rolelinks;
             $a->exceptions = '<a href="' . admin_url('report/capability/index.php?capability=' .
-                     $addcapability) . '" title = "' . get_string('showdetails', 'admin') . '">' .
+                     $addcapability) . '#report" title = "' . get_string('showdetails', 'admin') . '">' .
                      get_string('exceptions', 'admin') . '</a>';
             $rolelinks = get_string('roleswithexceptions', 'admin', $a) ;
         }
index a61087c441d2da12a133195a3c148c1de368188e..8cb7ff0af8dde344f61fab97d9eb27d0822aa484 100644 (file)
@@ -144,7 +144,8 @@ if ($capability) {
     }
 
     // Print the report heading.
-    print_heading(get_string('reportforcapability', 'report_capability', get_capability_string($capability)));
+    print_heading(get_string('reportforcapability', 'report_capability', get_capability_string($capability)),
+            '', 2, 'main', false, 'report');
     if (count($cleanedroleids) != count($allroles)) {
         $rolenames = array();
         foreach ($cleanedroleids as $roleid) {
index 79b364da577238309c0c94435c6e0a5e556c2fa1..4ac976ed3166d1d340b39ba7c47bbd4c3ce55de9 100644 (file)
@@ -23,6 +23,7 @@ $string['authsettings'] = 'Manage authentication';
 $string['autolang'] = 'Language autodetect';
 $string['autologinguests'] = 'Auto-login guests';
 $string['availablelangs'] = 'Available language packs';
+$string['availableto'] = 'Available to';
 $string['backgroundcolour'] = 'Transparent colour';
 $string['backups'] = 'Backups';
 $string['badwordsconfig'] = 'Enter your list of bad words separated by commas.';
@@ -41,6 +42,12 @@ $string['cachetext'] = 'Text cache lifetime';
 $string['cachetype'] = 'Cache Type';
 $string['calendar_weekend'] = 'Weekend Days';
 $string['calendarsettings'] = 'Calendar';
+$string['cannotdeletemissingqtype'] = 'You cannot delete the missing question type. It is needed by the system.';
+$string['cannotdeleteqtypeinuse'] = 'You cannot delete the question type \'$a\'. There are questions of this type in the question bank.';
+$string['cannotdeleteqtypeneeded'] = 'You cannot delete the question type \'$a\'. There are other question types installed that rely on it.';
+$string['deletingqtype'] = 'Deleting question type \'$a\'';
+$string['deleteqtypeareyousure'] = 'Are you sure you want to delete the question type \'$a\'';
+$string['deleteqtypeareyousuremessage'] = 'You are about to completely delete the question type \'$a\'. Are you sure you want to uninstall it?';
 $string['cfgwwwrootwarning'] = 'You have defined &#36;CFG->wwwroot incorrectly in your config.php file. It does not match the URL you are using to access this page. Please correct it, or you will experience strange bugs like <a href=\'http://tracker.moodle.org/browse/MDL-11061\'>MDL-11061</a>.';
 $string['cfgwwwrootslashwarning'] = 'You have defined &#36;CFG->wwwroot incorrectly in your config.php file. You have included a \'/\' character at the end. Please remove it, or you will experience strange bugs like <a href=\'http://tracker.moodle.org/browse/MDL-11061\'>MDL-11061</a>.';
 $string['change'] = 'change';
@@ -358,9 +365,11 @@ $string['environmentrequirecustomcheck'] = 'this test must pass';
 $string['environmentrequireinstall'] = 'must be installed and enabled';
 $string['environmentrequireversion'] = 'version $a->needed is required and you are running $a->current';
 $string['environmentxmlerror'] = 'Error reading environment data ($a->error_code)';
+$string['errordeletingconfig'] = 'An error occurred while deleting the configuration records for plugin \'$a\'.';
 $string['errors'] = 'Errors';
 $string['errorsetting'] = 'Could not save setting:';
 $string['errorwithsettings'] = 'Some settings were not changed due to an error.';
+$string['exceptions'] = 'exceptions';
 $string['experimental'] = 'Experimental';
 $string['experimentalsettings'] = 'Experimental settings';
 $string['extendedusernamechars'] = 'Allow extended characters in usernames';
@@ -476,6 +485,7 @@ $string['mailnewline'] = 'Newline characters in mail';
 $string['maintfileopenerror'] = 'Error opening maintenance files!';
 $string['maintinprogress'] = 'Maintenance is in progress...';
 $string['managelang'] = 'Manage';
+$string['manageqtypes'] = 'Manage question types';
 $string['maintenancemode'] = 'In Maintenance Mode';
 $string['maxbytes'] = 'Maximum uploaded file size';
 $string['maxeditingtime'] = 'Maximum time to edit posts';
@@ -516,6 +526,7 @@ $string['mysql416bypassed'] = 'However, if your site is using iso-8859-1 (latin)
 $string['mysql416required'] = 'MySQL 4.1.16 is the minimum version required for Moodle 1.6 in order to guarantee that all data can be converted to UTF-8 in the future.';
 $string['nobookmarksforuser'] = 'You do not have any bookmarks.';
 $string['nochanges'] = 'No changes';
+$string['nodatabase'] = 'No database';
 $string['nodefaultuserrolelists'] = 'Don\'t return all default role users';
 $string['nolangupdateneeded'] = 'All your language packs are up to date, no update is needed';
 $string['nomissingstrings'] = 'No missing strings';
@@ -524,12 +535,15 @@ $string['nonexistentbookmark'] = 'The bookmark you requested does not exist.';
 $string['nonmetacoursesyncroleids'] = 'Roles that are not synchronised to metacourses';
 $string['noreplyaddress'] = 'No-reply address';
 $string['noresults'] = 'No results found.';
+$string['noroles'] = 'No roles';
 $string['notifications'] = 'Notifications';
 $string['notifyloginfailures'] = 'Email login failures to';
 $string['notifyloginthreshold'] = 'Threshold for email notifications';
 $string['notloggedinroleid'] = 'Role for visitors';
 $string['numberofstrings'] = 'Total number of strings: $a->strings<br />Missing: $a->missing ($a->missingpercent&nbsp;%%)';
 $string['numberofmissingstrings'] = 'Number of missing strings: $a';
+$string['numquestions'] = 'No. questions';
+$string['numquestionsandhidden'] = '$a->numquestions (+$a->numhidden hidden)';
 $string['opensslrecommended'] = 'Installing the optional OpenSSL library is highly recommended -- it enables Moodle Networking functionality.';
 $string['opentogoogle'] = 'Open to Google';
 $string['optionalmaintenancemessage'] = 'Optional maintenance message';
@@ -614,12 +628,15 @@ $string['proxyport'] = 'Proxy port';
 $string['proxypassword'] = 'Proxy password';
 $string['proxyuser'] = 'Proxy username';
 $string['proxytype'] = 'Proxy type';
+$string['qtypedeletefiles'] = 'All data associated with the question type \'$a->qtype\' has been deleted from the database. To complete the deletion (and to prevent the question type from re-installing itself), you should now delete this directory from your server: $a->directory';
 $string['qtyperqpwillberemoved'] = 'During the upgrade, the RQP question type will be removed. You were not using this question type, so you should not experience any problems.';
 $string['qtyperqpwillberemovedanyway'] = 'During the upgrade, the RQP question type will be removed. You have some RQP questions in your database, and these will stop working unless you reinstall the code from http://moodle.org/mod/data/view.php?d=13&amp;rid=797 before continuing with the upgrade.';
 $string['quarantinedir'] = 'Quarantine directory';
 $string['question'] = 'Question';
 $string['questioncwqpfscheck'] = 'One or more \'random\' questions in a quiz are set up to select questions from a mixture of shared and unshared question categories. There is a more detailed report <a href=\"$a->reporturl\">here</a> and see Moodle Docs page <a href=\"$a->docsurl\">here</a>.';
 $string['questioncwqpfsok'] = 'Good. There are no \'random\' questions in your quizzes that are set up to select questions from a mixture of shared and unshared question categories.';
+$string['questiontype'] = 'Question type';
+$string['questiontypes'] = 'Question types';
 $string['rcache'] = 'Record cache';
 $string['rcachettl'] = 'Record cache TTL';
 $string['recaptchapublickey'] = 'ReCAPTCHA public key';
@@ -628,6 +645,7 @@ $string['releasenoteslink'] = 'For information about this version of Moodle, ple
 $string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.';
 $string['renameerrors'] = 'Rename errors';
 $string['requiredtemplate'] = 'Required. You may use template syntax here (%%l = lastname, %%f = firstname, %%u = username). See help for details and examples.';
+$string['requires'] = 'Requires';
 $string['restrictbydefault'] = 'Restrict modules by default';
 $string['restrictmodulesfor'] = 'Restrict modules for';
 $string['riskconfig'] = 'Users could change site configuration and behaviour';
@@ -640,6 +658,7 @@ $string['riskspam'] = 'Users could send spam to site users or others';
 $string['riskspamshort'] = 'Spam risk';
 $string['riskxss'] = 'Users could add files and texts that allow cross-site scripting (XSS)';
 $string['riskxssshort'] = 'XSS risk';
+$string['roleswithexceptions'] = '$a->roles, with $a->exceptions';
 $string['rowpreviewnum'] = 'Preview rows';
 $string['rssglobaldisabled'] = 'Disabled at server level';
 $string['runclamavonupload'] = 'Use clam AV on uploaded files';
@@ -659,6 +678,7 @@ $string['sessioncookiepath'] = 'Cookie path';
 $string['sessionhandling'] = 'Session Handling';
 $string['sessiontimeout'] = 'Timeout';
 $string['showblocksonmodpages'] = 'Show blocks on module pages';
+$string['showdetails'] = 'Show details';
 $string['simpletest'] = 'Unit tests';
 $string['dbtest'] = 'Functional DB tests';
 $string['sitelangchanged'] = 'Site language setting changed successfully';
index 78c9fb490228623f8715047515adfb33a9262fc9..edbcfa81db16c680ae2531683fcec107b7ab5b0d 100644 (file)
@@ -775,20 +775,33 @@ function get_config($plugin=NULL, $name=NULL) {
  * @param string $name the key to set
  * @param string $plugin (optional) the plugin scope
  * @uses $CFG
- * @return bool
+ * @return boolean whether the operation succeeded.
  */
 function unset_config($name, $plugin=NULL) {
     global $CFG, $DB;
 
-    unset($CFG->$name);
-
     if (empty($plugin)) {
+        unset($CFG->$name);
         return $DB->delete_records('config', array('name'=>$name));
     } else {
         return $DB->delete_records('config_plugins', array('name'=>$name, 'plugin'=>$plugin));
     }
 }
 
+/**
+ * Remove all the config variables for a given plugin.
+ *
+ * @param string $plugin a plugin, for example 'quiz' or 'qtype_multichoice';
+ * @return boolean whether the operation succeeded.
+ */
+function unset_all_config_for_plugin($plugin) {
+    global $DB;
+    $success = true;
+    $success = $success && $DB->delete_records('config_plugins', array('plugin' => $plugin));
+    $success = $success && $DB->delete_records_select('config', 'name LIKE ?', array($plugin . '_%'));
+    return $success;
+}
+
 /**
  * Get volatile flags
  *
index c95d71a2735b24e7998dc8aacfd13a0e1274f5a0..06972b4f38fdca345b13dbb586343e41b0654c9e 100644 (file)
@@ -3812,7 +3812,7 @@ function print_headline($text, $size=2, $return=false) {
  * @param string $align The alignment of the printed paragraph of text
  * @param int $size The size to set the font for text display.
  */
-function print_heading($text, $align='', $size=2, $class='main', $return=false) {
+function print_heading($text, $align='', $size=2, $class='main', $return=false, $id='') {
     global $verbose;
     if ($align) {
         $align = ' style="text-align:'.$align.';"';
@@ -3820,8 +3820,11 @@ function print_heading($text, $align='', $size=2, $class='main', $return=false)
     if ($class) {
         $class = ' class="'.$class.'"';
     }
+    if ($id) {
+        $id = ' id="'.$id.'"';
+    }
     if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
-    $output = "<h$size $align $class>".stripslashes_safe($text)."</h$size>";
+    $output = "<h$size $align $class $id>".stripslashes_safe($text)."</h$size>";
     } else if ( CLI_UPGRADE ) {
         $output = stripslashes_safe($text);
         if ($size == 1) {