2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* 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-07 15:04:06 +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/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2024-03-05 16:01:45 +01:00
|
|
|
use Models\Module;
|
|
|
|
use Models\Plugin;
|
2024-03-22 15:52:24 +01:00
|
|
|
use Util\Zip;
|
2018-09-19 16:51:37 +02:00
|
|
|
|
2018-07-08 18:11:17 +02:00
|
|
|
if (!setting('Attiva aggiornamenti')) {
|
2021-02-18 18:48:44 +01:00
|
|
|
exit(tr('Accesso negato'));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!extension_loaded('zip')) {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->error(tr('Estensione zip non supportata!').'<br>'.tr('Verifica e attivala sul tuo file _FILE_', [
|
2017-09-18 16:55:19 +02:00
|
|
|
'_FILE_' => '<b>php.ini</b>',
|
2018-07-07 13:56:22 +02:00
|
|
|
]));
|
2018-07-04 15:38:10 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-19 16:51:37 +02:00
|
|
|
$extraction_dir = Zip::extract($_FILES['blob']['tmp_name']);
|
2018-07-04 15:38:10 +02:00
|
|
|
|
|
|
|
// Aggiornamento del progetto
|
|
|
|
if (file_exists($extraction_dir.'/VERSION')) {
|
|
|
|
// Salva il file di configurazione
|
2020-09-23 13:36:37 +02:00
|
|
|
$config = file_get_contents(base_dir().'/config.inc.php');
|
2018-07-04 15:38:10 +02:00
|
|
|
|
|
|
|
// Copia i file dalla cartella temporanea alla root
|
2020-09-23 13:36:37 +02:00
|
|
|
copyr($extraction_dir, base_dir());
|
2018-07-04 15:38:10 +02:00
|
|
|
|
|
|
|
// Ripristina il file di configurazione dell'installazione
|
2020-09-23 13:36:37 +02:00
|
|
|
file_put_contents(base_dir().'/config.inc.php', $config);
|
2018-07-04 17:15:14 +02:00
|
|
|
} else {
|
|
|
|
$finder = Symfony\Component\Finder\Finder::create()
|
|
|
|
->files()
|
|
|
|
->ignoreDotFiles(true)
|
|
|
|
->ignoreVCS(true)
|
|
|
|
->in($extraction_dir);
|
|
|
|
|
2024-04-05 14:32:29 +02:00
|
|
|
$files_module = $finder->name('MODULE');
|
2018-07-04 17:15:14 +02:00
|
|
|
|
2022-05-27 11:50:28 +02:00
|
|
|
foreach ($files_module as $file) {
|
2018-07-04 17:15:14 +02:00
|
|
|
// Informazioni dal file di configurazione
|
|
|
|
$info = Util\Ini::readFile($file->getRealPath());
|
|
|
|
|
|
|
|
// Informazioni aggiuntive per il database
|
|
|
|
$insert = [];
|
|
|
|
|
|
|
|
// Modulo
|
|
|
|
if (basename($file->getRealPath()) == 'MODULE') {
|
|
|
|
$directory = 'modules';
|
|
|
|
$table = 'zz_modules';
|
|
|
|
|
2024-03-20 11:13:28 +01:00
|
|
|
$installed = Module::find((new Module())->getByField('name', $info['name']));
|
2018-07-04 17:15:14 +02:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:50:28 +02:00
|
|
|
// Copia dei file nella cartella relativa
|
|
|
|
copyr(dirname($file->getRealPath()), base_dir().'/'.$directory.'/'.$info['directory']);
|
|
|
|
|
|
|
|
// Eventuale registrazione nel database
|
|
|
|
if (empty($installed)) {
|
|
|
|
$dbo->insert($table, array_merge($insert, [
|
|
|
|
'directory' => $info['directory'],
|
|
|
|
'options' => $info['options'],
|
|
|
|
'version' => $info['version'],
|
|
|
|
'compatibility' => $info['compatibility'],
|
|
|
|
'order' => 100,
|
|
|
|
'default' => 0,
|
|
|
|
'enabled' => 1,
|
2024-04-05 14:32:29 +02:00
|
|
|
'icon' => $info['icon'],
|
|
|
|
'parent' => (new Module())->getByField('name', $info['parent']),
|
2022-05-27 11:50:28 +02:00
|
|
|
]));
|
2024-03-13 09:47:05 +01:00
|
|
|
$id_record = $dbo->lastInsertedID();
|
|
|
|
$dbo->insert($table.'_lang', array_merge($insert, [
|
|
|
|
'name' => $info['name'],
|
|
|
|
'title' => !empty($info['title']) ? $info['title'] : $info['name'],
|
|
|
|
'id_record' => $id_record,
|
2024-03-22 15:52:24 +01:00
|
|
|
'id_lang' => Models\Locale::getDefault()->id,
|
2024-03-13 09:47:05 +01:00
|
|
|
]));
|
2022-05-27 11:50:28 +02:00
|
|
|
|
|
|
|
flash()->error(tr('Installazione completata!'));
|
|
|
|
} else {
|
|
|
|
flash()->error(tr('Aggiornamento completato!'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$finder = Symfony\Component\Finder\Finder::create()
|
|
|
|
->files()
|
|
|
|
->ignoreDotFiles(true)
|
|
|
|
->ignoreVCS(true)
|
|
|
|
->in($extraction_dir);
|
|
|
|
|
2024-04-05 14:32:29 +02:00
|
|
|
$files_plugin_template = $finder->name('PLUGIN')->name('TEMPLATES');
|
2022-05-27 11:50:28 +02:00
|
|
|
|
|
|
|
foreach ($files_plugin_template as $file) {
|
|
|
|
// Informazioni dal file di configurazione
|
|
|
|
$info = Util\Ini::readFile($file->getRealPath());
|
|
|
|
|
|
|
|
// Informazioni aggiuntive per il database
|
|
|
|
$insert = [];
|
2024-04-05 16:07:27 +02:00
|
|
|
$insert_lang = [];
|
2022-05-27 11:50:28 +02:00
|
|
|
|
2018-07-04 17:15:14 +02:00
|
|
|
// Plugin
|
2022-05-27 11:50:28 +02:00
|
|
|
if (basename($file->getRealPath()) == 'PLUGIN') {
|
2018-07-04 17:15:14 +02:00
|
|
|
$directory = 'plugins';
|
|
|
|
$table = 'zz_plugins';
|
|
|
|
|
2024-03-20 11:13:28 +01:00
|
|
|
$installed = Plugin::find((new Plugin())->getByField('name', $info['name']));
|
|
|
|
$insert['idmodule_from'] = (new Module())->getByField('name', $info['module_from']);
|
|
|
|
$insert['idmodule_to'] = (new Module())->getByField('name', $info['module_to']);
|
2018-07-04 17:15:14 +02:00
|
|
|
$insert['position'] = $info['position'];
|
|
|
|
}
|
2022-05-03 12:51:05 +02:00
|
|
|
|
|
|
|
// Templates
|
|
|
|
elseif (basename($file->getRealPath()) == 'TEMPLATES') {
|
|
|
|
$directory = 'templates';
|
|
|
|
$table = 'zz_prints';
|
|
|
|
|
|
|
|
$installed = Prints::getPrints()[$info['name']];
|
2024-03-20 11:13:28 +01:00
|
|
|
$insert['id_module'] = (new Module())->getByField('name', $info['module']);
|
2022-05-03 12:51:05 +02:00
|
|
|
$insert['is_record'] = $info['is_record'];
|
2024-04-05 16:07:27 +02:00
|
|
|
$insert_lang['filename'] = $info['filename'];
|
2022-05-03 12:51:05 +02:00
|
|
|
$insert['icon'] = $info['icon'];
|
|
|
|
}
|
2018-07-04 17:15:14 +02:00
|
|
|
|
|
|
|
// Copia dei file nella cartella relativa
|
2020-09-23 13:36:37 +02:00
|
|
|
copyr(dirname($file->getRealPath()), base_dir().'/'.$directory.'/'.$info['directory']);
|
2018-07-04 17:15:14 +02:00
|
|
|
|
|
|
|
// Eventuale registrazione nel database
|
|
|
|
if (empty($installed)) {
|
|
|
|
$dbo->insert($table, array_merge($insert, [
|
|
|
|
'directory' => $info['directory'],
|
|
|
|
'options' => $info['options'],
|
|
|
|
'version' => $info['version'],
|
|
|
|
'compatibility' => $info['compatibility'],
|
|
|
|
'order' => 100,
|
|
|
|
'default' => 0,
|
|
|
|
'enabled' => 1,
|
|
|
|
]));
|
2024-03-13 09:47:05 +01:00
|
|
|
$id_record = $dbo->lastInsertedID();
|
2024-04-05 16:07:27 +02:00
|
|
|
$dbo->insert($table.'_lang', array_merge($insert_lang, [
|
2024-03-13 09:47:05 +01:00
|
|
|
'name' => $info['name'],
|
|
|
|
'title' => !empty($info['title']) ? $info['title'] : $info['name'],
|
|
|
|
'id_record' => $id_record,
|
2024-03-22 15:52:24 +01:00
|
|
|
'id_lang' => Models\Locale::getDefault()->id,
|
2024-04-05 16:07:27 +02:00
|
|
|
]));
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->error(tr('Installazione completata!'));
|
2018-07-04 17:15:14 +02:00
|
|
|
} else {
|
2018-07-19 17:29:21 +02:00
|
|
|
flash()->error(tr('Aggiornamento completato!'));
|
2018-07-04 17:15:14 +02:00
|
|
|
}
|
2018-07-04 15:38:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 17:15:14 +02:00
|
|
|
// Rimozione delle risorse inutilizzate
|
2018-07-04 15:38:10 +02:00
|
|
|
delete($extraction_dir);
|
2018-07-04 17:15:14 +02:00
|
|
|
|
|
|
|
// Redirect
|
2020-09-23 17:53:19 +02:00
|
|
|
redirect(base_path().'/editor.php?id_module='.$id_module);
|