Commit 795a08ad authored by skodak's avatar skodak
Browse files

MDL-17458 upgrade logging implemented + a lot more refactoring + exceptions...

MDL-17458 upgrade logging implemented + a lot more refactoring + exceptions implemented in install/upgrade code + lang pack cleanup + some more improvements
parent 9c421fab
...@@ -1119,8 +1119,6 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) { ...@@ -1119,8 +1119,6 @@ if ( file_exists(dirname(dirname(__FILE__)) . '/config.php')) {
// create default course category // create default course category
$cat = get_course_category(); $cat = get_course_category();
} else {
print_error('cannotsetupsite', 'error');
} }
} }
......
...@@ -130,7 +130,6 @@ ...@@ -130,7 +130,6 @@
} }
$strdatabasesetup = get_string("databasesetup"); $strdatabasesetup = get_string("databasesetup");
$strdatabasesuccess = get_string("databasesuccess");
$navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc'))); $navigation = build_navigation(array(array('name'=>$strdatabasesetup, 'link'=>null, 'type'=>'misc')));
print_header($strdatabasesetup, $strdatabasesetup, $navigation, print_header($strdatabasesetup, $strdatabasesetup, $navigation,
...@@ -147,31 +146,31 @@ ...@@ -147,31 +146,31 @@
} }
} }
upgrade_started(true); // does not store ugprade runnign flag try {
print_heading('coresystem'); print_upgrade_part_start('moodle', true); // does not store upgrade running flag
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
/// set all core default records and default settings $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
require_once("$CFG->libdir/db/install.php"); upgrade_started(); // we want the flag to be stored in config table ;-)
xmldb_main_install();
/// store version /// set all core default records and default settings
upgrade_main_savepoint(true, $version, false); 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 /// Continue with the instalation
events_update_definition('moodle'); events_update_definition('moodle');
message_update_providers('moodle');
message_update_providers('message');
// Install core message providers /// Write default settings unconditionlly
message_update_providers('moodle'); admin_apply_default_settings(NULL, true);
message_update_providers('message');
// Write default settings unconditionally print_upgrade_part_end(null, true);
admin_apply_default_settings(NULL, true); } catch (exception $ex) {
notify($strdatabasesuccess, 'notifysuccess'); upgrade_handle_exception($ex);
print_upgrade_separator(); }
} }
...@@ -197,16 +196,9 @@ ...@@ -197,16 +196,9 @@
$CFG->debug = DEBUG_MINIMAL; $CFG->debug = DEBUG_MINIMAL;
error_reporting($CFG->debug); 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)) { if (empty($confirmupgrade)) {
$navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc'))); $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
print_header($strdatabasechecking, $stradministration, $navigation, print_header($strdatabasechecking, $stradministration, $navigation, "", "", false, "&nbsp;", "&nbsp;");
"", "", false, "&nbsp;", "&nbsp;");
notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php'); notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
print_footer('none'); print_footer('none');
...@@ -260,42 +252,36 @@ ...@@ -260,42 +252,36 @@
die(); die();
} else { } else {
/// return to original debugging level /// return to original debugging level
$CFG->debug = $origdebug; $CFG->debug = $origdebug;
error_reporting($CFG->debug); error_reporting($CFG->debug);
upgrade_started();
/// Upgrade current language pack if we can /// Upgrade current language pack if we can
if (empty($CFG->skiplangupgrade)) { if (empty($CFG->skiplangupgrade)) {
upgrade_language_pack(); upgrade_language_pack();
} }
print_heading($strdatabasechecking); /// Launch main upgrade
/// Launch the old main upgrade (if exists) try {
$status = xmldb_main_upgrade($CFG->version); print_upgrade_part_start('moodle', false);
/// If successful, continue upgrading roles and setting everything properly
if ($status) {
update_capabilities('moodle');
// Update core events $result = xmldb_main_upgrade($CFG->version);
events_update_definition('moodle'); 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('moodle');
message_update_providers('message'); message_update_providers('message');
set_config("version", $version);
remove_dir($CFG->dataroot . '/cache', true); // flush cache remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify(get_string("databasesuccess"), "green");
print_upgrade_separator();
/// Main upgrade not success print_upgrade_part_end('moodle', false);
} else { } catch (Exception $ex) {
notify('Main Upgrade failed! See lib/db/upgrade.php'); upgrade_handle_exception($ex);
print_continue('index.php?confirmupgrade=1&amp;confirmrelease=1&amp;confirmplugincheck=1');
print_footer('none');
die;
} }
} }
} else if ($version < $CFG->version) { } else if ($version < $CFG->version) {
...@@ -312,19 +298,31 @@ ...@@ -312,19 +298,31 @@
/// upgrade all plugins types /// upgrade all plugins types
$plugintypes = get_plugin_types(); $plugintypes = get_plugin_types();
foreach ($plugintypes as $type=>$location) { try {
upgrade_plugins($type, $location); 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 /// Check for changes to RPC functions
if ($CFG->mnet_dispatcher_mode != 'off') { if ($CFG->mnet_dispatcher_mode != 'off') {
require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php"); try {
upgrade_RPC_functions(); // Return here afterwards 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 /// Check for local database customisations
require_once("$CFG->dirroot/lib/locallib.php"); try {
upgrade_local_db(); // Return here afterwards 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 /// indicate that this site is fully configured except the admin password
if (empty($CFG->rolesactive)) { if (empty($CFG->rolesactive)) {
......
...@@ -103,14 +103,10 @@ ...@@ -103,14 +103,10 @@
$aclrecord->mnet_host_id = $user->mnethostid; $aclrecord->mnet_host_id = $user->mnethostid;
$aclrecord->username = $user->username; $aclrecord->username = $user->username;
$aclrecord->accessctrl = $accessctrl; $aclrecord->accessctrl = $accessctrl;
if (!$DB->insert_record('mnet_sso_access_control', $aclrecord)) { $DB->insert_record('mnet_sso_access_control', $aclrecord);
print_error('dbnotinsert', 'debug', '', 'the MNET access control list');
}
} else { } else {
$aclrecord->accessctrl = $accessctrl; $aclrecord->accessctrl = $accessctrl;
if (!$DB->update_record('mnet_sso_access_control', $aclrecord)) { $DB->update_record('mnet_sso_access_control', $aclrecord);
print_error('dbnotupdate', 'debug', '', 'the MNET access control list');
}
} }
$mnethosts = $DB->get_records('mnet_host', null, 'id', 'id,wwwroot,name'); $mnethosts = $DB->get_records('mnet_host', null, 'id', 'id,wwwroot,name');
notify("MNET access control list updated: username '$user->username' from host '" notify("MNET access control list updated: username '$user->username' from host '"
......
...@@ -107,13 +107,6 @@ class block_base { ...@@ -107,13 +107,6 @@ class block_base {
$this->block_base(); $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 * Function that can be overridden to do extra cleanup before
* the database tables are deleted. (Called once per block, not per instance!) * the database tables are deleted. (Called once per block, not per instance!)
......
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
\ No newline at end of file
...@@ -795,6 +795,7 @@ $string['uploadpicture_userskipped'] = 'Skipping user $a (already has a picture) ...@@ -795,6 +795,7 @@ $string['uploadpicture_userskipped'] = 'Skipping user $a (already has a picture)
$string['uploadpicture_userupdated'] = 'Picture updated for user $a.'; $string['uploadpicture_userupdated'] = 'Picture updated for user $a.';
$string['uploadpicture_cannotsave'] = 'Cannot save picture for user $a. Check original picture file.'; $string['uploadpicture_cannotsave'] = 'Cannot save picture for user $a. Check original picture file.';
$string['updatetimezones'] = 'Update timezones'; $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['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['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>'; $string['upgradelogs'] = 'For full functionality, your old logs need to be upgraded. <a href=\"$a\">More information</a>';
......
...@@ -5,23 +5,12 @@ ...@@ -5,23 +5,12 @@
$string['authpluginnotfound'] = 'Authentication plugin $a not found.'; $string['authpluginnotfound'] = 'Authentication plugin $a not found.';
$string['blocknotexist'] = '$a block doesn\'t exist'; $string['blocknotexist'] = '$a block doesn\'t exist';
$string['cannotbenull'] = '$a cannot be null!'; $string['cannotbenull'] = '$a cannot be null!';
$string['cannotcreateadminuser'] = 'SERIOUS ERROR: Could not create admin user record !!!'; $string['cannotdowngrade'] = 'Cannot downgrade $a->plugin from $a->oldversion to $a->newversion.';
$string['cannotdowngrade'] = 'Cannot downgrade from $a->oldversion to $a->newversion.';
$string['cannotinitpage'] = 'Cannot fully initialize page: invalid $a->name id $a->id'; $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['cannotsetuptable'] = '$a tables could NOT be set up successfully!';
$string['cannotfindadmin'] = 'Could not find an admin user!'; $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['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['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['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['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'; $string['invalideventdata'] = 'Incorrect eventadata submitted: $a';
...@@ -32,8 +21,6 @@ $string['morethanonerecordinfetch'] = 'Found more than one record in fetch() !'; ...@@ -32,8 +21,6 @@ $string['morethanonerecordinfetch'] = 'Found more than one record in fetch() !';
$string['noadminrole'] = 'No admin role could be found'; $string['noadminrole'] = 'No admin role could be found';
$string['noactivityname'] = 'Page object derived from page_generic_activity but did not define $this->activityname'; $string['noactivityname'] = 'Page object derived from page_generic_activity but did not define $this->activityname';
$string['noblocks'] = 'No blocks installed!'; $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['nocate'] = 'No categories!';
$string['notables'] = 'No Tables!'; $string['notables'] = 'No Tables!';
$string['nopageclass'] = 'Imported $a but found no page classes'; $string['nopageclass'] = 'Imported $a but found no page classes';
...@@ -45,7 +32,6 @@ $string['phpvaron'] = 'The PHP server variable \'$a->name\' is not turned On - $ ...@@ -45,7 +32,6 @@ $string['phpvaron'] = 'The PHP server variable \'$a->name\' is not turned On - $
$string['sessionmissing'] = '$a object missing from session'; $string['sessionmissing'] = '$a object missing from session';
$string['siteisnotdefined'] = 'Site is not defined!'; $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['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['withoutversion'] = 'Main version.php file is missing, not readable or broken.';
$string['xmlizeunavailable'] = 'xmlize functions are not available'; $string['xmlizeunavailable'] = 'xmlize functions are not available';
......
...@@ -127,12 +127,10 @@ $string['cannotsetupblock'] = 'Blocks tables could NOT be set up successfully!'; ...@@ -127,12 +127,10 @@ $string['cannotsetupblock'] = 'Blocks tables could NOT be set up successfully!';
$string['cannotsetupcategory'] = 'Serious error! Could not set up a default course category!'; $string['cannotsetupcategory'] = 'Serious error! Could not set up a default course category!';
$string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for $a'; $string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for $a';
$string['cannotsetupcapformod'] = '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['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category $a.';
$string['cannotunzipfile'] = 'Cannot unzip file'; $string['cannotunzipfile'] = 'Cannot unzip file';
$string['cannotupgradeblock'] = 'Upgrade of blocks system failed! (Could not update version in config table.)'; $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['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['cannotupdatecategory'] = 'Could not update the category ($a)';
$string['cannotupdatecoursemodule'] = 'Could not update the course module'; $string['cannotupdatecoursemodule'] = 'Could not update the course module';
$string['cannotupdatecomment'] = 'Could not update this comment'; $string['cannotupdatecomment'] = 'Could not update this comment';
...@@ -202,6 +200,7 @@ $string['ddlxmlfileerror'] = 'XML database file errors found'; ...@@ -202,6 +200,7 @@ $string['ddlxmlfileerror'] = 'XML database file errors found';
$string['dmlreadexception'] = 'Error reading from database'; $string['dmlreadexception'] = 'Error reading from database';
$string['dmlwriteexception'] = 'Error writing to database'; $string['dmlwriteexception'] = 'Error writing to database';
$string['destinationcmnotexit'] = 'The destination course module does not exist'; $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['downloadedfilecheckfailed'] = 'Downloaded file check failed';
$string['duplicateusername'] = 'Duplicate username - skipping record'; $string['duplicateusername'] = 'Duplicate username - skipping record';
$string['duplicateparaminsql'] = 'ERROR: duplicate parameter name in query'; $string['duplicateparaminsql'] = 'ERROR: duplicate parameter name in query';
...@@ -331,7 +330,6 @@ $string['moduledoesnotexist'] = 'This module does not exist'; ...@@ -331,7 +330,6 @@ $string['moduledoesnotexist'] = 'This module does not exist';
$string['moduleinstancedoesnotexist'] = 'The instance of this module does not exist'; $string['moduleinstancedoesnotexist'] = 'The instance of this module does not exist';
$string['moduledisable'] = 'This module ($a) has been disabled for this particular course'; $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['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['mustbeteacher'] = 'You must be a teacher to look at this page';
$string['multiplerestorenotallow'] = 'Multiple restore execution not allowed!'; $string['multiplerestorenotallow'] = 'Multiple restore execution not allowed!';
$string['mustbeloggedin'] = 'You must be logged in to do this'; $string['mustbeloggedin'] = 'You must be logged in to do this';
...@@ -364,7 +362,6 @@ $string['nopermissiontolock'] = 'No permission to lock!'; ...@@ -364,7 +362,6 @@ $string['nopermissiontolock'] = 'No permission to lock!';
$string['nopermissiontomkdir'] = 'Cannot create folder. The site administrator needs to fix the file permissions'; $string['nopermissiontomkdir'] = 'Cannot create folder. The site administrator needs to fix the file permissions';
$string['nopermissiontoshow'] = 'No permission to see this!'; $string['nopermissiontoshow'] = 'No permission to see this!';
$string['nopermissiontounlock'] = 'No permission to unlock!'; $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['nopermissiontoviewpage'] = 'You are not allowed to look at this page';
$string['nopermissiontoviewletergrade'] = 'Missing permission to view letter grades'; $string['nopermissiontoviewletergrade'] = 'Missing permission to view letter grades';
$string['nopermissiontomanagegroup'] = 'You do not have the required permissions to manage groups'; $string['nopermissiontomanagegroup'] = 'You do not have the required permissions to manage groups';
...@@ -472,8 +469,6 @@ $string['usernotupdatederror'] = 'User not updated - error'; ...@@ -472,8 +469,6 @@ $string['usernotupdatederror'] = 'User not updated - error';
$string['usernotupdatednotexists'] = 'User not updated - does not exist'; $string['usernotupdatednotexists'] = 'User not updated - does not exist';
$string['userselectortoomany'] = 'user_selector got more than one selected user, even though multiselect is false.'; $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['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['upgraderunning'] = 'Site is being upgraded, please retry later.';
$string['younotteacher'] = 'You are not a teacher!'; $string['younotteacher'] = 'You are not a teacher!';
$string['wrongcall'] = 'This script is called wrongly'; $string['wrongcall'] = 'This script is called wrongly';
......
...@@ -3099,9 +3099,7 @@ function get_cached_capabilities($component='moodle') { ...@@ -3099,9 +3099,7 @@ function get_cached_capabilities($component='moodle') {
*/ */
function get_default_capabilities($legacyrole) { function get_default_capabilities($legacyrole) {
global $DB; global $DB;
if (!$allcaps = $DB->get_records('capabilities')) { $allcaps = $DB->get_records('capabilities');
print_error('nocaps', 'debug');
}
$alldefs = array(); $alldefs = array();
$defaults = array(); $defaults = array();
$components = array(); $components = array();
......
...@@ -95,7 +95,7 @@ function get_plugin_types() { ...@@ -95,7 +95,7 @@ function get_plugin_types() {
return array('mod' => 'mod', return array('mod' => 'mod',
'qtype' => 'question/type', 'qtype' => 'question/type',
'blocks' => 'blocks', 'block' => 'blocks',
'auth' => 'auth', 'auth' => 'auth',
'enrol' => 'enrol', 'enrol' => 'enrol',
'format' => 'course/format', 'format' => 'course/format',
...@@ -105,11 +105,12 @@ function get_plugin_types() { ...@@ -105,11 +105,12 @@ function get_plugin_types() {
'message' => 'message/output', 'message' => 'message/output',
'coursereport' => 'course/report', 'coursereport' => 'course/report',
'report' => $CFG->admin.'/report', 'report' => $CFG->admin.'/report',
'quizreport' => 'mod/quiz/report',
'portfolio' => 'portfolio/type', 'portfolio' => 'portfolio/type',
'trackerexport' => 'tracker/export',
'trackerimport' => 'tracker/import', // following types a very ugly hacks - we should not make exceptions like this - all plugins should be equal;
'trackerreport' => 'tracker/report', // these plugins may cause problems such as when wanting to uninstall them
'quizreport' => 'mod/quiz/report',
'assignment_type' => 'mod/assignment/type',
); );
} }
......
...@@ -18,70 +18,6 @@ define('BLOCKS_PINNED_BOTH',2); ...@@ -18,70 +18,6 @@ define('BLOCKS_PINNED_BOTH',2);
require_once($CFG->libdir.'/pagelib.php'); require_once($CFG->libdir.'/pagelib.php');
require_once($CFG->dirroot.'/course/lib.php'); // needed to solve all those: Call to undefined function: print_recent_activity() when adding Recent Activity require_once($CFG->dirroot.'/course/lib.php'); // needed to solve all those: Call to undefined function: print_recent_activity() when adding Recent Activity
// Returns false if this block is incompatible with the current version of Moodle.
function block_is_compatible($blockname) {
global $CFG;
$file = @file($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php'); // ignore errors when file does not exist
if(empty($file)) {
return NULL;
}
foreach($file as $line) {
// If you find MoodleBlock (appearing in the class declaration) it's not compatible
if(strpos($line, 'MoodleBlock')) {
return false;
}
// But if we find a { it means the class declaration is over, so it's compatible
else if(strpos($line, '{')) {
return true;
}
}
return NULL;
}
// Returns the case-sensitive name of the class' constructor function. This includes both
// PHP5- and PHP4-style constructors. If no appropriate constructor can be found, returns NULL.
// If there is no such class, returns boolean false.
function get_class_constructor($classname) {
// Caching
static $constructors = array();
if(!class_exists($classname)) {
return false;
}
// Tests indicate this doesn't hurt even in PHP5.
$classname = strtolower($classname);
// Return cached value, if exists
if(isset($constructors[$classname])) {
return $constructors[$classname];
}
// Get a list of methods. After examining several different ways of
// doing the check, (is_callable, method_exists, function_exists etc)
// it seems that this is the most reliable one.
$methods = get_class_methods($classname);
// PHP5 constructor?
if(phpversion() >= '5') {
if(in_array('__construct', $methods)) {
return $constructors[$classname] = '__construct';
}
}
// If we have PHP5 but no magic constructor, we have to lowercase the methods
$methods = array_map('strtolower', $methods);
if(in_array($classname, $methods)) {
return $constructors[$classname] = $classname;
}
return $constructors[$classname] = NULL;
}
//This function retrieves a method-defined property of a class WITHOUT instantiating an object //This function retrieves a method-defined property of a class WITHOUT instantiating an object
function block_method_result($blockname, $method, $param = NULL) { function block_method_result($blockname, $method, $param = NULL) {
if(!block_load_class($blockname)) { if(!block_load_class($blockname)) {
...@@ -1069,227 +1005,4 @@ function blocks_repopulate_page($page) { ...@@ -1069,227 +1005,4 @@ function blocks_repopulate_page($page) {
return true; return true;
} }
//This function finds all available blocks and install them
//into blocks table or do all the upgrade process if newer
function upgrade_blocks_plugins() {
global $CFG, $interactive, $DB, $SITE;
require_once($CFG->dirroot .'/blocks/moodleblock.class.php');
$updated_blocks = false;
$blocktitles = array();
$invalidblocks = array();
$validblocks = array();
$notices = array();
//Count the number of blocks in db
$blockcount = $DB->count_records('block');
//If there isn't records. This is the first install, so I remember it
$first_install = ($blockcount == 0);
if (!$blocks = get_list_of_plugins('blocks') ) {
print_error('noblocks', 'debug');
}
if (!class_exists('block_base')) {
print_error('noblockbase');
}
foreach ($blocks as $blockname) {
if ($blockname == 'NEWBLOCK') { // Someone has unzipped the template, ignore it
continue;
}
if(!block_is_compatible($blockname)) {
// This is an old-style block
//$notices[] = 'Block '. $blockname .' is not compatible with the current version of Mooodle and needs to be updated by a programmer.';
$invalidblocks[] = $blockname;
continue;
}
$fullblock = $CFG->dirroot .'/blocks/'. $blockname;
if ( is_readable($fullblock.'/block_'.$blockname.'.php')) {