1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-26 15:54:17 +01:00
openstamanager/modules/aggiornamenti/upload_modules.php

97 lines
2.9 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/../../core.php';
2018-09-19 16:51:37 +02:00
use Util\Zip;
2018-07-08 18:11:17 +02:00
if (!setting('Attiva aggiornamenti')) {
die(tr('Accesso negato'));
}
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_', [
'_FILE_' => '<b>php.ini</b>',
]));
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
$config = file_get_contents($docroot.'/config.inc.php');
// Copia i file dalla cartella temporanea alla root
copyr($extraction_dir, $docroot);
// Ripristina il file di configurazione dell'installazione
file_put_contents($docroot.'/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);
$files = $finder->name('MODULE')->name('PLUGIN');
foreach ($files as $file) {
// 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';
$installed = Modules::get($info['name']);
2019-02-21 15:09:11 +01:00
$insert['parent'] = Modules::get($info['parent'])['id'];
2018-09-21 16:02:33 +02:00
$insert['icon'] = $info['icon'];
2018-07-04 17:15:14 +02:00
}
// Plugin
elseif (basename($file->getRealPath()) == 'PLUGIN') {
$directory = 'plugins';
$table = 'zz_plugins';
$installed = Plugins::get($info['name']);
$insert['idmodule_from'] = Modules::get($info['module_from'])['id'];
$insert['idmodule_to'] = Modules::get($info['module_to'])['id'];
$insert['position'] = $info['position'];
}
// Copia dei file nella cartella relativa
copyr(dirname($file->getRealPath()), $docroot.'/'.$directory.'/'.$info['directory']);
// Eventuale registrazione nel database
if (empty($installed)) {
$dbo->insert($table, array_merge($insert, [
'name' => $info['name'],
'title' => !empty($info['title']) ? $info['title'] : $info['name'],
'directory' => $info['directory'],
'options' => $info['options'],
'version' => $info['version'],
'compatibility' => $info['compatibility'],
'order' => 100,
'default' => 0,
'enabled' => 1,
]));
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
redirect(ROOTDIR.'/editor.php?id_module='.$id_module);