2013-09-30 Miguel de Dios <miguel.dedios@artica.es>

* include/functions.php: added function "delete_dir" and improved
	the function "copy_dir".
	
	* extensions/update_manager/lib/libupdate_manager_client.php,
	extensions/update_manager/lib/functions.php,
	extensions/update_manager/main.php: added feature to upload zip
	archives to update.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8827 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-09-30 09:08:10 +00:00
parent 9639821051
commit b2e0094f6b
5 changed files with 155 additions and 84 deletions

View File

@ -1,3 +1,13 @@
2013-09-30 Miguel de Dios <miguel.dedios@artica.es>
* include/functions.php: added function "delete_dir" and improved
the function "copy_dir".
* extensions/update_manager/lib/libupdate_manager_client.php,
extensions/update_manager/lib/functions.php,
extensions/update_manager/main.php: added feature to upload zip
archives to update.
2013-09-29 Junichi Satoh <junichi@rworks.jp> 2013-09-29 Junichi Satoh <junichi@rworks.jp>
* include/ajax/events.php: Added timeout binary paths to execute * include/ajax/events.php: Added timeout binary paths to execute

View File

@ -480,95 +480,128 @@ function install_offline_enterprise_package(&$settings, $user_key) {
$extension = substr($_FILES["fileloaded"]["name"], $extension = substr($_FILES["fileloaded"]["name"],
strlen($_FILES["fileloaded"]["name"])-4, 4); strlen($_FILES["fileloaded"]["name"])-4, 4);
if ($extension != '.oum') { switch ($extension) {
ui_print_error_message(__('Incorrect file extension')); case '.oum':
} case '.zip':
else { $tempDir = sys_get_temp_dir();
$tempDir = sys_get_temp_dir()."/tmp_oum/"; if ($extension == '.oum') {
$tempDir .= "/tmp_oum/";
$zip = new ZipArchive;
if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) {
$zip->extractTo($tempDir);
$zip->close();
}
else {
$error = ui_print_error_message(__('Update cannot be opened'));
}
$package = um_package_info_from_paths ($tempDir);
if ($package === false) {
ui_print_error_message(
__('Error, the file package is empty or corrupted.'));
}
else {
$settings = um_db_load_settings ();
if ($settings->current_update >= $package->id) {
ui_print_error_message(
__('Your system version is higher or equal than the loaded package'));
} }
else { else {
$binary_paths = um_client_get_files ($tempDir."binary/"); $tempDir .= "/tmp_zip";
}
foreach ($binary_paths as $key => $paths) { delete_dir($tempDir);
foreach($paths as $index => $path) {
$tempDir_scaped = preg_replace('/\//', '\/', $tempDir."binary");
$binary_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path); $zip = new ZipArchive;
} if ($zip->open($_FILES["fileloaded"]['tmp_name']) === TRUE) {
$zip->extractTo($tempDir);
$zip->close();
}
else {
$error = ui_print_error_message(__('Update cannot be opened'));
}
if ($extension == '.oum') {
////////////////////////////////////////////////////
$package = um_package_info_from_paths ($tempDir);
if ($package === false) {
ui_print_error_message(
__('Error, the file package is empty or corrupted.'));
} }
else {
$code_paths = um_client_get_files ($tempDir."code/"); $settings = um_db_load_settings ();
foreach ($code_paths as $key => $paths) { if ($settings->current_update >= $package->id) {
foreach($paths as $index => $path) { ui_print_error_message(
$tempDir_scaped = preg_replace('/\//', '\/', $tempDir."code"); __('Your system version is higher or equal than the loaded package'));
$code_paths[$key][$index] = preg_replace('/^'.$tempDir_scaped.'/', ' ', $path);
} }
} else {
$binary_paths = um_client_get_files ($tempDir . "binary/");
$sql_paths = um_client_get_files ($tempDir);
foreach ($sql_paths as $key => $paths) { foreach ($binary_paths as $key => $paths) {
foreach ($paths as $index => $path) { foreach($paths as $index => $path) {
if ($path != $tempDir || ($key == 'info_package' && $path == $tempDir)) { $tempDir_scaped = preg_replace('/\//',
unset($sql_paths[$key]); '\/', $tempDir . "binary");
$binary_paths[$key][$index] = preg_replace(
'/^' . $tempDir_scaped . '/', ' ', $path);
}
}
$code_paths = um_client_get_files ($tempDir . "code/");
foreach ($code_paths as $key => $paths) {
foreach($paths as $index => $path) {
$tempDir_scaped = preg_replace('/\//', '\/', $tempDir . "code");
$code_paths[$key][$index] = preg_replace(
'/^' . $tempDir_scaped . '/', ' ', $path);
}
}
$sql_paths = um_client_get_files ($tempDir);
foreach ($sql_paths as $key => $paths) {
foreach ($paths as $index => $path) {
if ($path != $tempDir || ($key == 'info_package' && $path == $tempDir)) {
unset($sql_paths[$key]);
}
}
}
$updates_binary = array();
$updates_code = array();
$updates_sql = array();
if (!empty($binary_paths)) {
$updates_binary = um_client_update_from_paths(
$binary_paths, $tempDir, $package->id, 'binary');
}
if (!empty($code_paths)) {
$updates_code = um_client_update_from_paths(
$code_paths, $tempDir, $package->id, 'code');
}
if (!empty($sql_paths)) {
$updates_sql = um_client_update_from_paths(
$sql_paths, $tempDir, $package->id, 'sql');
}
um_delete_directory($tempDir);
$updates= array_merge((array) $updates_binary, (array) $updates_code, (array) $updates_sql);
$package->updates = $updates;
$settings = um_db_load_settings ();
if (um_client_upgrade_to_package($package, $settings, true)) {
ui_print_success_message(
__('Successfully upgraded'));
//Refresh the settings object.
$settings = um_db_load_settings ();
}
else {
ui_print_error_message(__('Cannot be upgraded'));
} }
} }
} }
////////////////////////////////////////////////////
}
else {
$correct = copy_dir($tempDir, $config['homedir']);
$updates_binary = array(); if ($correct) {
$updates_code = array();
$updates_sql = array();
if (!empty($binary_paths)) {
$updates_binary = um_client_update_from_paths ($binary_paths, $tempDir, $package->id, 'binary');
}
if (!empty($code_paths)) {
$updates_code = um_client_update_from_paths ($code_paths, $tempDir, $package->id, 'code');
}
if (!empty($sql_paths)) {
$updates_sql = um_client_update_from_paths ($sql_paths, $tempDir, $package->id, 'sql');
}
um_delete_directory($tempDir);
$updates= array_merge((array) $updates_binary, (array) $updates_code, (array) $updates_sql);
$package->updates = $updates;
$settings = um_db_load_settings ();
if (um_client_upgrade_to_package($package, $settings, true)) {
ui_print_success_message( ui_print_success_message(
__('Successfully upgraded')); __('Successfully upgraded'));
//Refresh the settings object.
$settings = um_db_load_settings ();
} }
else { else {
ui_print_error_message(__('Cannot be upgraded')); ui_print_error_message(__('Cannot be upgraded'));
} }
} }
} break;
default:
ui_print_error_message(__('Incorrect file extension'));
break;
} }
} }
else { else {

View File

@ -325,7 +325,7 @@ function um_client_decrypt ($data) {
// with the path of all files into directory // // with the path of all files into directory //
/////////////////////////////////////////////// ///////////////////////////////////////////////
function um_client_get_files ($dir_path) { function um_client_get_files ($dir_path) {
if(!file_exists($dir_path)) { if (!file_exists($dir_path)) {
return array(); return array();
} }
@ -334,10 +334,10 @@ function um_client_get_files ($dir_path) {
$cont = 0; $cont = 0;
while ($element = readdir($dir)) while ($element = readdir($dir))
{ {
if($element == '.' || $element == '..') { if ($element == '.' || $element == '..') {
continue; continue;
} }
if(is_dir($dir_path.$element)) { if (is_dir($dir_path.$element)) {
$file_temp = um_client_get_files ("$dir_path$element/"); $file_temp = um_client_get_files ("$dir_path$element/");
$files = array_merge((array)$files,(array)$file_temp); $files = array_merge((array)$files,(array)$file_temp);
} }
@ -353,7 +353,7 @@ function um_client_get_files ($dir_path) {
} }
function um_client_print_update ($update, $settings) { function um_client_print_update ($update, $settings) {
if(isset($update->id)) { if (isset($update->id)) {
echo 'Update #'.$update->id; echo 'Update #'.$update->id;
} }
@ -554,7 +554,7 @@ function um_client_upgrade_to_package ($package, $settings, $force = true, $upda
} }
$tempDirServer = '/'.implode('/',$path_script).'/temp/'; $tempDirServer = '/'.implode('/',$path_script).'/temp/';
$package_name = 'package_'.$package->id.'.oum'; $package_name = 'package_'.$package->id.'.oum';
$zipArchive = $tempDir . $package_name; $zipArchive = $tempDir . $package_name;
$zipArchiveServer = $tempDirServer . $package_name; $zipArchiveServer = $tempDirServer . $package_name;

View File

@ -97,8 +97,11 @@ function main_view_enterprise($settings, $user_key) {
} }
} }
if (!empty($_FILES)) { $upload_package = (bool)get_parameter('upload_package');
install_offline_enterprise_package($settings, $user_key); if ($upload_package) {
if (!empty($_FILES)) {
install_offline_enterprise_package($settings, $user_key);
}
} }
@ -172,7 +175,6 @@ function main_view_enterprise($settings, $user_key) {
<?php <?php
echo '<h4>' . __('Offline') . '</h4>'; echo '<h4>' . __('Offline') . '</h4>';
$table = null; $table = null;
$table->width = '98%'; $table->width = '98%';

View File

@ -1704,6 +1704,7 @@ function get_periods ($custom = true, $show_default = true) {
*/ */
function copy_dir($src, $dst) { function copy_dir($src, $dst) {
$dir = opendir($src); $dir = opendir($src);
$return = true;
if (!$dir) if (!$dir)
return false; return false;
@ -1712,14 +1713,39 @@ function copy_dir($src, $dst) {
while (false !== ( $file = readdir($dir)) ) { while (false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) { if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) { if ( is_dir($src . '/' . $file) ) {
copy_dir($src . '/' . $file,$dst . '/' . $file); $return = copy_dir($src . '/' . $file, $dst . '/' . $file);
if (!$return) {
break;
}
} }
else { else {
copy($src . '/' . $file,$dst . '/' . $file); $r = copy($src . '/' . $file, $dst . '/' . $file);
} }
} }
} }
closedir($dir); closedir($dir);
return $return;
}
function delete_dir($dir) {
if (!file_exists($dir))
return true;
if (!is_dir($dir))
return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..')
continue;
if (!delete_dir($dir . "/" . $item))
return false;
}
return rmdir($dir);
} }
/** /**