2020-09-19 10:18:39 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-19 10:18:39 +02:00
|
|
|
*
|
|
|
|
* 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';
|
|
|
|
|
2020-09-19 11:08:13 +02:00
|
|
|
$backup = null; // Cartella di backup specifica
|
2020-09-19 10:18:39 +02:00
|
|
|
$file = null; // File di backup del database
|
|
|
|
|
|
|
|
// Ricerca dell'ultimo backup (idealmente versione 2.4.16)
|
2020-09-19 11:08:13 +02:00
|
|
|
if (empty($file) && empty($backup)) {
|
2020-09-19 10:18:39 +02:00
|
|
|
$backups = Backup::getList();
|
2020-09-22 08:30:08 +02:00
|
|
|
$backups = array_reverse($backups);
|
2020-09-19 10:18:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($file)) {
|
2020-09-19 11:08:13 +02:00
|
|
|
$count = count($backups);
|
|
|
|
for ($i = 0; $i < $count; ++$i) {
|
|
|
|
$backup = $backups[$i];
|
|
|
|
|
|
|
|
// Individuazione del database nel backup
|
2020-10-29 16:48:37 +01:00
|
|
|
if (string_ends_with($backup, '.zip')) {
|
2020-09-19 11:08:13 +02:00
|
|
|
$zip = new ZipArchive();
|
|
|
|
$zip->open($backup);
|
|
|
|
|
|
|
|
$version = $zip->getFromName('VERSION');
|
|
|
|
if ($version == '2.4.17') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 {
|
|
|
|
$version = file_get_contents($backup.'/VERSION');
|
|
|
|
if ($version == '2.4.17') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = $backup.'/database.sql';
|
|
|
|
}
|
2020-09-19 10:18:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 11:08:13 +02:00
|
|
|
if (empty($file)) {
|
|
|
|
echo 'Impossibile procedere';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-19 10:18:39 +02:00
|
|
|
// Lettura delle query
|
|
|
|
$queries = readSQLFile($file, ';');
|
|
|
|
$count = count($queries);
|
|
|
|
|
|
|
|
// Individuazione del dump di co_movimenti
|
|
|
|
$query = null;
|
|
|
|
for ($i = 0; $i < $count; ++$i) {
|
2020-10-29 16:48:37 +01:00
|
|
|
if (string_starts_with($queries[$i], 'INSERT INTO `co_movimenti`')) {
|
2020-09-19 10:18:39 +02:00
|
|
|
$query = $queries[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($query)) {
|
|
|
|
echo 'Impossibile procedere';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lettura dei contenuti
|
|
|
|
$values = explode('VALUES', $query, 2)[1];
|
|
|
|
$values = explode('),', $values);
|
|
|
|
|
2020-09-19 11:08:13 +02:00
|
|
|
// Generazione delle query per il recupero delle date per la Prima Nota
|
2020-09-19 10:18:39 +02:00
|
|
|
$results = [];
|
|
|
|
foreach ($values as $row) {
|
|
|
|
$row = substr(trim($row), 1);
|
|
|
|
|
|
|
|
$campi = explode(',', $row);
|
|
|
|
$id = $campi[0];
|
|
|
|
$data = $campi[2];
|
2020-09-19 11:08:13 +02:00
|
|
|
$is_primanota = $campi[12];
|
2020-09-19 10:18:39 +02:00
|
|
|
|
2020-09-19 11:08:13 +02:00
|
|
|
if (!empty($is_primanota)) {
|
|
|
|
$results[] = 'UPDATE `co_movimenti` SET `data` = '.$data.' WHERE `id` = '.prepare($id).';';
|
|
|
|
}
|
2020-09-19 10:18:39 +02:00
|
|
|
}
|
|
|
|
|
2020-09-19 10:22:02 +02:00
|
|
|
echo implode("\n", $results);
|