mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Bugfix sulla creazione degli archivi
This commit is contained in:
@@ -82,16 +82,21 @@ function deltree($path)
|
|||||||
*
|
*
|
||||||
* @return bool Returns TRUE on success, FALSE on failure
|
* @return bool Returns TRUE on success, FALSE on failure
|
||||||
*/
|
*/
|
||||||
function copyr($source, $dest, $exclude = [])
|
function copyr($source, $dest, $ignores = [])
|
||||||
{
|
{
|
||||||
|
$path = realpath($source);
|
||||||
|
$exclude = !empty(array_intersect([slashes($path), slashes($path.'/'), $entry], $ignores));
|
||||||
|
|
||||||
// Simple copy for a file
|
// Simple copy for a file
|
||||||
if (is_file($source) && !in_array(slashes(realpath($source)), $exclude) && !in_array($source, $exclude)) {
|
if (is_file($source) && !$exclude) {
|
||||||
return copy($source, $dest);
|
return copy($source, $dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make destination directory
|
// Make destination directory
|
||||||
if (!is_dir($dest)) {
|
if (!is_dir($dest)) {
|
||||||
mkdir($dest);
|
mkdir($dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the source is a symlink
|
// If the source is a symlink
|
||||||
if (is_link($source)) {
|
if (is_link($source)) {
|
||||||
$link_dest = readlink($source);
|
$link_dest = readlink($source);
|
||||||
@@ -107,8 +112,11 @@ function copyr($source, $dest, $exclude = [])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$path = realpath($source.'/'.$entry.'/');
|
||||||
|
$exclude = !empty(array_intersect([slashes($path), slashes($path.'/'), $entry], $ignores));
|
||||||
|
|
||||||
// Deep copy directories
|
// Deep copy directories
|
||||||
if ($dest !== $source.'/'.$entry && !in_array(slashes(realpath($source.'/'.$entry.'/')), $exclude) && !in_array(slashes(realpath($source.'/'.$entry.'/').'/'), $exclude) && !in_array($entry, $exclude)) {
|
if ($dest !== $source.'/'.$entry && !$exclude) {
|
||||||
copyr($source.'/'.$entry, $dest.'/'.$entry, $exclude);
|
copyr($source.'/'.$entry, $dest.'/'.$entry, $exclude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,8 +144,8 @@ function create_zip($source, $destination)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
|
$result = $zip->open($destination, ZIPARCHIVE::CREATE);
|
||||||
if ($zip->open($destination, ZIPARCHIVE::CREATE)) {
|
if ($result === true && is_writable(dirname($destination))) {
|
||||||
$source = slashes(realpath($source));
|
$source = slashes(realpath($source));
|
||||||
|
|
||||||
if (is_dir($source) === true) {
|
if (is_dir($source) === true) {
|
||||||
@@ -145,12 +153,12 @@ function create_zip($source, $destination)
|
|||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$file = slashes(realpath($file));
|
$file = slashes(realpath($file));
|
||||||
$file = str_replace($source.DIRECTORY_SEPARATOR, '', $file);
|
$filename = str_replace($source.DIRECTORY_SEPARATOR, '', $file);
|
||||||
|
|
||||||
if (is_dir($file) === true) {
|
if (is_dir($file) === true) {
|
||||||
$zip->addEmptyDir($file);
|
$zip->addEmptyDir($filename);
|
||||||
} elseif (is_file($file) === true) {
|
} elseif (is_file($file) === true) {
|
||||||
$zip->addFromString($file, file_get_contents($file));
|
$zip->addFromString($filename, file_get_contents($file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (is_file($source) === true) {
|
} elseif (is_file($source) === true) {
|
||||||
@@ -158,13 +166,11 @@ function create_zip($source, $destination)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
$_SESSION['errors'][] = tr("Errore durante la creazione dell'archivio!");
|
$_SESSION['errors'][] = tr("Errore durante la creazione dell'archivio!");
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $result === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,12 +248,13 @@ function do_backup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($do_backup) {
|
if ($do_backup) {
|
||||||
$database_file = 'backup database.sql';
|
$database_file = 'database.sql';
|
||||||
$backup_file = 'OSM backup '.date('Y-m-d').' '.date('H_i_s').'.zip';
|
$backup_file = 'OSM backup '.date('Y-m-d').' '.date('H_i_s').'.zip';
|
||||||
|
|
||||||
// Dump database
|
// Dump database
|
||||||
$dump = "SET foreign_key_checks = 0;\n";
|
$dump = "SET foreign_key_checks = 0;\n";
|
||||||
$dump .= backup_tables();
|
$dump .= backup_tables();
|
||||||
|
$dump .= "SET foreign_key_checks = 1;\n";
|
||||||
file_put_contents($backup_dir.$tmp_backup_dir.$database_file, $dump);
|
file_put_contents($backup_dir.$tmp_backup_dir.$database_file, $dump);
|
||||||
|
|
||||||
// Copia file di OSM (escludendo la cartella di backup)
|
// Copia file di OSM (escludendo la cartella di backup)
|
||||||
@@ -336,37 +343,38 @@ function backup_tables($tables = '*')
|
|||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
$result = $dbo->fetchArray('SELECT * FROM '.$table, true);
|
$result = $dbo->fetchArray('SELECT * FROM '.$table, true);
|
||||||
$num_fields = count($result[0]);
|
$num_fields = count($result[0]);
|
||||||
|
|
||||||
$row2 = $dbo->fetchArray('SHOW CREATE TABLE '.$table);
|
$row2 = $dbo->fetchArray('SHOW CREATE TABLE '.$table);
|
||||||
$return .= "\n".$row2[1].";\n";
|
$return .= "\n".$row2[1].";\n";
|
||||||
|
|
||||||
for ($i = 0; $i < $num_fields; ++$i) {
|
for ($i = 0; $i < $num_fields; ++$i) {
|
||||||
if ($result != false) {
|
foreach ($result as $row) {
|
||||||
foreach ($result as $row) {
|
$return .= 'INSERT INTO '.$table.' VALUES(';
|
||||||
$return .= 'INSERT INTO '.$table.' VALUES(';
|
|
||||||
for ($j = 0; $j < $num_fields; ++$j) {
|
for ($j = 0; $j < $num_fields; ++$j) {
|
||||||
$row[$j] = addslashes($row[$j]);
|
$row[$j] = addslashes($row[$j]);
|
||||||
$row[$j] = str_replace("\r\n", '\\n', $row[$j]);
|
$row[$j] = str_replace("\r\n", '\\n', $row[$j]);
|
||||||
$row[$j] = str_replace("\n", '\\n', $row[$j]);
|
$row[$j] = str_replace("\n", '\\n', $row[$j]);
|
||||||
if (isset($row[$j])) {
|
|
||||||
$return .= '"'.$row[$j].'"';
|
if (isset($row[$j])) {
|
||||||
} else {
|
$return .= '"'.$row[$j].'"';
|
||||||
$return .= '""';
|
} else {
|
||||||
}
|
$return .= '""';
|
||||||
if ($j < ($num_fields - 1)) {
|
}
|
||||||
$return .= ',';
|
|
||||||
}
|
if ($j < ($num_fields - 1)) {
|
||||||
|
$return .= ',';
|
||||||
}
|
}
|
||||||
$return .= ");\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$return .= ");\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$return .= "\n";
|
$return .= "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
// save file
|
|
||||||
// $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
|
|
||||||
// fwrite($handle,$return);
|
|
||||||
// fclose($handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,16 +30,14 @@ switch (post('op')) {
|
|||||||
// Creazione zip
|
// Creazione zip
|
||||||
if (extension_loaded('zip')) {
|
if (extension_loaded('zip')) {
|
||||||
create_zip($dir, $file);
|
create_zip($dir, $file);
|
||||||
} else {
|
|
||||||
system('zip -9 -r -j "'.$file.'" "'.$dir.'"');
|
// Invio al browser dello zip
|
||||||
|
force_download($file);
|
||||||
|
|
||||||
|
// Rimozione dei contenuti
|
||||||
|
deltree($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invio al browser dello zip
|
|
||||||
force_download($dir.'/fatture.zip');
|
|
||||||
|
|
||||||
// Rimozione cartella temporeanea
|
|
||||||
deltree($dir);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user