Skip to content

Commit

Permalink
MDL-17427 - removed old file based logging from ugprade - going to ad…
Browse files Browse the repository at this point in the history
…d new upgrade logging later
  • Loading branch information
skodak committed Jan 11, 2009
1 parent 4d6d912 commit 3e46c66
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 98 deletions.
3 changes: 0 additions & 3 deletions admin/cliupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,12 +966,9 @@
console_write_error('Main Upgrade failed! See lib/db/upgrade.php','',false);

}
upgrade_log_finish();

} else if ($version < $CFG->version) {
upgrade_log_start();
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
upgrade_log_finish();
}
} else {
if (!set_config("version", $version)) {
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
user_accesstime_log();
}

if ($CFG->rolesactive) { // if already using roles system
if (!empty($CFG->rolesactive)) { // if already using roles system
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
Expand All @@ -79,7 +79,7 @@
}
}
} else { // if upgrading from 1.6 or below
if (is_siteadmin() && moodle_needs_upgrading()) {
if (is_siteadmin($USER->id) && moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
}
Expand Down
91 changes: 7 additions & 84 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->libdir.'/messagelib.php'); // Messagelib functions

global $upgradeloghandle, $upgradelogbuffer;

$upgradeloghandle = false;
$upgradelogbuffer = '';

define('INSECURE_DATAROOT_WARNING', 1);
define('INSECURE_DATAROOT_ERROR', 2);

Expand Down Expand Up @@ -116,7 +111,6 @@ function upgrade_db($version, $release) {
/// return to original debugging level
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
upgrade_log_start();
$DB->set_debug(true);

if (!$DB->setup_is_unicodedb()) {
Expand All @@ -127,6 +121,7 @@ function upgrade_db($version, $release) {
}

$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 ;-)

/// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
Expand Down Expand Up @@ -310,12 +305,9 @@ function upgrade_db($version, $release) {
print_footer('none');
die;
}
upgrade_log_finish();
}
} else if ($version < $CFG->version) {
upgrade_log_start();
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
upgrade_log_finish();
}

/// Updated human-readable release version if necessary
Expand Down Expand Up @@ -837,13 +829,10 @@ function upgrade_plugins($type, $dir) {
echo '<hr />';
}
} else {
upgrade_log_start();
print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$installedversion, 'newversion'=>$plugin->version));
}
}

upgrade_log_finish();

return $updated_plugins;
}

Expand Down Expand Up @@ -972,7 +961,6 @@ function upgrade_activity_modules() {
$updated_modules = true;

} else {
upgrade_log_start();
print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$currmodule->version, 'newversion'=>$module->version));
}

Expand Down Expand Up @@ -1065,8 +1053,6 @@ function upgrade_activity_modules() {
}
}

upgrade_log_finish(); // finish logging if started

return $updated_modules;
}

Expand Down Expand Up @@ -1246,7 +1232,7 @@ 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 start_upgrade() {
function upgrade_log_start() {
global $CFG, $DB;

static $started = false;
Expand All @@ -1257,89 +1243,26 @@ function start_upgrade() {
} else {
ignore_user_abort(true);
register_shutdown_function('upgrade_finished_handler');
if ($CFG->version === '' || !$DB->get_manager()->table_exists(new xmldb_table('config'))) {
// db not installed yet
$CFG->upgraderunning = time()+300;
} else {
set_config('upgraderunning', time()+300);
}
set_config('upgraderunning', time()+300);
$started = true;
}
}

/**
* Internal function - executed at the very end of each upgrade.
* Internal function - executed if upgrade interruped.
*/
function upgrade_finished_handler() {
upgrade_log_finish();
unset_config('upgraderunning');
ignore_user_abort(false);
}

/**
* Start logging of output into file (if not disabled) and
* prevent aborting and concurrent execution of upgrade script.
*
* Please note that you can not write into session variables after calling this function!
*
* This function may be called repeatedly.
*/
function upgrade_log_start() {
global $upgradeloghandle;

start_upgrade(); // make sure the upgrade is started

if ($upgradeloghandle and ($upgradeloghandle !== 'error')) {
return;
}

make_upload_directory('upgradelogs');
ob_start('upgrade_log_callback', 2); // function for logging to disk; flush each line of text ASAP
}

/**
* Terminate logging of output, flush all data.
*
* Please make sure that each upgrade_log_start() is properly terminated by
* this function or print_error().
* Indicates upgrade is finished.
*
* This function may be called repeatedly.
*/
function upgrade_log_finish() {
global $CFG, $upgradeloghandle, $upgradelogbuffer;

@ob_end_flush();
if ($upgradelogbuffer !== '') {
@fwrite($upgradeloghandle, $upgradelogbuffer);
$upgradelogbuffer = '';
}
if ($upgradeloghandle and ($upgradeloghandle !== 'error')) {
@fclose($upgradeloghandle);
$upgradeloghandle = false;
}
}

/**
* Callback function for logging into files. Not more than one file is created per minute,
* upgrade session (terminated by upgrade_log_finish()) is always stored in one file.
*
* This function must not output any characters or throw warnigns and errors!
*/
function upgrade_log_callback($string) {
global $CFG, $upgradeloghandle, $upgradelogbuffer;

if (empty($CFG->disableupgradelogging) and ($string != '') and ($upgradeloghandle !== 'error')) {
if ($upgradeloghandle or ($upgradeloghandle = @fopen($CFG->dataroot.'/upgradelogs/upg_'.date('Ymd-Hi').'.html', 'a'))) {
$upgradelogbuffer .= $string;
if (strlen($upgradelogbuffer) > 2048) { // 2kB write buffer
@fwrite($upgradeloghandle, $upgradelogbuffer);
$upgradelogbuffer = '';
}
} else {
$upgradeloghandle = 'error';
}
}
return $string;
unset_config('upgraderunning');
ignore_user_abort(false);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,6 @@ function upgrade_blocks_plugins() {
echo '<hr />';
}
} else {
upgrade_log_start();
print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$currblock->version, 'newversion'=>$block->version));
}

Expand Down Expand Up @@ -1297,7 +1296,6 @@ function upgrade_blocks_plugins() {
}

if(!empty($notices)) {
upgrade_log_start();
foreach($notices as $notice) {
notify($notice);
}
Expand All @@ -1306,8 +1304,6 @@ function upgrade_blocks_plugins() {
// Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks
if ($first_install) {
require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');

upgrade_log_start();
//Iterate over each course - there should be only site course here now
if ($courses = $DB->get_records('course')) {
foreach ($courses as $course) {
Expand All @@ -1321,8 +1317,6 @@ function upgrade_blocks_plugins() {
blocks_repopulate_page($page);
}

upgrade_log_finish();

return $updated_blocks;
}

Expand Down
3 changes: 0 additions & 3 deletions lib/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,13 @@ function upgrade_local_db($continueto) {
}

} else if ($local_version < $CFG->local_version) {
upgrade_log_start();
notify('WARNING!!! The local version you are using is OLDER than the version that made these databases!');
}

/// Capabilities
if (!update_capabilities('local')) {
print_error('cannotsetupcapformod', 'error', '', 'local');
}

upgrade_log_finish();
}

/**
Expand Down

0 comments on commit 3e46c66

Please sign in to comment.