From: tjhunt Date: Thu, 11 Sep 2008 11:01:20 +0000 (+0000) Subject: MDL-16410 Implement the delete question type functionality on the question type admin... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4b600aa005ea8460489993d22a9e241f1e1d4e22;p=moodle.git MDL-16410 Implement the delete question type functionality on the question type administration screen. --- diff --git a/admin/modules.php b/admin/modules.php index 1d3c566df5..5eedcaf508 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -138,8 +138,8 @@ } // 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 diff --git a/admin/qtypes.php b/admin/qtypes.php index 95060de8b6..7c10ea1826 100644 --- a/admin/qtypes.php +++ b/admin/qtypes.php @@ -14,112 +14,6 @@ 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&confirm=1&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 @@ -134,6 +28,7 @@ $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; @@ -146,12 +41,72 @@ } } + // 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 . '&confirm=1&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', @@ -229,7 +184,7 @@ $a = new stdClass; $a->roles = $rolelinks; $a->exceptions = '' . + $addcapability) . '#report" title = "' . get_string('showdetails', 'admin') . '">' . get_string('exceptions', 'admin') . ''; $rolelinks = get_string('roleswithexceptions', 'admin', $a) ; } diff --git a/admin/report/capability/index.php b/admin/report/capability/index.php index a61087c441..8cb7ff0af8 100644 --- a/admin/report/capability/index.php +++ b/admin/report/capability/index.php @@ -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) { diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 79b364da57..4ac976ed31 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -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 $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 MDL-11061.'; $string['cfgwwwrootslashwarning'] = 'You have defined $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 MDL-11061.'; $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
Missing: $a->missing ($a->missingpercent %%)'; $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&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 reporturl\">here and see Moodle Docs page docsurl\">here.'; $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'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 78c9fb4902..edbcfa81db 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 * diff --git a/lib/weblib.php b/lib/weblib.php index c95d71a273..06972b4f38 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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 = "".stripslashes_safe($text).""; + $output = "".stripslashes_safe($text).""; } else if ( CLI_UPGRADE ) { $output = stripslashes_safe($text); if ($size == 1) {