This commit is contained in:
Abdulrahman
2019-05-05 20:12:32 +03:00
parent 26fbee212a
commit 6df022a20b
5 changed files with 149 additions and 105 deletions

View File

@@ -37,7 +37,11 @@ return PhpCsFixer\Config::create()
'visibility_required' => true,
'native_function_casing' => true,
'no_empty_comment' => true,
'single_line_comment_style' => true
'single_line_comment_style' => true,
'phpdoc_add_missing_param_annotation' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
])
->setFinder($finder)
->setIndent(" ")

View File

@@ -656,7 +656,7 @@ switch ($case):
if (is_dir($plugin_folder_name))
{
delete_plugin_folder($plugin_folder_name);
kleeja_unlink($plugin_folder_name);
}
redirect($plugin_download_link . $update_plugin . '&update' );

View File

@@ -25,6 +25,7 @@ if (!ig('install_again'))
{
// kleeja doesn't need to update
kleeja_admin_info('there is no update for your version', ADMIN_PATH);
exit;
}
} // $_GET['install_again'] is set => reinstall kleeja => check if he is a developer
@@ -33,7 +34,8 @@ else
// please no .
if (! defined('DEV_STAGE'))
{
kleeja_admin_err(":( NOOO!!");
kleeja_admin_err(':( NOOO!!');
exit;
}
}
@@ -52,30 +54,32 @@ $kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/';
$old_version = KLEEJA_VERSION;
$new_version = unserialize($config['new_version'])['version_number'];
// downloaded the last version to cache folder
$down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true);
if ($down_new_pack) // we connected to github & downloaded the last version to cache folder
if ($down_new_pack)
{
// let's extract the zip to cache
$zip = new ZipArchive;
if ($zip->open( PATH . 'cache/kleeja.zip' ) == TRUE)
if ($zip->open(PATH . 'cache/kleeja.zip') == true)
{
$zip->extractTo(PATH . 'cache/');
$zip->close();
}
// some folder don't need it
$no_need = array(
$no_need = [
'cache', // delete_cache() function
'plugins', // kleeja now support plugins update
'uploads',
'styles', // kleeja will support style_update soon
'install' // befor removing install folder , we will take what we want from it
);
];
// let's check if there any update files in install folder
$update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_files/{$old_version}_to_{$new_version}.php";
if (file_exists($update_file))
{
// move the update file from install folder to cache folder to include it later and delete install folder
@@ -85,47 +89,79 @@ if ($down_new_pack) // we connected to github & downloaded the last version to c
foreach ($no_need as $folderName)
{
delete_plugin_folder( PATH . "cache/kleeja-{$new_version}/{$folderName}" );
kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folderName}");
}
// delete plugin folder function with some changes :)
$it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
//rollback settings
mkdir(PATH . 'cache/rollback');
$update_failed = false;
foreach ($files as $file)
{
if ($file->isLink())
if ($file->isFile())
{
file_put_contents(
str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) ,
$file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname());
// same, no need to replace
if (file_exists($file_path) && md5_file($file_path) != md5_file($file->getPathname()))
{
continue;
}
//backup for rollback
if (! file_put_contents(
'cache/rollback/' . ltrim($file_path, '/'),
file_get_contents($file_path)
))
{
$update_failed = true;
break;
}
//copy file
if (! file_put_contents(
$file_path,
file_get_contents($file->getPathname())
);
unlink($file->getPathname());
))
{
$update_failed = true;
break;
}
}
elseif ($file->isDir())
{
// here is folder , when we finish update , we will delete all folders and files
//TODO if folder is new, then mkdir it.
continue;
}
else
{
file_put_contents(
str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) ,
file_get_contents( $file->getPathname() )
);
unlink($file->getPathname());
// not file or folder ?
}
}
if ($update_failed)
{
//rollback to backup cache/rollback
}
else
{
// we will include what we want to do in this file , and kleeja will done
if (file_exists($updateFiles = PATH . "cache/update_{$old_version}_to_{$new_version}.php"))
{
require_once $updateFiles; // we will include what we want to do in this file , and kleeja will done
require_once $updateFiles;
}
// after we made success update , let's delete files and folders incache
// kleeja new version files
delete_plugin_folder(PATH . "cache/kleeja-{$new_version}");
kleeja_unlink(PATH . "cache/kleeja-{$new_version}");
// delete old cache files
delete_cache('', true);
@@ -135,5 +171,5 @@ if ($down_new_pack) // we connected to github & downloaded the last version to c
* OR WE CAN INCLUDE UPDATE FILES IN GITHUB , AND DOWNLOAD IT IN CACHE FOLDER WHEN IT REQUEST
* AND DELETE AFTER WE FINISH ;
*/
}
}

View File

@@ -576,9 +576,34 @@ function kleeja_unlink($filePath, $cache_file = false)
//99.9% who use this
if (function_exists('unlink'))
{
if (is_dir($filePath))
{
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file)
{
if ($file->isLink())
{
unlink($file->getPathname());
}
elseif ($file->isDir())
{
rmdir($file->getPathname());
}
else
{
unlink($file->getPathname());
}
}
return rmdir($dir);
}
else
{
return unlink($filePath);
}
}
//5% only who use this
//else if (function_exists('exec'))
//{

View File

@@ -18,6 +18,13 @@ if (! defined('IN_COMMON'))
* Print cp error function handler
*
* For admin
* @param mixed $msg
* @param mixed $navigation
* @param mixed $title
* @param mixed $exit
* @param mixed $redirect
* @param mixed $rs
* @param mixed $style
*/
function kleeja_admin_err($msg, $navigation = true, $title='', $exit = true, $redirect = false, $rs = 3, $style = 'admin_err')
{
@@ -386,31 +393,3 @@ function adm_is_start_box_hidden($name)
return in_array($name, $boxes);
}
/**
* delete plugin folder
* @param string $dir plugin folder path
* @return void
*/
function delete_plugin_folder($dir)
{
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file)
{
if ($file->isLink())
{
unlink($file->getPathname());
}
elseif ($file->isDir())
{
rmdir($file->getPathname());
}
else
{
unlink($file->getPathname());
}
}
rmdir($dir);
}