Commit 1045a007 authored by skodak's avatar skodak
Browse files

MDL-17849 sql queries not printed by default during upgrade anymore, there is...

MDL-17849 sql queries not printed by default during upgrade anymore, there is a new config.php only setting $CFG->upgradeshowsql instead
parent 5c144d60
......@@ -142,7 +142,6 @@
/// return to original debugging level
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
$DB->set_debug(true);
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
......@@ -151,8 +150,10 @@
}
}
upgrade_log_start(true); // does not store ugprade runnign flag
print_heading('coresystem');
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_log_start(); // move here because we want the flag to be stored in config table ;-)
upgrade_log_start(); // we want the flag to be stored in config table ;-)
/// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
......@@ -173,9 +174,7 @@
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
admin_apply_default_settings(NULL, true);
notify($strdatabasesuccess, 'notifysuccess');
/// do not show certificates in log ;-)
$DB->set_debug(false);
print_upgrade_separator();
}
......@@ -277,7 +276,6 @@
} else {
$strdatabasesuccess = get_string("databasesuccess");
upgrade_log_start();
/// return to original debugging level
......@@ -291,15 +289,11 @@
}
print_heading($strdatabasechecking);
$DB->set_debug(true);
/// Launch the old main upgrade (if exists)
$status = xmldb_main_upgrade($CFG->version);
$DB->set_debug(false);
/// If successful, continue upgrading roles and setting everything properly
if ($status) {
if (!update_capabilities()) {
print_error('cannotupgradecapabilities', 'debug');
}
update_capabilities();
// Update core events
events_update_definition();
......@@ -310,7 +304,8 @@
set_config("version", $version);
remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify($strdatabasesuccess, "green");
notify(get_string("databasesuccess"), "green");
print_upgrade_separator();
/// Main upgrade not success
} else {
......
......@@ -81,9 +81,6 @@ die;die;die;
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
admin_apply_default_settings(NULL, true);
/// do not show certificates in log ;-)
$DB->set_debug(false);
/// upgrade all plugins types
$upgradedplugins = false;
......
......@@ -294,16 +294,16 @@ $CFG->admin = 'admin';
// NOTE: course, category, session, user themes still require the
// respective settings to be enabled
//
// When working with production data on test servers, no emails should ever be send to real users
// $CFG->noemailever = true;
//
//=========================================================================
// 8. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
//=========================================================================
//
// When working with production data on test servers, no emails should ever be send to real users
// $CFG->noemailever = true;
//
// Specify prefix for fake unit test tables. If not specified only tests
// taht do not need fake tables will be executed.
// that do not need fake tables will be executed.
// $CFG->unittestprefix = 'tst_';
//
// special magic evil developer only wanting to edit the xmldb files manually
......@@ -312,12 +312,18 @@ $CFG->admin = 'admin';
// $CFG->xmldbdisablecommentchecking = true;
// $CFG->xmldbdisablenextprevchecking = true;
//
// special magig evil developer only wanting to edit xmldb files manually
// Special magic - evil developer only wanting to edit xmldb files manually
// AND allowing the XMLDBEditor to recostruct the prev/next elements every
// time one file is loaded and saved (Moodle).
// Uncomment this if you're lazy like Petr
// $CFG->xmldbreconstructprevnext = true;
//
//
// Since 2.0 sql queries are not shown during upgrade by default.
// Please note that this setting may produce very long upgrade page on large sites.
// $CFG->upgradeshowsql = true;
//=========================================================================
// ALL DONE! To continue installation, visit your main page with a browser
......
......@@ -1614,6 +1614,10 @@ function compact_rdefs(&$rdefs) {
function load_all_capabilities() {
global $USER, $CFG, $DIRTYCONTEXTS;
if (empty($CFG->rolesactive)) {
return;
}
$base = '/'.SYSCONTEXTID;
if (isguestuser()) {
......@@ -4728,7 +4732,7 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
// is the default role interesting? does it have
// a relevant rolecap? (we use this a lot later)
if (in_array((int)$CFG->defaultuserroleid, $roleids, true)) {
if (isset($CFG->defaultuserroleid) and in_array((int)$CFG->defaultuserroleid, $roleids, true)) {
$defaultroleinteresting = true;
} else {
$defaultroleinteresting = false;
......@@ -5993,6 +5997,11 @@ function get_dirty_contexts($time) {
*/
function mark_context_dirty($path) {
global $CFG, $DIRTYCONTEXTS;
if (empty($CFG->rolesactive)) {
return;
}
// only if it is a non-empty string
if (is_string($path) && $path !== '') {
set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
......
......@@ -390,9 +390,6 @@ function upgrade_plugins($type, $dir) {
$updated_plugins = true;
upgrade_log_start();
print_heading($dir.'/'. $plugin->name .' plugin needs upgrading');
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
@set_time_limit(0); // To allow slow databases to complete the long SQL
if ($installedversion == 0) { // It's a new install of this plugin
......@@ -402,9 +399,6 @@ function upgrade_plugins($type, $dir) {
$DB->get_manager()->install_from_xmldb_file($fullplug . '/db/install.xml'); //New method
}
$status = true;
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
/// Continue with the instalation, roles and other stuff
if ($status) {
/// OK so far, now update the plugins record
......@@ -439,17 +433,11 @@ function upgrade_plugins($type, $dir) {
$newupgrade_function = 'xmldb_' .$plugin->fullname .'_upgrade';
$newupgrade_status = true;
if ($newupgrade && function_exists($newupgrade_function)) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
$newupgrade_status = $newupgrade_function($installedversion);
} else if ($newupgrade) {
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
$fullplug . '/db/upgrade.php');
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
/// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed
/// OK so far, now update the plugins record
......@@ -466,9 +454,7 @@ function upgrade_plugins($type, $dir) {
notify('Upgrading '. $plugin->name .' from '. $installedversion .' to '. $plugin->version .' FAILED!');
}
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
echo '<hr />';
}
print_upgrade_separator();
} else {
print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$installedversion, 'newversion'=>$plugin->version));
}
......@@ -559,17 +545,11 @@ function upgrade_activity_modules() {
/// Then, the new function if exists and the old one was ok
$newupgrade_status = true;
if ($newupgrade && function_exists($newupgrade_function)) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
$newupgrade_status = $newupgrade_function($currmodule->version, $module);
} else if ($newupgrade) {
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
$mod . ': ' . $fullmod . '/db/upgrade.php');
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
/// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed
// OK so far, now update the modules record
......@@ -577,9 +557,7 @@ function upgrade_activity_modules() {
$DB->update_record('modules', $module);
remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
echo '<hr />';
}
print_upgrade_separator();
} else {
notify('Upgrading '. $module->name .' from '. $currmodule->version .' to '. $module->version .' FAILED!');
}
......@@ -604,9 +582,6 @@ function upgrade_activity_modules() {
print_heading($module->name);
$updated_modules = true;
// To avoid unnecessary output from the SQL queries in the CLI version
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
$DB->set_debug(true);
}
@set_time_limit(0); // To allow slow databases to complete the long SQL
/// Both old .sql files and new install.xml are supported
......@@ -615,9 +590,6 @@ function upgrade_activity_modules() {
$DB->get_manager()->install_from_xmldb_file($fullmod . '/db/install.xml'); //New method
$status = true;
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
/// Continue with the installation, roles and other stuff
if ($status) {
......@@ -641,9 +613,7 @@ function upgrade_activity_modules() {
}
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
echo '<hr />';
}
print_upgrade_separator();
} else {
print_error('cannotaddmodule', '', '', $module->name);
}
......@@ -852,12 +822,16 @@ function create_admin_user($user_input=NULL) {
* Marks start of upgrade, blocks any other access to site.
* The upgrade is finished at the end of script or after timeout.
*/
function upgrade_log_start() {
function upgrade_log_start($preinstall=false) {
global $CFG, $DB;
static $started = false;
if ($started) {
if ($preinstall) {
ignore_user_abort(true);
upgrade_setup_debug(true);
} else if ($started) {
upgrade_set_timeout(120);
} else {
......@@ -868,9 +842,11 @@ function upgrade_log_start() {
build_navigation(array(array('name' => $strupgrade, 'link' => null, 'type' => 'misc'))), '',
upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
}
//$DB->set_debug(true); // should be configurable soon
ignore_user_abort(true);
register_shutdown_function('upgrade_finished_handler');
upgrade_setup_debug(true);
set_config('upgraderunning', time()+300);
$started = true;
}
......@@ -889,9 +865,11 @@ function upgrade_finished_handler() {
* This function may be called repeatedly.
*/
function upgrade_log_finish($continueurl=null) {
global $CFG;
global $CFG, $DB;
if (!empty($CFG->upgraderunning)) {
unset_config('upgraderunning');
upgrade_setup_debug(false);
ignore_user_abort(false);
if ($continueurl) {
print_continue($continueurl);
......@@ -901,6 +879,29 @@ function upgrade_log_finish($continueurl=null) {
}
}
function upgrade_setup_debug($starting) {
global $CFG, $DB;
static $originaldebug = null;
if ($starting) {
if ($originaldebug === null) {
$originaldebug = $DB->get_debug();
}
if (!empty($CFG->upgradeshowsql)) {
$DB->set_debug(true);
}
} else {
$DB->set_debug($originaldebug);
}
}
function print_upgrade_separator() {
if (!CLI_SCRIPT) {
echo '<hr />';
}
}
/**
* Test if and critical warnings are present
* @return bool
......
......@@ -1183,17 +1183,11 @@ function upgrade_blocks_plugins() {
/// Then, the new function if exists and the old one was ok
$newupgrade_status = true;
if ($newupgrade && function_exists($newupgrade_function)) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
$newupgrade_status = $newupgrade_function($currblock->version, $block);
} else if ($newupgrade) {
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
$fullblock . '/db/upgrade.php');
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
/// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed
......@@ -1221,9 +1215,7 @@ function upgrade_blocks_plugins() {
} else {
notify('Upgrading block '. $block->name .' from '. $currblock->version .' to '. $block->version .' FAILED!');
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
echo '<hr />';
}
print_upgrade_separator();
} else {
print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$currblock->version, 'newversion'=>$block->version));
}
......@@ -1249,9 +1241,6 @@ function upgrade_blocks_plugins() {
$updated_blocks = true;
upgrade_log_start();
print_heading($block->name);
if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
$DB->set_debug(true);
}
@set_time_limit(0); // To allow slow databases to complete the long SQL
/// Both old .sql files and new install.xml are supported
......@@ -1259,9 +1248,6 @@ function upgrade_blocks_plugins() {
if (file_exists($fullblock . '/db/install.xml')) {
$DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
$block->id = $DB->insert_record('block', $block);
$blockobj->after_install();
$component = 'block/'.$block->name;
......@@ -1275,9 +1261,7 @@ function upgrade_blocks_plugins() {
message_update_providers($component);
notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
echo '<hr />';
}
print_upgrade_separator();
}
$blocktitles[$block->name] = $blocktitle;
......
......@@ -45,7 +45,8 @@ function xmldb_main_install($version) {
$cat = get_course_category();
$defaults = array('auth' => 'email',
$defaults = array('rolesactive' => '0', // marks fully set up system
'auth' => 'email',
'auth_pop3mailbox' => 'INBOX',
'enrol' => 'manual',
'enrol_plugins_enabled' => 'manual',
......
......@@ -37,14 +37,12 @@ function upgrade_fix_category_depths() {
FROM {course_categories} c, {course_categories} pc
WHERE c.parent=pc.id AND c.depth=0 AND pc.depth=?";
if ($rs = $DB->get_recordset_sql($sql, array($parentdepth))) {
$DB->set_debug(false);
foreach ($rs as $cat) {
$cat->depth = $parentdepth+1;
$cat->path = $cat->path.'/'.$cat->id;
$DB->update_record('course_categories', $cat);
}
$rs->close();
$DB->set_debug(false);
}
$parentdepth++;
if ($parentdepth > 100) {
......@@ -68,8 +66,6 @@ function upgrade_migrate_files_courses() {
$pbar = new progress_bar('migratecoursefiles', 500, true);
$rs = $DB->get_recordset('course');
$olddebug = $DB->get_debug();
$DB->set_debug(false); // lower debug level, there might be many files
$i = 0;
foreach ($rs as $course) {
$i++;
......@@ -78,7 +74,6 @@ function upgrade_migrate_files_courses() {
upgrade_migrate_files_course($context, '/', true);
$pbar->update($i, $count, "Migrated course files - course $i/$count.");
}
$DB->set_debug($olddebug); // reset debug level
$rs->close();
return true;
......@@ -179,8 +174,6 @@ function upgrade_migrate_files_blog() {
$pbar = new progress_bar('migrateblogfiles', 500, true);
$olddebug = $DB->get_debug();
$DB->set_debug(false); // lower debug level, there might be many files
$i = 0;
foreach ($rs as $entry) {
$i++;
......@@ -216,7 +209,6 @@ function upgrade_migrate_files_blog() {
$DB->update_record('post', $entry);
$pbar->update($i, $count, "Migrated blog attachments - $i/$count.");
}
$DB->set_debug($olddebug); // reset debug level
$rs->close();
}
......
......@@ -141,10 +141,6 @@ class database_manager {
throw new ddl_table_missing_exception($tablename);
}
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
if (is_string($field)) {
$fieldname = $field;
} else {
......@@ -157,9 +153,6 @@ class database_manager {
$exists = array_key_exists($fieldname, $columns);
/// Re-set original debug
$this->mdb->set_debug($olddbdebug);
return $exists;
}
......@@ -180,10 +173,6 @@ class database_manager {
throw new ddl_table_missing_exception($tablename);
}
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
/// Extract index columns
$indcolumns = $xmldb_index->getFields();
......@@ -197,13 +186,11 @@ class database_manager {
$diferences = array_merge(array_diff($columns, $indcolumns), array_diff($indcolumns, $columns));
/// If no diferences, we have find the index
if (empty($diferences)) {
$this->mdb->set_debug($olddbdebug);
return $indexname;
}
}
/// Arriving here, index not found
$this->mdb->set_debug($olddbdebug);
return false;
}
......@@ -243,10 +230,6 @@ class database_manager {
throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
}
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
/// Get list of check_constraints in table/field
$checks = false;
if ($objchecks = $this->generator->getCheckConstraintsFromDB($xmldb_table, $xmldb_field)) {
......@@ -258,7 +241,6 @@ class database_manager {
}
/// Arriving here, check not found
$this->mdb->set_debug($olddbdebug);
return $checks;
}
......@@ -336,13 +318,8 @@ class database_manager {
$sequencename = false;
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
$sequencename = $this->generator->getSequenceFromDB($xmldb_table);
$this->mdb->set_debug($olddbdebug);
return $sequencename;
}
......@@ -441,16 +418,9 @@ class database_manager {
*/
public function install_from_xmldb_structure($xmldb_structure) {
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
if (!$sqlarr = $this->generator->getCreateStructureSQL($xmldb_structure)) {
return; // nothing to do
}
$this->mdb->set_debug($olddbdebug);
$this->execute_sql_arr($sqlarr);
}
......
......@@ -166,10 +166,6 @@ abstract class sql_generator {
* @return boolean true/false
*/
public function table_exists($table, $temptable=false) {
/// Do this function silenty (to avoid output in install/upgrade process)
$olddbdebug = $this->mdb->get_debug();
$this->mdb->set_debug(false);
if (is_string($table)) {
$tablename = $table;
} else {
......@@ -181,9 +177,6 @@ abstract class sql_generator {
$tables = $this->mdb->get_tables();
$exists = in_array($tablename, $tables);
/// Re-set original debug
$this->mdb->set_debug($olddbdebug);
return $exists;
}
......
......@@ -134,16 +134,11 @@ function upgrade_local_db() {
upgrade_log_start();
require_once ($CFG->dirroot .'/local/db/upgrade.php');
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
xmldb_local_upgrade($CFG->local_version);
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(false);
}
set_config('local_version', $local_version);
notify(get_string('databasesuccess'), 'notifysuccess');
notify(get_string('databaseupgradelocal', '', $local_version), 'notifysuccess');
print_upgrade_separator();
return true;
......
......@@ -54,8 +54,6 @@ function xmldb_assignment_upgrade($oldversion) {
$pbar = new progress_bar('migrateassignmentfiles', 500, true);
$olddebug = $DB->get_debug();
$DB->set_debug(false); // lower debug level, there might be many files
$i = 0;
foreach ($rs as $submission) {
$i++;
......@@ -127,7 +125,6 @@ function xmldb_assignment_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment");
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment");
}
$DB->set_debug($olddebug); // reset debug level
$rs->close();
}
......
......@@ -2254,8 +2254,6 @@ function assignment_upgrade_grades() {
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = $DB->get_recordset_sql($sql)) {
// too much debug output
$prevdebug = $DB->get_debug();
$DB->set_debug(false);
$pbar = new progress_bar('assignmentupgradegrades', 500, true);
$i=0;
foreach ($rs as $assignment) {
......@@ -2264,7 +2262,6 @@ function assignment_upgrade_grades() {
assignment_update_grades($assignment);
$pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
}
$DB->set_debug($prevdebug);
$rs->close();
upgrade_set_timeout(); // reset to default timeout
}
......
......@@ -94,8 +94,6 @@ function xmldb_data_upgrade($oldversion) {
$pbar = new progress_bar('migratedatafiles', 500, true);
$olddebug = $DB->get_debug();
$DB->set_debug(false); // lower debug level, there might be very many files
$i = 0;
foreach ($rs as $content) {
$i++;
......@@ -143,7 +141,6 @@ function xmldb_data_upgrade($oldversion) {
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data");
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata");
}
$DB->set_debug($olddebug); // reset debug level
$rs->close();
}
upgrade_mod_savepoint($result, 2008091400, 'data');
......
......@@ -848,8 +848,6 @@ function data_upgrade_grades() {
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";