Commit ead29342 authored by gustav_delius's avatar gustav_delius
Browse files

Questiontypes are doing their own database upgrade now.

I modified the enrollment plugin mechanism to work for any type of plugin
parent ea889e77
......@@ -239,6 +239,9 @@
redirect("config.php");
}
/// Check all questiontype plugins and upgrade if necessary
upgrade_plugins('qtype', 'question/questiontypes', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
/// Find and check all main modules and load them up or upgrade them if necessary
upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
......@@ -254,7 +257,7 @@
upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
/// Check all enrolment plugins and upgrade if necessary
upgrade_enrol_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
/// Check for local database customisations
require_once("$CFG->dirroot/lib/locallib.php");
......
......@@ -2,7 +2,7 @@
// MySQL commands for upgrading this enrolment module
function authorize_upgrade($oldversion=0) {
function enrol_authorize_upgrade($oldversion=0) {
global $CFG, $THEME, $db;
require_once("$CFG->dirroot/enrol/authorize/const.php");
......
......@@ -2,7 +2,7 @@
// PostgreSQL commands for upgrading this enrolment module
function authorize_upgrade($oldversion=0) {
function enrol_authorize_upgrade($oldversion=0) {
global $CFG, $THEME, $db;
require_once("$CFG->dirroot/enrol/authorize/const.php");
......
<?PHP // $Id$
$module->version = 2006021500;
$module->requires = 2005072200;
$plugin->version = 2006021500;
$plugin->requires = 2005072200;
?>
......@@ -2,7 +2,7 @@
// MySQL commands for upgrading this enrolment module
function paypal_upgrade($oldversion=0) {
function enrol_paypal_upgrade($oldversion=0) {
global $CFG, $THEME, $db;
......
......@@ -2,7 +2,7 @@
// PostgreSQL commands for upgrading this enrolment module
function paypal_upgrade($oldversion=0) {
function enrol_paypal_upgrade($oldversion=0) {
global $CFG, $THEME, $db;
......
......@@ -5,8 +5,8 @@
/// This fragment is called by admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2004081800; // This module's version
$plugin->version = 2004081800; // This module's version
$module->requires = 2004081800; // Requires this Moodle version
$plugin->requires = 2004081800; // Requires this Moodle version
?>
......@@ -44,6 +44,7 @@ $string['notavailable'] = 'That is not currently available';
$string['onlyeditown'] = 'You can only edit your own information';
$string['onlyeditingteachers'] = 'Only editing teachers can do that.';
$string['onlyadmins'] = 'Only administrators can do that.';
$string['pluginrequirementsnotmet'] = 'Plugin \"$a->pluginname\" ($a->pluginversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
$string['processingstops'] = 'Processing stops here. Remaining records ignored.';
$string['remotedownloadnotallowed'] = 'Download of components to your server isn\'t allowed (allow_url_fopen is disabled).<br /><br />You must download the <a href=\"$a->url\">$a->url</a> file manually, copy it to \"$a->dest\" in your server and unzip it there.';
$string['restricteduser'] = 'Sorry, but your current account \"$a\" is restricted from doing that.';
......
......@@ -991,6 +991,7 @@ $string['periodending'] = 'Period ending ($a)';
$string['personalprofile'] = 'Personal profile';
$string['phone'] = 'Phone';
$string['phpinfo'] = 'PHP info';
$string['pluginsetup'] = 'Setting up plugin tables';
$string['policyagree'] = 'You must agree to this policy to continue using this site. Do you agree?';
$string['policyagreement'] = 'Site Policy Agreement';
$string['policyagreementclick'] = 'Click here to read the Site Policy Agreement';
......
......@@ -11,93 +11,92 @@
*/
/**
* upgrade_enrol_plugins
*
* long description
* Upgrade plugins
*
* @uses $db
* @uses $CFG
* @param string $return The url to prompt the user to continue to
* @todo Finish documenting this function
* @param string $type The type of plugins that should be updated (e.g. 'enrol', 'qtype')
* @param string $dir The directory where the plugins are located (e.g. 'question/questiontypes')
* @param string $return The url to prompt the user to continue to
*/
function upgrade_enrol_plugins($return) {
function upgrade_plugins($type, $dir, $return) {
global $CFG, $db;
if (!$mods = get_list_of_plugins('enrol') ) {
error('No modules installed!');
if (!$plugs = get_list_of_plugins($dir) ) {
error('No '.$type.' plugins installed!');
}
foreach ($mods as $mod) {
foreach ($plugs as $plug) {
$fullmod = $CFG->dirroot .'/enrol/'. $mod;
$fullplug = $CFG->dirroot .'/'.$dir.'/'. $plug;
unset($module);
unset($plugin);
if ( is_readable($fullmod .'/version.php')) {
include_once($fullmod .'/version.php'); // defines $module with version etc
if ( is_readable($fullplug .'/version.php')) {
include_once($fullplug .'/version.php'); // defines $plugin with version etc
} else {
continue; // Nothing to do.
}
if ( is_readable($fullmod .'/db/'. $CFG->dbtype .'.php')) {
include_once($fullmod .'/db/'. $CFG->dbtype .'.php'); // defines upgrading function
if ( is_readable($fullplug .'/db/'. $CFG->dbtype .'.php')) {
include_once($fullplug .'/db/'. $CFG->dbtype .'.php'); // defines upgrading function
} else {
continue;
}
if (!isset($module)) {
if (!isset($plugin)) {
continue;
}
if (!empty($module->requires)) {
if ($module->requires > $CFG->version) {
$info->modulename = $mod;
$info->moduleversion = $module->version;
if (!empty($plugin->requires)) {
if ($plugin->requires > $CFG->version) {
$info->pluginname = $plug;
$info->pluginversion = $plugin->version;
$info->currentmoodle = $CFG->version;
$info->requiremoodle = $module->requires;
notify(get_string('modulerequirementsnotmet', 'error', $info));
$info->requiremoodle = $plugin->requires;
notify(get_string('pluginrequirementsnotmet', 'error', $info));
unset($info);
continue;
}
}
$module->name = $mod; // The name MUST match the directory
$plugin->name = $plug; // The name MUST match the directory
$moduleversion = 'enrol_'.$mod.'_version';
$pluginversion = $type.'_'.$plug.'_version';
if (!isset($CFG->$moduleversion)) {
set_config($moduleversion, 0);
if (!isset($CFG->$pluginversion)) {
set_config($pluginversion, 0);
}
if ($CFG->$moduleversion == $module->version) {
if ($CFG->$pluginversion == $plugin->version) {
// do nothing
} else if ($CFG->$moduleversion < $module->version) {
if (empty($updated_modules)) {
$strmodulesetup = get_string('modulesetup');
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '', '', false, '&nbsp;', '&nbsp;');
} else if ($CFG->$pluginversion < $plugin->version) {
if (empty($updated_plugins)) {
$strpluginsetup = get_string('pluginsetup');
print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '', '', false, '&nbsp;', '&nbsp;');
}
print_heading($module->name .' module needs upgrading');
$upgrade_function = $module->name .'_upgrade';
print_heading($plugin->name .' plugin needs upgrading');
$upgrade_function = $type.'_'.$plugin->name .'_upgrade';
if (function_exists($upgrade_function)) {
$db->debug=true;
if ($upgrade_function($CFG->$moduleversion)) {
if ($upgrade_function($CFG->$pluginversion)) {
$db->debug=false;
// OK so far, now update the modules record
set_config($moduleversion, $module->version);
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
// OK so far, now update the plugins record
set_config($pluginversion, $plugin->version);
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
echo '<hr />';
} else {
$db->debug=false;
notify('Upgrading '. $module->name .' from '. $CFG->$moduleversion .' to '. $module->version .' FAILED!');
notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!');
}
}
$updated_modules = true;
$updated_plugins = true;
} else {
error('Version mismatch: '. $module->name .' can\'t downgrade '. $CFG->$moduleversion .' -> '. $module->version .' !');
error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !');
}
}
if (!empty($updated_modules)) {
if (!empty($updated_plugins)) {
print_continue($return);
die;
}
......
......@@ -105,25 +105,6 @@ CREATE TABLE prefix_quiz_attempts (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_calculated`
--
CREATE TABLE prefix_question_calculated (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
answer int(10) unsigned NOT NULL default '0',
tolerance varchar(20) NOT NULL default '0.0',
tolerancetype int(10) NOT NULL default '1',
correctanswerlength int(10) NOT NULL default '2',
correctanswerformat int(10) NOT NULL default '2',
PRIMARY KEY (id),
KEY question (question),
KEY answer (answer)
) TYPE=MyISAM COMMENT='Options for questions of type calculated';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_categories`
--
......@@ -175,35 +156,6 @@ CREATE TABLE prefix_question_dataset_items (
-- --------------------------------------------------------
--
-- Table structure for table `mdl_question_essay`
--
CREATE TABLE `prefix_question_essay` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`answer` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Options for essay questions';
-- --------------------------------------------------------
--
-- Table structure for table `mdl_question_essay_states`
--
CREATE TABLE `prefix_question_essay_states` (
`id` int(10) unsigned NOT NULL auto_increment,
`stateid` int(10) unsigned NOT NULL default '0',
`graded` tinyint(4) unsigned NOT NULL default '0',
`fraction` float NOT NULL default '0',
`response` text NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='essay question type specific state information';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_quiz_grades`
--
......@@ -221,68 +173,6 @@ CREATE TABLE prefix_quiz_grades (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_match`
--
CREATE TABLE prefix_question_match (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
subquestions varchar(255) NOT NULL default '',
shuffleanswers tinyint(4) NOT NULL default '1',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Defines fixed matching questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_match_sub`
--
CREATE TABLE prefix_question_match_sub (
id int(10) unsigned NOT NULL auto_increment,
code int(10) unsigned NOT NULL default '0',
question int(10) unsigned NOT NULL default '0',
questiontext text NOT NULL default '',
answertext varchar(255) NOT NULL default '',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Defines the subquestions that make up a matching question';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_multianswer`
--
CREATE TABLE prefix_question_multianswer (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
sequence text NOT NULL default '',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for multianswer questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_multichoice`
--
CREATE TABLE prefix_question_multichoice (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
layout tinyint(4) NOT NULL default '0',
answers varchar(255) NOT NULL default '',
single tinyint(4) NOT NULL default '0',
shuffleanswers tinyint(4) NOT NULL default '1',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for multiple choice questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_sessions`
--
......@@ -300,22 +190,6 @@ CREATE TABLE prefix_question_sessions (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_numerical`
--
CREATE TABLE prefix_question_numerical (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
answer int(10) unsigned NOT NULL default '0',
tolerance varchar(255) NOT NULL default '0.0',
PRIMARY KEY (id),
KEY answer (answer),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for numerical questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_numerical_units`
--
......@@ -403,97 +277,6 @@ CREATE TABLE prefix_question (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_randomsamatch`
--
CREATE TABLE prefix_question_randomsamatch (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
choose int(10) unsigned NOT NULL default '4',
shuffleanswers tinyint(4) NOT NULL default '1',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Info about a random short-answer matching question';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_rqp`
--
CREATE TABLE prefix_question_rqp (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
type int(10) unsigned NOT NULL default '0',
source longblob NOT NULL default '',
format varchar(255) NOT NULL default '',
flags tinyint(3) unsigned NOT NULL default '0',
maxscore int(10) unsigned NOT NULL default '1',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for RQP questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_rqp_servers`
--
CREATE TABLE prefix_question_rqp_servers (
id int(10) unsigned NOT NULL auto_increment,
typeid int(10) unsigned NOT NULL default '0',
url varchar(255) NOT NULL default '',
can_render tinyint(2) unsigned NOT NULL default '0',
can_author tinyint(2) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='Information about RQP servers';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_rqp_states`
--
CREATE TABLE prefix_question_rqp_states (
id int(10) unsigned NOT NULL auto_increment,
stateid int(10) unsigned NOT NULL default '0',
responses text NOT NULL default '',
persistent_data text NOT NULL default '',
template_vars text NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='RQP question type specific state information';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_rqp_types`
--
CREATE TABLE prefix_question_rqp_types (
id int(10) unsigned NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY name (name)
) TYPE=MyISAM COMMENT='RQP question types';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_shortanswer`
--
CREATE TABLE prefix_question_shortanswer (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
answers varchar(255) NOT NULL default '',
usecase tinyint(2) NOT NULL default '0',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for short answer questions';
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_states`
--
......@@ -517,18 +300,6 @@ CREATE TABLE prefix_question_states (
-- --------------------------------------------------------
--
-- Table structure for table `prefix_question_truefalse`
--
CREATE TABLE prefix_question_truefalse (
id int(10) unsigned NOT NULL auto_increment,
question int(10) unsigned NOT NULL default '0',
trueanswer int(10) unsigned NOT NULL default '0',
falseanswer int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
KEY question (question)
) TYPE=MyISAM COMMENT='Options for True-False questions';
INSERT INTO prefix_log_display VALUES ('quiz', 'add', 'quiz', 'name');
INSERT INTO prefix_log_display VALUES ('quiz', 'update', 'quiz', 'name');
......
......@@ -99,25 +99,6 @@ CREATE INDEX prefix_quiz_attempts_quiz_idx ON prefix_quiz_attempts (quiz);
CREATE INDEX prefix_quiz_attempts_userid_idx ON prefix_quiz_attempts (userid);
CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);
# --------------------------------------------------------
#
# Table structure for table prefix_question_calculated
#
CREATE TABLE prefix_question_calculated (
id SERIAL8 PRIMARY KEY,
question INT8 NOT NULL default '0',
answer INT8 NOT NULL default '0',
tolerance varchar(20) NOT NULL default '0.0',
tolerancetype INT8 NOT NULL default '1',
correctanswerlength INT8 NOT NULL default '2',
correctanswerformat INT8 NOT NULL default '2'
);
CREATE INDEX prefix_question_calculated_question_idx ON prefix_question_calculated (question);
CREATE INDEX prefix_question_calculated_answer_idx ON prefix_question_calculated (answer);
# --------------------------------------------------------
#
......@@ -170,32 +151,6 @@ CREATE INDEX prefix_question_dataset_items_definition_idx ON prefix_question_da
# --------------------------------------------------------
#
# Table structure for table prefix_question_essay
#
CREATE TABLE mdl_question_essay (
id serial NOT NULL,
question integer NOT NULL DEFAULT 0,
answer varchar(255) NOT NULL DEFAULT ''
);
# --------------------------------------------------------
#
# Table structure for table prefix_question_essay_states
#
CREATE TABLE mdl_question_essay_states (
id serial NOT NULL,
stateid integer NOT NULL DEFAULT 0,
graded integer NOT NULL DEFAULT 0,
response text NOT NULL DEFAULT '',
fraction real NOT NULL DEFAULT 0
);
# --------------------------------------------------------
#
# Table structure for table prefix_quiz_grades
#
......@@ -211,68 +166,6 @@ CREATE TABLE prefix_quiz_grades (
CREATE INDEX prefix_quiz_grades_quiz_idx ON prefix_quiz_grades (quiz);
CREATE INDEX prefix_quiz_grades_userid_idx ON prefix_quiz_grades (userid);
# --------------------------------------------------------
#
# Table structure for table prefix_question_match
#
CREATE TABLE prefix_question_match (
id SERIAL PRIMARY KEY,
question integer NOT NULL default '0',
subquestions varchar(255) NOT NULL default '',
shuffleanswers integer NOT NULL default '1'
);
CREATE INDEX prefix_question_match_question_idx ON prefix_question_match (question);
# --------------------------------------------------------
#
# Table structure for table prefix_question_match_sub
#
CREATE TABLE prefix_question_match_sub (
id SERIAL PRIMARY KEY,
code integer NOT NULL default '0',
question integer NOT NULL default '0',
questiontext text NOT NULL default '',
answertext varchar(255) NOT NULL default ''
);
CREATE INDEX prefix_question_match_sub_question_idx ON prefix_question_match_sub (question);
# --------------------------------------------------------
#
# Table structure for table prefix_question_multianswer
#
CREATE TABLE prefix_question_multianswer (
id SERIAL PRIMARY KEY,
question integer NOT NULL default '0',
sequence text NOT NULL default ''
);
CREATE INDEX prefix_question_multianswer_question_idx ON prefix_question_multianswer (question);
# --------------------------------------------------------
#
# Table structure for table prefix_question_multichoice
#
CREATE TABLE prefix_question_multichoice (
id SERIAL PRIMARY KEY,