Skip to content

Commit

Permalink
MDL-17458 upgrade logging implemented + a lot more refactoring + exce…
Browse files Browse the repository at this point in the history
…ptions implemented in install/upgrade code + lang pack cleanup + some more improvements
  • Loading branch information
skodak committed Jan 31, 2009
1 parent 9c421fa commit 795a08a
Show file tree
Hide file tree
Showing 17 changed files with 625 additions and 740 deletions.
2 changes: 0 additions & 2 deletions admin/cliupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,6 @@
// create default course category
$cat = get_course_category();

} else {
print_error('cannotsetupsite', 'error');
}
}

Expand Down
106 changes: 52 additions & 54 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
}

$strdatabasesetup = get_string("databasesetup");
$strdatabasesuccess = get_string("databasesuccess");
$navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc')));

print_header($strdatabasesetup, $strdatabasesetup, $navigation,
Expand All @@ -147,31 +146,31 @@
}
}

upgrade_started(true); // does not store ugprade runnign flag
print_heading('coresystem');
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
try {
print_upgrade_part_start('moodle', true); // does not store upgrade running flag

/// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install();
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)

/// store version
upgrade_main_savepoint(true, $version, false);
/// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install();

/// Continue with the instalation
/// store version
upgrade_main_savepoint(true, $version, false);

// Install core event handlers
events_update_definition('moodle');
/// Continue with the instalation
events_update_definition('moodle');
message_update_providers('moodle');
message_update_providers('message');

// Install core message providers
message_update_providers('moodle');
message_update_providers('message');
/// Write default settings unconditionlly
admin_apply_default_settings(NULL, true);

// Write default settings unconditionally
admin_apply_default_settings(NULL, true);
notify($strdatabasesuccess, 'notifysuccess');
print_upgrade_separator();
print_upgrade_part_end(null, true);
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
}


Expand All @@ -197,16 +196,9 @@
$CFG->debug = DEBUG_MINIMAL;
error_reporting($CFG->debug);

// logo ut in case we are upgrading from pre 1.9 version in order to prevent
// weird session/role problems caused by incorrect data in USER and SESSION
if ($CFG->version < 2007101500) {
require_logout();
}

if (empty($confirmupgrade)) {
$navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
print_header($strdatabasechecking, $stradministration, $navigation,
"", "", false, "&nbsp;", "&nbsp;");
print_header($strdatabasechecking, $stradministration, $navigation, "", "", false, "&nbsp;", "&nbsp;");

notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
print_footer('none');
Expand Down Expand Up @@ -260,42 +252,36 @@
die();

} else {

/// return to original debugging level
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
upgrade_started();

/// Upgrade current language pack if we can
if (empty($CFG->skiplangupgrade)) {
upgrade_language_pack();
}

print_heading($strdatabasechecking);
/// Launch the old main upgrade (if exists)
$status = xmldb_main_upgrade($CFG->version);
/// If successful, continue upgrading roles and setting everything properly
if ($status) {
update_capabilities('moodle');
/// Launch main upgrade
try {
print_upgrade_part_start('moodle', false);

// Update core events
events_update_definition('moodle');
$result = xmldb_main_upgrade($CFG->version);
if ($version > $CFG->version) {
// store version if not already there
upgrade_main_savepoint($result, $version, false);
}

// Update core message providers
// perform all other component upgrade routines
update_capabilities('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
message_update_providers('message');

set_config("version", $version);
remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify(get_string("databasesuccess"), "green");
print_upgrade_separator();

/// Main upgrade not success
} else {
notify('Main Upgrade failed! See lib/db/upgrade.php');
print_continue('index.php?confirmupgrade=1&amp;confirmrelease=1&amp;confirmplugincheck=1');
print_footer('none');
die;
print_upgrade_part_end('moodle', false);
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}
} else if ($version < $CFG->version) {
Expand All @@ -312,19 +298,31 @@

/// upgrade all plugins types
$plugintypes = get_plugin_types();
foreach ($plugintypes as $type=>$location) {
upgrade_plugins($type, $location);
try {
foreach ($plugintypes as $type=>$location) {
upgrade_plugins($type, $location, 'print_upgrade_part_start', 'print_upgrade_part_end');
}
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}

/// Check for changes to RPC functions
if ($CFG->mnet_dispatcher_mode != 'off') {
require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
upgrade_RPC_functions(); // Return here afterwards
try {
require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
upgrade_RPC_functions(); // Return here afterwards
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
}

/// Check for local database customisations
require_once("$CFG->dirroot/lib/locallib.php");
upgrade_local_db(); // Return here afterwards
try {
require_once("$CFG->dirroot/lib/locallib.php");
upgrade_local_db('print_upgrade_part_start', 'print_upgrade_part_end');
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}

/// indicate that this site is fully configured except the admin password
if (empty($CFG->rolesactive)) {
Expand Down
8 changes: 2 additions & 6 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,10 @@
$aclrecord->mnet_host_id = $user->mnethostid;
$aclrecord->username = $user->username;
$aclrecord->accessctrl = $accessctrl;
if (!$DB->insert_record('mnet_sso_access_control', $aclrecord)) {
print_error('dbnotinsert', 'debug', '', 'the MNET access control list');
}
$DB->insert_record('mnet_sso_access_control', $aclrecord);
} else {
$aclrecord->accessctrl = $accessctrl;
if (!$DB->update_record('mnet_sso_access_control', $aclrecord)) {
print_error('dbnotupdate', 'debug', '', 'the MNET access control list');
}
$DB->update_record('mnet_sso_access_control', $aclrecord);
}
$mnethosts = $DB->get_records('mnet_host', null, 'id', 'id,wwwroot,name');
notify("MNET access control list updated: username '$user->username' from host '"
Expand Down
7 changes: 0 additions & 7 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ function __construct() {
$this->block_base();
}

/**
* Function that can be overridden to do extra setup after
* the database install. (Called once per block, not per instance!)
*/
function after_install() {
}

/**
* Function that can be overridden to do extra cleanup before
* the database tables are deleted. (Called once per block, not per instance!)
Expand Down
19 changes: 19 additions & 0 deletions blocks/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This files describes API changes in /blocks/* - activity modules,
information provided here is intended especially for developers.

=== 2.0 ===

required changes in code:
* use new DML syntax everywhere
* use new DDL syntax in db/upgrade.php
* replace defaults.php by settings.php and db/install.php
* replace STATEMENTS section in db/install.xml by db/install.php
* move post instalation code from install() method into db/install.php
* completely rewrite file handling
* rewrite backup/restore

optional - no changes needed in older code:
*


TODO: add links to docs
1 change: 1 addition & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@
$string['uploadpicture_userupdated'] = 'Picture updated for user $a.';
$string['uploadpicture_cannotsave'] = 'Cannot save picture for user $a. Check original picture file.';
$string['updatetimezones'] = 'Update timezones';
$string['upgradeerror'] = 'Unknown error upgrading $a->plugin to version $a->version, can not continue.';
$string['upgradeforumread'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts.<br />To use this functionality you need to <a href=\"$a\">update your tables</a>.';
$string['upgradeforumreadinfo'] = 'A new feature has been added in Moodle 1.5 to track read/unread forum posts. To use this functionality you need to update your tables with all the tracking information for existing posts. Depending on the size of your site this can take a long time (hours) and can be quite taxing on the database, so it\'s best to do it during a quiet period. However, your site will continue functioning during this upgrade and users won\'t be affected. Once you start this process you should let it finish (keep your browser window open). However, if you stop the process by closing the window: don\'t worry, you can start over.<br /><br />Do you want to start the upgrading process now?';
$string['upgradelogs'] = 'For full functionality, your old logs need to be upgraded. <a href=\"$a\">More information</a>';
Expand Down
16 changes: 1 addition & 15 deletions lang/en_utf8/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@
$string['authpluginnotfound'] = 'Authentication plugin $a not found.';
$string['blocknotexist'] = '$a block doesn\'t exist';
$string['cannotbenull'] = '$a cannot be null!';
$string['cannotcreateadminuser'] = 'SERIOUS ERROR: Could not create admin user record !!!';
$string['cannotdowngrade'] = 'Cannot downgrade from $a->oldversion to $a->newversion.';
$string['cannotdowngrade'] = 'Cannot downgrade $a->plugin from $a->oldversion to $a->newversion.';
$string['cannotinitpage'] = 'Cannot fully initialize page: invalid $a->name id $a->id';
$string['cannotupgradecapabilities'] = 'Had trouble upgrading the core capabilities for the Roles System';
$string['cannotupdateversion'] = 'Upgrade failed! (Could not update version in config table)';
$string['cannotupdaterelease'] = 'ERROR: Could not update release version in database!!';
$string['cannotsetupsite'] = 'Serious Error! Could not set up the site!';
$string['cannotsetuptable'] = '$a tables could NOT be set up successfully!';
$string['cannotfindadmin'] = 'Could not find an admin user!';
$string['cannotupgradedbcustom'] = 'Upgrade of local database customisations failed! (Could not update version in config table)';
$string['codingerror'] = 'Coding error detected, it must be fixed by a programmer: $a';
$string['configmoodle'] = 'Moodle has not been configured yet. You need to edit config.php first.';
$string['dbnotinsert'] = 'Database error - Cannot insert ($a)';
$string['dbnotupdate'] = 'Database error - Cannot update ($a)';
$string['dbnotsupport'] = 'Error: Your database ($a) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.';
$string['dbnotsetup'] = 'Error: Main databases NOT set up successfully';
$string['doesnotworkwitholdversion'] = 'This script does not work with this old version of Moodle';
$string['erroroccur'] = 'An error has occurred during this process';
$string['fixsetting'] = 'Please fix your settings in config.php: <p>You have:</p> <p>\$CFG->dirroot = \"$a->current\";</p> <p>but it should be:</p> <p>\$CFG->dirroot = \"$a->found\"</p>';
$string['invalideventdata'] = 'Incorrect eventadata submitted: $a';
Expand All @@ -32,8 +21,6 @@
$string['noadminrole'] = 'No admin role could be found';
$string['noactivityname'] = 'Page object derived from page_generic_activity but did not define $this->activityname';
$string['noblocks'] = 'No blocks installed!';
$string['noblockbase'] = 'Class block_base is not defined or file not found for /blocks/moodleblock.class.php';
$string['nocaps'] = 'Error: no capabilitites defined!';
$string['nocate'] = 'No categories!';
$string['notables'] = 'No Tables!';
$string['nopageclass'] = 'Imported $a but found no page classes';
Expand All @@ -45,7 +32,6 @@
$string['sessionmissing'] = '$a object missing from session';
$string['siteisnotdefined'] = 'Site is not defined!';
$string['sqlrelyonobsoletetable'] = 'This SQL relies on obsolete table(s): $a! Your code must be fixed by a developer.';
$string['upgradefail'] = 'Upgrade failed! see: $a';
$string['withoutversion'] = 'Main version.php file is missing, not readable or broken.';
$string['xmlizeunavailable'] = 'xmlize functions are not available';

Expand Down
7 changes: 1 addition & 6 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@
$string['cannotsetupcategory'] = 'Serious error! Could not set up a default course category!';
$string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for $a';
$string['cannotsetupcapformod'] = 'Could not set up the capabilities for $a';
$string['cannotsetupsite'] = 'Serious error! Could not set up the site!';
$string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category $a.';
$string['cannotunzipfile'] = 'Cannot unzip file';
$string['cannotupgradeblock'] = 'Upgrade of blocks system failed! (Could not update version in config table.)';
$string['cannotupgradecaps'] = 'Had difficulties upgrading the core capabilities for the Roles system';
$string['cannotupdateblock'] = 'Could not update block $a record in block table!';
$string['cannotupdatecategory'] = 'Could not update the category ($a)';
$string['cannotupdatecoursemodule'] = 'Could not update the course module';
$string['cannotupdatecomment'] = 'Could not update this comment';
Expand Down Expand Up @@ -202,6 +200,7 @@
$string['dmlreadexception'] = 'Error reading from database';
$string['dmlwriteexception'] = 'Error writing to database';
$string['destinationcmnotexit'] = 'The destination course module does not exist';
$string['detectedbrokenplugin'] = 'Plugin \"$a\" is defective, can not continue, sorry.';
$string['downloadedfilecheckfailed'] = 'Downloaded file check failed';
$string['duplicateusername'] = 'Duplicate username - skipping record';
$string['duplicateparaminsql'] = 'ERROR: duplicate parameter name in query';
Expand Down Expand Up @@ -331,7 +330,6 @@
$string['moduleinstancedoesnotexist'] = 'The instance of this module does not exist';
$string['moduledisable'] = 'This module ($a) has been disabled for this particular course';
$string['modulemissingcode'] = 'Module $a is missing the code needed to perform this function';
$string['modulerequirementsnotmet'] = 'Module \"$a->modulename\" ($a->moduleversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
$string['mustbeteacher'] = 'You must be a teacher to look at this page';
$string['multiplerestorenotallow'] = 'Multiple restore execution not allowed!';
$string['mustbeloggedin'] = 'You must be logged in to do this';
Expand Down Expand Up @@ -364,7 +362,6 @@
$string['nopermissiontomkdir'] = 'Cannot create folder. The site administrator needs to fix the file permissions';
$string['nopermissiontoshow'] = 'No permission to see this!';
$string['nopermissiontounlock'] = 'No permission to unlock!';
$string['nopermissiontoupdateblock'] = 'No permission to update $a!';
$string['nopermissiontoviewpage'] = 'You are not allowed to look at this page';
$string['nopermissiontoviewletergrade'] = 'Missing permission to view letter grades';
$string['nopermissiontomanagegroup'] = 'You do not have the required permissions to manage groups';
Expand Down Expand Up @@ -472,8 +469,6 @@
$string['usernotupdatednotexists'] = 'User not updated - does not exist';
$string['userselectortoomany'] = 'user_selector got more than one selected user, even though multiselect is false.';
$string['updatersserror'] = 'There was an error trying to update RSS feed with id: $a';
$string['upgradeversionfail'] = 'Upgrade of backup system failed! (Could not update version in config table.)';
$string['upgradefail'] = 'Upgrade failed! $a';
$string['upgraderunning'] = 'Site is being upgraded, please retry later.';
$string['younotteacher'] = 'You are not a teacher!';
$string['wrongcall'] = 'This script is called wrongly';
Expand Down
4 changes: 1 addition & 3 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3099,9 +3099,7 @@ function get_cached_capabilities($component='moodle') {
*/
function get_default_capabilities($legacyrole) {
global $DB;
if (!$allcaps = $DB->get_records('capabilities')) {
print_error('nocaps', 'debug');
}
$allcaps = $DB->get_records('capabilities');
$alldefs = array();
$defaults = array();
$components = array();
Expand Down
11 changes: 6 additions & 5 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function get_plugin_types() {

return array('mod' => 'mod',
'qtype' => 'question/type',
'blocks' => 'blocks',
'block' => 'blocks',
'auth' => 'auth',
'enrol' => 'enrol',
'format' => 'course/format',
Expand All @@ -105,11 +105,12 @@ function get_plugin_types() {
'message' => 'message/output',
'coursereport' => 'course/report',
'report' => $CFG->admin.'/report',
'quizreport' => 'mod/quiz/report',
'portfolio' => 'portfolio/type',
'trackerexport' => 'tracker/export',
'trackerimport' => 'tracker/import',
'trackerreport' => 'tracker/report',

// following types a very ugly hacks - we should not make exceptions like this - all plugins should be equal;
// these plugins may cause problems such as when wanting to uninstall them
'quizreport' => 'mod/quiz/report',
'assignment_type' => 'mod/assignment/type',
);
}

Expand Down
Loading

0 comments on commit 795a08a

Please sign in to comment.