bug:2898 make some updates methods static + factorize code from plugins, themes & languages
git-svn-id: http://piwigo.org/svn/trunk@23821 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
718ef5a670
commit
d95425b9bb
5 changed files with 68 additions and 232 deletions
|
|
@ -2527,4 +2527,58 @@ function get_dirs($directory)
|
|||
}
|
||||
return $sub_dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* recursively delete a directory
|
||||
* @param string $path
|
||||
* @param string $trash_path, try to move the directory to this path if it cannot be delete
|
||||
*/
|
||||
function deltree($path, $trash_path=null)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
$fh = opendir($path);
|
||||
while ($file = readdir($fh))
|
||||
{
|
||||
if ($file != '.' and $file != '..')
|
||||
{
|
||||
$pathfile = $path . '/' . $file;
|
||||
if (is_dir($pathfile))
|
||||
{
|
||||
deltree($pathfile, $trash_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($pathfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($fh);
|
||||
|
||||
if (@rmdir($path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
elseif (!empty($trash_path))
|
||||
{
|
||||
if (!is_dir($trash_path))
|
||||
{
|
||||
@mkgetdir($trash_path, MKGETDIR_RECURSIVE|MKGETDIR_DIE_ON_ERROR|MKGETDIR_PROTECT_HTACCESS);
|
||||
}
|
||||
while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
|
||||
{
|
||||
if (!is_dir($r))
|
||||
{
|
||||
@rename($path, $r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -112,10 +112,7 @@ UPDATE '.USER_INFOS_TABLE.'
|
|||
;';
|
||||
pwg_query($query);
|
||||
|
||||
if (!$this->deltree(PHPWG_ROOT_PATH.'language/'.$language_id))
|
||||
{
|
||||
$this->send_to_trash(PHPWG_ROOT_PATH.'language/'.$language_id);
|
||||
}
|
||||
deltree(PHPWG_ROOT_PATH.'language/'.$language_id, PHPWG_ROOT_PATH.'language/trash');
|
||||
break;
|
||||
|
||||
case 'set_default':
|
||||
|
|
@ -381,10 +378,7 @@ UPDATE '.USER_INFOS_TABLE.'
|
|||
}
|
||||
elseif (is_dir($path))
|
||||
{
|
||||
if (!$this->deltree($path))
|
||||
{
|
||||
$this->send_to_trash($path);
|
||||
}
|
||||
deltree($path, PHPWG_ROOT_PATH.'language/trash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -405,59 +399,6 @@ UPDATE '.USER_INFOS_TABLE.'
|
|||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete $path directory
|
||||
* @param string - path
|
||||
*/
|
||||
function deltree($path)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
$fh = opendir($path);
|
||||
while ($file = readdir($fh))
|
||||
{
|
||||
if ($file != '.' and $file != '..')
|
||||
{
|
||||
$pathfile = $path . '/' . $file;
|
||||
if (is_dir($pathfile))
|
||||
{
|
||||
$this->deltree($pathfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($pathfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($fh);
|
||||
return @rmdir($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send $path to trash directory
|
||||
* @param string - path
|
||||
*/
|
||||
function send_to_trash($path)
|
||||
{
|
||||
$trash_path = PHPWG_ROOT_PATH . 'language/trash';
|
||||
if (!is_dir($trash_path))
|
||||
{
|
||||
@mkdir($trash_path);
|
||||
$file = @fopen($trash_path . '/.htaccess', 'w');
|
||||
@fwrite($file, 'deny from all');
|
||||
@fclose($file);
|
||||
}
|
||||
while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
|
||||
{
|
||||
if (!is_dir($r))
|
||||
{
|
||||
@rename($path, $r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort functions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -166,10 +166,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\'';
|
|||
{
|
||||
break;
|
||||
}
|
||||
if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id))
|
||||
{
|
||||
$this->send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
|
||||
}
|
||||
deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash');
|
||||
break;
|
||||
}
|
||||
return $errors;
|
||||
|
|
@ -514,10 +511,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\'';
|
|||
}
|
||||
elseif (is_dir($path))
|
||||
{
|
||||
if (!$this->deltree($path))
|
||||
{
|
||||
$this->send_to_trash($path);
|
||||
}
|
||||
deltree($path, PHPWG_PLUGINS_PATH . 'trash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -553,59 +547,6 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\'';
|
|||
}
|
||||
return $merged_extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete $path directory
|
||||
* @param string - path
|
||||
*/
|
||||
function deltree($path)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
$fh = opendir($path);
|
||||
while ($file = readdir($fh))
|
||||
{
|
||||
if ($file != '.' and $file != '..')
|
||||
{
|
||||
$pathfile = $path . '/' . $file;
|
||||
if (is_dir($pathfile))
|
||||
{
|
||||
$this->deltree($pathfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($pathfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($fh);
|
||||
return @rmdir($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send $path to trash directory
|
||||
* @param string - path
|
||||
*/
|
||||
function send_to_trash($path)
|
||||
{
|
||||
$trash_path = PHPWG_PLUGINS_PATH . 'trash';
|
||||
if (!is_dir($trash_path))
|
||||
{
|
||||
@mkdir($trash_path);
|
||||
$file = @fopen($trash_path . '/.htaccess', 'w');
|
||||
@fwrite($file, 'deny from all');
|
||||
@fclose($file);
|
||||
}
|
||||
while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
|
||||
{
|
||||
if (!is_dir($r))
|
||||
{
|
||||
@rename($path, $r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort functions
|
||||
|
|
|
|||
|
|
@ -221,10 +221,7 @@ DELETE
|
|||
}
|
||||
}
|
||||
|
||||
if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id))
|
||||
{
|
||||
$this->send_to_trash(PHPWG_THEMES_PATH.$theme_id);
|
||||
}
|
||||
deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash');
|
||||
break;
|
||||
|
||||
case 'set_default':
|
||||
|
|
@ -641,10 +638,7 @@ SELECT
|
|||
}
|
||||
elseif (is_dir($path))
|
||||
{
|
||||
if (!$this->deltree($path))
|
||||
{
|
||||
$this->send_to_trash($path);
|
||||
}
|
||||
deltree($path, PHPWG_THEMES_PATH . 'trash');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -663,59 +657,6 @@ SELECT
|
|||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete $path directory
|
||||
* @param string - path
|
||||
*/
|
||||
function deltree($path)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
$fh = opendir($path);
|
||||
while ($file = readdir($fh))
|
||||
{
|
||||
if ($file != '.' and $file != '..')
|
||||
{
|
||||
$pathfile = $path . '/' . $file;
|
||||
if (is_dir($pathfile))
|
||||
{
|
||||
$this->deltree($pathfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($pathfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($fh);
|
||||
return @rmdir($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* send $path to trash directory
|
||||
* @param string - path
|
||||
*/
|
||||
function send_to_trash($path)
|
||||
{
|
||||
$trash_path = PHPWG_THEMES_PATH . 'trash';
|
||||
if (!is_dir($trash_path))
|
||||
{
|
||||
@mkdir($trash_path);
|
||||
$file = @fopen($trash_path . '/.htaccess', 'w');
|
||||
@fwrite($file, 'deny from all');
|
||||
@fclose($file);
|
||||
}
|
||||
while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
|
||||
{
|
||||
if (!is_dir($r))
|
||||
{
|
||||
@rename($path, $r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort functions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class updates
|
|||
}
|
||||
}
|
||||
|
||||
function check_piwigo_upgrade()
|
||||
static function check_piwigo_upgrade()
|
||||
{
|
||||
$_SESSION['need_update'] = null;
|
||||
|
||||
|
|
@ -242,48 +242,7 @@ class updates
|
|||
return $this->$type->$version_compare($a, $b);
|
||||
}
|
||||
|
||||
function deltree($path, $move_to_trash=false)
|
||||
{
|
||||
if (is_dir($path))
|
||||
{
|
||||
$fh = opendir($path);
|
||||
while ($file = readdir($fh))
|
||||
{
|
||||
if ($file != '.' and $file != '..')
|
||||
{
|
||||
$pathfile = $path . '/' . $file;
|
||||
if (is_dir($pathfile))
|
||||
{
|
||||
self::deltree($pathfile, $move_to_trash);
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($pathfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($fh);
|
||||
if (@rmdir($path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
elseif ($move_to_trash)
|
||||
{
|
||||
$trash = PHPWG_ROOT_PATH.'_trash';
|
||||
if (!is_dir($trash))
|
||||
{
|
||||
@mkgetdir($trash);
|
||||
}
|
||||
return @rename($path, $trash . '/'.md5(uniqid(rand(), true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function process_obsolete_list($file)
|
||||
static function process_obsolete_list($file)
|
||||
{
|
||||
if (file_exists(PHPWG_ROOT_PATH.$file)
|
||||
and $old_files = file(PHPWG_ROOT_PATH.$file, FILE_IGNORE_NEW_LINES)
|
||||
|
|
@ -299,13 +258,13 @@ class updates
|
|||
}
|
||||
elseif (is_dir($path))
|
||||
{
|
||||
self::deltree($path, true);
|
||||
deltree($path, PHPWG_ROOT_PATH.'_trash');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dump_database($include_history=false)
|
||||
static function dump_database($include_history=false)
|
||||
{
|
||||
global $page, $conf, $cfgBase;
|
||||
|
||||
|
|
@ -350,7 +309,7 @@ class updates
|
|||
}
|
||||
|
||||
@readfile($backupFile);
|
||||
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
exit();
|
||||
}
|
||||
else
|
||||
|
|
@ -359,7 +318,7 @@ class updates
|
|||
}
|
||||
}
|
||||
|
||||
function upgrade_to($upgrade_to, &$step, $check_current_version=true)
|
||||
static function upgrade_to($upgrade_to, &$step, $check_current_version=true)
|
||||
{
|
||||
global $page, $conf, $template;
|
||||
|
||||
|
|
@ -449,7 +408,7 @@ class updates
|
|||
if (empty($error))
|
||||
{
|
||||
self::process_obsolete_list($obsolete_list);
|
||||
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
invalidate_user_cache(true);
|
||||
$template->delete_compiled_templates();
|
||||
unset($_SESSION['need_update']);
|
||||
|
|
@ -477,7 +436,7 @@ class updates
|
|||
}
|
||||
else
|
||||
{
|
||||
self::deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
deltree(PHPWG_ROOT_PATH.$conf['data_location'].'update');
|
||||
array_push($page['errors'], l10n('An error has occured during upgrade.'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue