2004-09-26 05:10:38 +00:00
|
|
|
<?php //
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* adminlib.php - Contains functions that only administrators will ever need to use
|
|
|
|
*
|
|
|
|
* @author Martin Dougiamas
|
|
|
|
* @version $Id$
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package moodlecore
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2006-03-22 10:44:54 +00:00
|
|
|
* Upgrade plugins
|
2004-09-26 05:10:38 +00:00
|
|
|
*
|
|
|
|
* @uses $db
|
|
|
|
* @uses $CFG
|
2006-03-22 10:44:54 +00:00
|
|
|
* @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
|
2004-09-26 05:10:38 +00:00
|
|
|
*/
|
2006-03-22 10:44:54 +00:00
|
|
|
function upgrade_plugins($type, $dir, $return) {
|
2004-08-24 04:58:06 +00:00
|
|
|
global $CFG, $db;
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
if (!$plugs = get_list_of_plugins($dir) ) {
|
|
|
|
error('No '.$type.' plugins installed!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-01 07:46:19 +00:00
|
|
|
$updated_plugins = false;
|
|
|
|
$strpluginsetup = get_string('pluginsetup');
|
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
foreach ($plugs as $plug) {
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
$fullplug = $CFG->dirroot .'/'.$dir.'/'. $plug;
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
unset($plugin);
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (is_readable($fullplug .'/version.php')) {
|
2006-03-22 10:44:54 +00:00
|
|
|
include_once($fullplug .'/version.php'); // defines $plugin with version etc
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
|
|
|
continue; // Nothing to do.
|
|
|
|
}
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if (is_readable($fullplug .'/db/'. $CFG->dbtype .'.php')) {
|
2006-03-22 10:44:54 +00:00
|
|
|
include_once($fullplug .'/db/'. $CFG->dbtype .'.php'); // defines upgrading function
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
if (!isset($plugin)) {
|
2004-08-19 09:37:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
if (!empty($plugin->requires)) {
|
|
|
|
if ($plugin->requires > $CFG->version) {
|
|
|
|
$info->pluginname = $plug;
|
|
|
|
$info->pluginversion = $plugin->version;
|
2004-08-19 09:37:42 +00:00
|
|
|
$info->currentmoodle = $CFG->version;
|
2006-03-22 10:44:54 +00:00
|
|
|
$info->requiremoodle = $plugin->requires;
|
2006-08-01 07:46:19 +00:00
|
|
|
if (!$updated_plugins) {
|
|
|
|
print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '',
|
|
|
|
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
|
|
|
|
false, ' ', ' ');
|
|
|
|
}
|
|
|
|
upgrade_log_start();
|
2006-03-22 10:44:54 +00:00
|
|
|
notify(get_string('pluginrequirementsnotmet', 'error', $info));
|
2006-08-01 07:46:19 +00:00
|
|
|
$updated_plugins = true;
|
2004-08-19 09:37:42 +00:00
|
|
|
unset($info);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
$plugin->name = $plug; // The name MUST match the directory
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
$pluginversion = $type.'_'.$plug.'_version';
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
if (!isset($CFG->$pluginversion)) {
|
|
|
|
set_config($pluginversion, 0);
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
2006-03-22 10:44:54 +00:00
|
|
|
if ($CFG->$pluginversion == $plugin->version) {
|
2004-08-19 09:37:42 +00:00
|
|
|
// do nothing
|
2006-03-22 10:44:54 +00:00
|
|
|
} else if ($CFG->$pluginversion < $plugin->version) {
|
2006-08-01 07:46:19 +00:00
|
|
|
if (!$updated_plugins) {
|
2006-07-13 09:48:56 +00:00
|
|
|
print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '',
|
|
|
|
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
|
|
|
|
false, ' ', ' ');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_start();
|
2006-03-22 10:44:54 +00:00
|
|
|
print_heading($plugin->name .' plugin needs upgrading');
|
2006-04-16 16:50:55 +00:00
|
|
|
if ($CFG->$pluginversion == 0) { // It's a new install of this plugin
|
|
|
|
if (file_exists($fullplug .'/db/'. $CFG->dbtype .'.sql')) {
|
|
|
|
$db->debug = true;
|
|
|
|
@set_time_limit(0); // To allow slow databases to complete the long SQL
|
|
|
|
if (modify_database($fullplug .'/db/'. $CFG->dbtype .'.sql')) {
|
|
|
|
// OK so far, now update the plugins record
|
|
|
|
set_config($pluginversion, $plugin->version);
|
2006-08-14 08:59:01 +00:00
|
|
|
if (!update_capabilities($dir.'/'.$plug)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error('Could not set up the capabilities for '.$module->name.'!');
|
|
|
|
}
|
2006-04-16 16:50:55 +00:00
|
|
|
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
|
|
|
|
} else {
|
|
|
|
notify('Installing '. $plugin->name .' FAILED!');
|
|
|
|
}
|
|
|
|
$db->debug = false;
|
|
|
|
} else { // We'll assume no tables are necessary
|
2006-03-22 10:44:54 +00:00
|
|
|
set_config($pluginversion, $plugin->version);
|
|
|
|
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
|
2006-04-16 16:50:55 +00:00
|
|
|
}
|
|
|
|
} else { // Upgrade existing install
|
|
|
|
$upgrade_function = $type.'_'.$plugin->name .'_upgrade';
|
|
|
|
if (function_exists($upgrade_function)) {
|
|
|
|
$db->debug=true;
|
|
|
|
if ($upgrade_function($CFG->$pluginversion)) {
|
|
|
|
$db->debug=false;
|
|
|
|
// OK so far, now update the plugins record
|
|
|
|
set_config($pluginversion, $plugin->version);
|
2006-08-14 08:59:01 +00:00
|
|
|
if (!update_capabilities($dir.'/'.$plug)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error('Could not update '.$plugin->name.' capabilities!');
|
|
|
|
}
|
2006-04-16 16:50:55 +00:00
|
|
|
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
|
|
|
|
} else {
|
|
|
|
$db->debug=false;
|
|
|
|
notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!');
|
|
|
|
}
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-16 16:50:55 +00:00
|
|
|
echo '<hr />';
|
2006-03-22 10:44:54 +00:00
|
|
|
$updated_plugins = true;
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_start();
|
2006-03-22 10:44:54 +00:00
|
|
|
error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_finish();
|
|
|
|
|
|
|
|
if ($updated_plugins) {
|
2004-08-19 09:37:42 +00:00
|
|
|
print_continue($return);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
/**
|
|
|
|
* Find and check all modules and load them up or upgrade them if necessary
|
|
|
|
*
|
|
|
|
* @uses $db
|
|
|
|
* @uses $CFG
|
|
|
|
* @param string $return The url to prompt the user to continue to
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
2004-08-19 09:37:42 +00:00
|
|
|
function upgrade_activity_modules($return) {
|
|
|
|
|
2004-08-24 04:58:06 +00:00
|
|
|
global $CFG, $db;
|
2004-08-19 09:37:42 +00:00
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
if (!$mods = get_list_of_plugins('mod') ) {
|
|
|
|
error('No modules installed!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-01 07:46:19 +00:00
|
|
|
$updated_modules = false;
|
|
|
|
$strmodulesetup = get_string('modulesetup');
|
|
|
|
|
2004-08-19 09:37:42 +00:00
|
|
|
foreach ($mods as $mod) {
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
|
2004-08-19 09:37:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
$fullmod = $CFG->dirroot .'/mod/'. $mod;
|
2004-08-19 09:37:42 +00:00
|
|
|
|
|
|
|
unset($module);
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
if ( is_readable($fullmod .'/version.php')) {
|
|
|
|
include_once($fullmod .'/version.php'); // defines $module with version etc
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
2004-09-26 05:10:38 +00:00
|
|
|
notify('Module '. $mod .': '. $fullmod .'/version.php was not readable');
|
2004-08-19 09:37:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
if ( is_readable($fullmod .'/db/'. $CFG->dbtype .'.php')) {
|
|
|
|
include_once($fullmod .'/db/'. $CFG->dbtype .'.php'); // defines upgrading function
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
2004-09-26 05:10:38 +00:00
|
|
|
notify('Module '. $mod .': '. $fullmod .'/db/'. $CFG->dbtype .'.php was not readable');
|
2004-08-19 09:37:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($module)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($module->requires)) {
|
|
|
|
if ($module->requires > $CFG->version) {
|
|
|
|
$info->modulename = $mod;
|
|
|
|
$info->moduleversion = $module->version;
|
|
|
|
$info->currentmoodle = $CFG->version;
|
|
|
|
$info->requiremoodle = $module->requires;
|
2006-08-01 07:46:19 +00:00
|
|
|
if (!$updated_modules) {
|
|
|
|
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
|
|
|
|
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
|
|
|
|
false, ' ', ' ');
|
|
|
|
}
|
|
|
|
upgrade_log_start();
|
2004-08-19 09:37:42 +00:00
|
|
|
notify(get_string('modulerequirementsnotmet', 'error', $info));
|
2006-08-01 07:46:19 +00:00
|
|
|
$updated_modules = true;
|
2004-08-19 09:37:42 +00:00
|
|
|
unset($info);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$module->name = $mod; // The name MUST match the directory
|
|
|
|
|
2004-09-26 05:10:38 +00:00
|
|
|
if ($currmodule = get_record('modules', 'name', $module->name)) {
|
2004-08-19 09:37:42 +00:00
|
|
|
if ($currmodule->version == $module->version) {
|
|
|
|
// do nothing
|
|
|
|
} else if ($currmodule->version < $module->version) {
|
2006-08-01 07:46:19 +00:00
|
|
|
if (!$updated_modules) {
|
2006-07-13 09:48:56 +00:00
|
|
|
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
|
|
|
|
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
|
|
|
|
false, ' ', ' ');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_start();
|
2004-09-26 05:10:38 +00:00
|
|
|
print_heading($module->name .' module needs upgrading');
|
2006-08-08 05:13:06 +00:00
|
|
|
|
|
|
|
// Run the upgrade function for the module.
|
2004-09-26 05:10:38 +00:00
|
|
|
$upgrade_function = $module->name.'_upgrade';
|
2004-08-19 09:37:42 +00:00
|
|
|
if (function_exists($upgrade_function)) {
|
|
|
|
$db->debug=true;
|
|
|
|
if ($upgrade_function($currmodule->version, $module)) {
|
|
|
|
$db->debug=false;
|
|
|
|
// OK so far, now update the modules record
|
|
|
|
$module->id = $currmodule->id;
|
2004-09-26 05:10:38 +00:00
|
|
|
if (! update_record('modules', $module)) {
|
|
|
|
error('Could not update '. $module->name .' record in modules table!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
2005-04-20 07:29:28 +00:00
|
|
|
remove_dir($CFG->dataroot . '/cache', true); // flush cache
|
2005-02-08 17:09:41 +00:00
|
|
|
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
|
2004-09-26 05:10:38 +00:00
|
|
|
echo '<hr />';
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
|
|
|
$db->debug=false;
|
2004-09-26 05:10:38 +00:00
|
|
|
notify('Upgrading '. $module->name .' from '. $currmodule->version .' to '. $module->version .' FAILED!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-08 05:13:06 +00:00
|
|
|
|
|
|
|
// Update the capabilities table?
|
|
|
|
if (!update_capabilities('mod/'.$module->name)) {
|
|
|
|
error('Could not update '.$module->name.' capabilities!');
|
|
|
|
}
|
|
|
|
|
2004-08-19 09:37:42 +00:00
|
|
|
$updated_modules = true;
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_start();
|
2004-09-26 05:10:38 +00:00
|
|
|
error('Version mismatch: '. $module->name .' can\'t downgrade '. $currmodule->version .' -> '. $module->version .' !');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else { // module not installed yet, so install it
|
2006-08-01 07:46:19 +00:00
|
|
|
if (!$updated_modules) {
|
2006-07-13 09:48:56 +00:00
|
|
|
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
|
|
|
|
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
|
|
|
|
false, ' ', ' ');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_start();
|
2004-08-19 09:37:42 +00:00
|
|
|
print_heading($module->name);
|
|
|
|
$updated_modules = true;
|
|
|
|
$db->debug = true;
|
|
|
|
@set_time_limit(0); // To allow slow databases to complete the long SQL
|
2004-09-26 05:10:38 +00:00
|
|
|
if (modify_database($fullmod .'/db/'. $CFG->dbtype .'.sql')) {
|
2004-08-19 09:37:42 +00:00
|
|
|
$db->debug = false;
|
2004-09-26 05:10:38 +00:00
|
|
|
if ($module->id = insert_record('modules', $module)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
if (!update_capabilities('mod/'.$module->name)) {
|
|
|
|
error('Could not set up the capabilities for '.$module->name.'!');
|
|
|
|
}
|
2005-02-08 17:09:41 +00:00
|
|
|
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
|
2004-09-26 05:10:38 +00:00
|
|
|
echo '<hr />';
|
2004-08-19 09:37:42 +00:00
|
|
|
} else {
|
2004-09-26 05:10:38 +00:00
|
|
|
error($module->name .' module could not be added to the module list!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-26 05:10:38 +00:00
|
|
|
error($module->name .' tables could NOT be set up successfully!');
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-15 17:28:45 +00:00
|
|
|
|
|
|
|
/// Check submodules of this module if necessary
|
|
|
|
|
|
|
|
include_once($fullmod.'/lib.php'); // defines upgrading function
|
|
|
|
|
|
|
|
$submoduleupgrade = $module->name.'_upgrade_submodules';
|
|
|
|
if (function_exists($submoduleupgrade)) {
|
|
|
|
$submoduleupgrade();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Run any defaults or final code that is necessary for this module
|
|
|
|
|
2004-12-23 07:09:33 +00:00
|
|
|
if ( is_readable($fullmod .'/defaults.php')) {
|
|
|
|
// Insert default values for any important configuration variables
|
2004-12-23 09:07:43 +00:00
|
|
|
unset($defaults);
|
2004-12-23 07:09:33 +00:00
|
|
|
include_once($fullmod .'/defaults.php');
|
2005-04-26 07:45:09 +00:00
|
|
|
if (!empty($defaults)) {
|
|
|
|
foreach ($defaults as $name => $value) {
|
|
|
|
if (!isset($CFG->$name)) {
|
|
|
|
set_config($name, $value);
|
|
|
|
}
|
2004-12-23 07:09:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-19 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-01 07:46:19 +00:00
|
|
|
upgrade_log_finish(); // finish logging if started
|
|
|
|
|
|
|
|
if ($updated_modules) {
|
2004-08-19 09:37:42 +00:00
|
|
|
print_continue($return);
|
2005-11-14 04:33:25 +00:00
|
|
|
print_footer();
|
2004-08-19 09:37:42 +00:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-01 04:14:31 +00:00
|
|
|
/**
|
|
|
|
* This function will return FALSE if the lock fails to be set (ie, if it's already locked)
|
2005-12-13 03:44:08 +00:00
|
|
|
*
|
|
|
|
* @param string $name ?
|
|
|
|
* @param bool $value ?
|
|
|
|
* @param int $staleafter ?
|
|
|
|
* @param bool $clobberstale ?
|
|
|
|
* @todo Finish documenting this function
|
2005-09-01 04:14:31 +00:00
|
|
|
*/
|
|
|
|
function set_cron_lock($name,$value=true,$staleafter=7200,$clobberstale=false) {
|
|
|
|
|
|
|
|
if (empty($name)) {
|
|
|
|
mtrace("Tried to get a cron lock for a null fieldname");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($value)) {
|
|
|
|
set_config($name,0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($config = get_record('config','name',$name)) {
|
|
|
|
if (empty($config->value)) {
|
|
|
|
set_config($name,time());
|
|
|
|
} else {
|
|
|
|
// check for stale.
|
|
|
|
if ((time() - $staleafter) > $config->value) {
|
|
|
|
mtrace("STALE LOCKFILE FOR $name - was $config->value");
|
|
|
|
if (!empty($clobberstale)) {
|
|
|
|
set_config($name,time());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false; // was not stale - ie, we're ok to still be running.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_config($name,time());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2006-01-27 02:54:51 +00:00
|
|
|
|
2006-06-18 10:09:58 +00:00
|
|
|
function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='') {
|
2006-01-27 02:54:51 +00:00
|
|
|
static $starttime;
|
|
|
|
static $lasttime;
|
|
|
|
|
|
|
|
if (empty($starttime)) {
|
|
|
|
$starttime = $lasttime = time();
|
|
|
|
$lasttime = $starttime - $updatetime;
|
|
|
|
echo '<table width="500" cellpadding="0" cellspacing="0" align="center"><tr><td width="500">';
|
|
|
|
echo '<div id="bar" style="border-style:solid;border-width:1px;width:500px;height:50px;">';
|
|
|
|
echo '<div id="slider" style="border-style:solid;border-width:1px;height:48px;width:10px;background-color:green;"></div>';
|
|
|
|
echo '</div>';
|
|
|
|
echo '<div id="text" align="center" style="width:500px;"></div>';
|
|
|
|
echo '</td></tr></table>';
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$now = time();
|
|
|
|
|
|
|
|
if ($done && (($now - $lasttime) >= $updatetime)) {
|
|
|
|
$elapsedtime = $now - $starttime;
|
|
|
|
$projectedtime = (int)(((float)$total / (float)$done) * $elapsedtime) - $elapsedtime;
|
|
|
|
$percentage = format_float((float)$done / (float)$total, 2);
|
|
|
|
$width = (int)(500 * $percentage);
|
|
|
|
|
2006-06-18 10:09:58 +00:00
|
|
|
if ($projectedtime > 10) {
|
|
|
|
$projectedtext = ' Ending: '.format_time($projectedtime);
|
|
|
|
} else {
|
|
|
|
$projectedtext = '';
|
|
|
|
}
|
|
|
|
|
2006-01-27 02:54:51 +00:00
|
|
|
echo '<script>';
|
2006-06-18 10:09:58 +00:00
|
|
|
echo 'document.getElementById("text").innerHTML = "'.addslashes($donetext).' '.$done.' done.'.$projectedtext.'";'."\n";
|
2006-01-27 02:54:51 +00:00
|
|
|
echo 'document.getElementById("slider").style.width = \''.$width.'px\';'."\n";
|
|
|
|
echo '</script>';
|
|
|
|
|
|
|
|
$lasttime = $now;
|
|
|
|
sleep($sleeptime);
|
|
|
|
}
|
|
|
|
}
|
2006-08-01 07:46:19 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
/// upgrade logging functions
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
$upgradeloghandle = false;
|
|
|
|
global $upgradeloghandle; // needed for access from callback funtion
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if upgrade is already running.
|
|
|
|
*
|
|
|
|
* If anything goes wrong due to missing call to upgrade_log_finish()
|
|
|
|
* just restart the browser.
|
|
|
|
*
|
|
|
|
* @param string warning message indicating upgrade is already running
|
|
|
|
* @param int page reload timeout
|
|
|
|
*/
|
|
|
|
function upgrade_check_running($message, $timeout) {
|
|
|
|
if (!empty($_SESSION['upgraderunning'])) {
|
|
|
|
print_header();
|
|
|
|
redirect(me(), $message, $timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
if (!empty($_SESSION['upgraderunning'])) {
|
|
|
|
return; // logging already started
|
|
|
|
}
|
|
|
|
|
|
|
|
@ignore_user_abort(true); // ignore if user stops or otherwise aborts page loading
|
|
|
|
$_SESSION['upgraderunning'] = 1; // set upgrade indicator
|
|
|
|
session_write_close(); // from now on user can reload page - will be displayed warning
|
|
|
|
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, allow script aborting
|
|
|
|
* and reopen session for writing. Function error() does terminate the logging too.
|
|
|
|
*
|
|
|
|
* Please make sure that each upgrade_log_start() is properly terminated by
|
|
|
|
* this function or error().
|
|
|
|
*
|
|
|
|
* This function may be called repeatedly.
|
|
|
|
*/
|
|
|
|
function upgrade_log_finish() {
|
|
|
|
global $upgradeloghandle;
|
|
|
|
|
|
|
|
if (empty($_SESSION['upgraderunning'])) {
|
|
|
|
return; // logging already terminated
|
|
|
|
}
|
|
|
|
|
|
|
|
@ob_end_flush();
|
|
|
|
@fclose($upgradeloghandle);
|
|
|
|
@session_start(); // ignore header errors, we only need to reopen session
|
|
|
|
$_SESSION['upgraderunning'] = 0; // clear upgrade indicator
|
|
|
|
if (connection_aborted()) {
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
@ignore_user_abort(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;
|
|
|
|
|
|
|
|
if (empty($CFG->disableupgradelogging) and ($string != '') and ($upgradeloghandle !== 'error')) {
|
|
|
|
if ($upgradeloghandle or ($upgradeloghandle = @fopen($CFG->dataroot.'/upgradelogs/upg_'.date('Ymd-Hi').'.html', 'a'))) {
|
|
|
|
@fwrite($upgradeloghandle, $string);
|
|
|
|
} else {
|
|
|
|
$upgradeloghandle = 'error';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2004-12-23 09:07:43 +00:00
|
|
|
?>
|