Source for file _maintenance.funcs.php
Documentation is available at _maintenance.funcs.php
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
* @param new version dir name
* @return string message or NULL
global $install_subdir, $install_path, $upgrade_path;
// Upgrade database using regular upgrader script
require_once( $install_path.
'/_version.php' );
require_once( $install_path.
'/_version.php' );
$new_version_file =
$upgrade_path.
$new_version_dir.
'/'.
$install_subdir.
'_version.php';
$current_version_file =
$install_path.
'/_version.php';
return T_( 'Installed version doesn\'t support upgrade!' );
require
( $new_version_file );
$new_version =
$current_version;
unset
( $current_version );
require
( $current_version_file );
$current_version =
$current_version;
if( $new_version ==
$current_version )
return T_( 'This package is already installed!' );
elseif( $new_version <
$current_version )
return T_( 'This is an old version!' );
@ini_set( 'max_execution_time', $seconds );
* Enable/disable maintenance mode
* @param boolean true if maintenance mode need to be enabled
* @param string maintenance mode message
$maintenance_mode_file =
'maintenance.txt';
{ // Create maintenance file
echo
'<p>'.
T_('Switching to maintenance mode...').
'</p>';
$f =
@fopen( $conf_path.
$maintenance_mode_file , 'w+' );
{ // Maintenance file has not been created
echo
'<p style="color:red">'.
sprintf( T_( 'Unable to switch maintenance mode. Maintenance file can\'t be created: «%s»' ), $maintenance_mode_file ).
'</p>';
{ // Delete maintenance file
echo
'<p>'.
T_('Switching out of maintenance mode...').
'</p>';
unlink( $conf_path.
$maintenance_mode_file );
* Prepare maintenance directory
* @param string directory path
* @param boolean create .htaccess file with 'deny from all' text
{ // We can create directory
echo
'<p style="color:red">'.
sprintf( T_( 'Unable to create «%s» directory.' ), $dir_name ).
'</p>';
{ // Create .htaccess file
$htaccess_name =
$dir_name.
'.htaccess';
{ // We can create .htaccess file
$f =
@fopen( $htaccess_name , 'w+' );
echo
'<p style="color:red">'.
sprintf( T_( 'Unable to create «%s» file in directory.' ), $htaccess_name ).
'</p>';
fwrite( $f, 'deny from all' );
* Unpack ZIP archive to destination directory
* @param string source file path
* @param string destination directory path
* @param boolean true if create destination directory
* @return boolean results
{ // We can create directory
echo
'<p style="color:red">'.
sprintf( T_( 'Unable to create «%s» directory.' ), $dest_dir ).
'</p>';
{ // Unpack using 'zlib' extension and PclZip wrapper
// Load PclZip class (PHP4):
load_class( '_ext/pclzip/pclzip.lib.php', 'PclZip' );
$PclZip =
new PclZip( $src_file );
echo
'<p style="color:red">'.
sprintf( T_( 'Unable to unpack «%s» ZIP archive.' ), $src_file ).
'</p>';
debug_die( 'There is no \'zip\' or \'zlib\' extension installed!' );
* Verify that destination files can be overwritten
* @param string source directory
* @param string destination directory
* @param string action name
* @param boolean overwrite
* @param array read only file list
function verify_overwrite( $src, $dest, $action =
'', $overwrite =
true, &$read_only_list )
while( false !==
( $file =
readdir( $dir ) ) )
if ( ( $file !=
'.' ) &&
( $file !=
'..' ) )
$srcfile =
$src.
'/'.
$file;
$destfile =
$dest.
'/'.
$file;
{ // Folder or file is not writable
$read_only_list[] =
$destfile;
$dir_list[$srcfile] =
$destfile;
$file_list[$srcfile] =
$destfile;
foreach( $dir_list as $src_dir =>
$dest_dir )
// progressive display of what backup is doing
echo
$action.
' «<strong>'.
$dest_dir.
'</strong>»...<br />';
// Create destination directory
foreach( $file_list as $src_file =>
$dest_file )
{ // Overwrite destination file
copy( $src_file, $dest_file );
* @param string download url
global $upgrade_path, $servertimenow, $debug;
// Construct version name from download URL
$slash_pos =
strrpos( $download_url, '/' );
$point_pos =
strrpos( $download_url, '.' );
if( $slash_pos <
$point_pos )
$version_name =
substr( $download_url, $slash_pos +
1, $point_pos -
$slash_pos -
1 );
if( empty( $version_name ) )
// Search if there is unpacked version in '_upgrade' directory
foreach( get_filenames( $upgrade_path, false, true, true, false, true ) as $dir_name )
if( strpos( $dir_name, $version_name ) ===
0 )
if( !empty( $new_version_status ) )
$action_props['action'] =
'none';
$action_props['status'] =
$new_version_status;
if( $debug >
0 ||
empty( $new_version_status ) )
$action_props['action'] =
'install';
$action_props['name'] =
$dir_name;
// Search if there is packed version in '_upgrade' directory
foreach( get_filenames( $upgrade_path, true, false, true, false, true ) as $file_name )
if( strpos( $file_name, $version_name ) ===
0 )
return array( 'action' =>
'unzip', 'name' =>
substr( $file_name, 0, strrpos( $file_name, '.' ) ) );
// There is no any version in '_upgrade' directory. So, we need download package before.
return array( 'action' =>
'download', 'name' =>
$version_name.
'-'.
date( 'Y-m-d', $servertimenow ) );
* Convert aliases to real table names as table backup works with real table names
foreach( $aliases as $alias )
$tables[] =
preg_replace( $DB->dbaliases, $DB->dbreplaces, $alias );
elseif( $aliases ==
'*' )
return preg_replace( $DB->dbaliases, $DB->dbreplaces, $aliases );
* $Log: _maintenance.funcs.php,v $
* Revision 1.8 2010/02/04 19:29:53 blueyed
* Revision 1.7 2010/01/17 16:15:24 sam2kb
* Revision 1.6 2009/11/22 19:15:34 efy-maxim
* Revision 1.5 2009/11/19 12:10:51 efy-maxim
* Force 'upgrade' for debug mode
* Revision 1.4 2009/11/18 21:54:25 efy-maxim
* compatibility fix for PHP4
* Revision 1.3 2009/10/21 14:27:39 efy-maxim
* Revision 1.2 2009/10/20 14:38:54 efy-maxim
* maintenance modulde: downloading - unpacking - verifying destination files - backing up - copying new files - upgrade database using regular script (Warning: it is very unstable version! Please, don't use maintenance modulde, because it can affect your data )
* Revision 1.1 2009/10/18 20:15:51 efy-maxim
* 1. backup, upgrade have been moved to maintenance module
* 2. maintenance module permissions