mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Script sperimentale per il recupero date movimenti da backup
This commit is contained in:
parent
17f583c7b9
commit
d71715297b
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
use Ifsnop\Mysqldump\Mysqldump;
|
||||
use Util\Generator;
|
||||
use Util\Zip;
|
||||
|
||||
/**
|
||||
@ -96,7 +97,7 @@ class Backup
|
||||
*/
|
||||
public static function readName($string)
|
||||
{
|
||||
return Util\Generator::read(self::PATTERN, basename($string));
|
||||
return Generator::read(self::PATTERN, basename($string));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,7 +297,7 @@ class Backup
|
||||
*/
|
||||
protected static function getReplaces()
|
||||
{
|
||||
return Util\Generator::getReplaces();
|
||||
return Generator::getReplaces();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,6 +307,6 @@ class Backup
|
||||
*/
|
||||
protected static function getNextName()
|
||||
{
|
||||
return Util\Generator::generate(self::PATTERN);
|
||||
return Generator::generate(self::PATTERN);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
<?php
|
||||
|
||||
rename(DOCROOT.'/files/my_impianti', DOCROOT.'/files/impianti');
|
||||
rename(DOCROOT.'/files/my_impianti', DOCROOT.'/files/impianti');
|
||||
|
94
update/v2_4_17/recupero_date_movimenti.php
Normal file
94
update/v2_4_17/recupero_date_movimenti.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/*
|
||||
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
||||
* Copyright (C) DevCode s.n.c.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Rimozione delle limitazioni sull'esecuzione
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(true);
|
||||
|
||||
$skip_permissions = true;
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
$last_backup = null; // Cartella di backup specifica
|
||||
$file = null; // File di backup del database
|
||||
|
||||
// Ricerca dell'ultimo backup (idealmente versione 2.4.16)
|
||||
if (empty($file) && empty($last_backup)) {
|
||||
$backups = Backup::getList();
|
||||
$last_backup = end($backups);
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
// Individuazione del database nel backup
|
||||
if (ends_with($last_backup, '.zip')) {
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($last_backup);
|
||||
|
||||
$contents = $zip->getFromName('database.sql');
|
||||
|
||||
// File temporaneo
|
||||
$file = DIRECTORY_SEPARATOR.
|
||||
trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).
|
||||
DIRECTORY_SEPARATOR.
|
||||
ltrim('database.sql', DIRECTORY_SEPARATOR);
|
||||
|
||||
file_put_contents($file, $contents);
|
||||
|
||||
register_shutdown_function(function () use ($file) {
|
||||
unlink($file);
|
||||
});
|
||||
} else {
|
||||
$file = $last_backup.'/database.sql';
|
||||
}
|
||||
}
|
||||
|
||||
// Lettura delle query
|
||||
$queries = readSQLFile($file, ';');
|
||||
$count = count($queries);
|
||||
|
||||
// Individuazione del dump di co_movimenti
|
||||
$query = null;
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
if (starts_with($queries[$i], 'INSERT INTO `co_movimenti`')) {
|
||||
$query = $queries[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($query)) {
|
||||
echo 'Impossibile procedere';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Lettura dei contenuti
|
||||
$values = explode('VALUES', $query, 2)[1];
|
||||
$values = explode('),', $values);
|
||||
|
||||
// Generazione delle query per il recupero delle date
|
||||
$results = [];
|
||||
foreach ($values as $row) {
|
||||
$row = substr(trim($row), 1);
|
||||
|
||||
$campi = explode(',', $row);
|
||||
$id = $campi[0];
|
||||
$data = $campi[2];
|
||||
|
||||
$results[] = 'UPDATE `co_movimenti` SET `data` = '.$data.' WWHERE `id` = '.prepare($id);
|
||||
}
|
||||
|
||||
echo implode(';', $results);
|
Loading…
x
Reference in New Issue
Block a user