mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Aggiunto controllo sullo spazio disponibile prima del Backup
Stile del codice
This commit is contained in:
parent
a408a86593
commit
1136adbb2b
@ -20,8 +20,6 @@
|
||||
namespace Modules\Aggiornamenti\Controlli;
|
||||
|
||||
use Models\Module;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Util\XML;
|
||||
|
||||
class ColonneDuplicateViste extends Controllo
|
||||
{
|
||||
|
@ -55,11 +55,17 @@ switch (filter('op')) {
|
||||
break;
|
||||
|
||||
case 'backup':
|
||||
if (Backup::create()) {
|
||||
try {
|
||||
$result = Backup::create();
|
||||
|
||||
if ($result) {
|
||||
flash()->info(tr('Nuovo backup creato correttamente!'));
|
||||
} else {
|
||||
flash()->error(tr('Errore durante la creazione del backup!').' '.str_replace('_DIR_', '"'.$backup_dir.'"', tr('Verifica che la cartella _DIR_ abbia i permessi di scrittura!')));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
flash()->error(tr('Errore durante la creazione del backup!').' '.$e->getMessage());
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
@ -80,7 +80,7 @@ function restore() {
|
||||
}
|
||||
|
||||
// Creazione backup
|
||||
function backup(){
|
||||
function creaBackup(button){
|
||||
swal({
|
||||
title: "'.tr('Nuovo backup').'",
|
||||
text: "'.tr('Sei sicuro di voler creare un nuovo backup?').'",
|
||||
@ -88,10 +88,32 @@ function backup(){
|
||||
showCancelButton: true,
|
||||
confirmButtonClass: "btn btn-lg btn-success",
|
||||
confirmButtonText: "'.tr('Crea').'",
|
||||
}).then(
|
||||
function() {
|
||||
location.href = globals.rootdir + "/editor.php?id_module='.$id_module.'&op=backup";
|
||||
}, function() {});
|
||||
}).then(function() {
|
||||
let restore = buttonLoading(button);
|
||||
$("#main_loading").show();
|
||||
|
||||
$.ajax({
|
||||
url: globals.rootdir + "/actions.php",
|
||||
type: "GET",
|
||||
data: {
|
||||
id_module: globals.id_module,
|
||||
op: "backup",
|
||||
},
|
||||
success: function(data) {
|
||||
$("#main_loading").fadeOut();
|
||||
buttonRestore(button, restore);
|
||||
|
||||
// Ricaricamento della pagina corrente
|
||||
window.location.reload();
|
||||
},
|
||||
error: function() {
|
||||
swal("'.tr('Errore').'", "'.tr('Errore durante la creazione del backup').'", "error");
|
||||
renderMessages();
|
||||
|
||||
buttonRestore(button, restore);
|
||||
}
|
||||
});
|
||||
}).catch(swal.noop);
|
||||
}
|
||||
|
||||
// Caricamento
|
||||
@ -100,7 +122,7 @@ function loadSize(number, id){
|
||||
|
||||
$.ajax({
|
||||
url: globals.rootdir + "/actions.php",
|
||||
type: "get",
|
||||
type: "GET",
|
||||
data: {
|
||||
id_module: globals.id_module,
|
||||
op: "size",
|
||||
@ -294,7 +316,9 @@ if (file_exists($backup_dir)) {
|
||||
// Creazione backup
|
||||
if (!empty($backup_dir)) {
|
||||
echo '
|
||||
<button type="button" class="btn btn-primary pull-right" onclick="backup()"><i class="fa fa-database"></i> '.tr('Crea backup').'...</button>
|
||||
<button type="button" class="btn btn-primary pull-right" onclick="creaBackup(this)">
|
||||
<i class="fa fa-database"></i> '.tr('Crea backup').'...
|
||||
</button>
|
||||
|
||||
<div class="clearfix"></div>';
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
use Modules\Articoli\Articolo as ArticoloOriginale;
|
||||
use Modules\DDT\DDT;
|
||||
use Modules\Fatture\Components\Articolo;
|
||||
use Modules\Fatture\Components\Descrizione;
|
||||
use Modules\Fatture\Components\Riga;
|
||||
|
@ -464,7 +464,7 @@ class Fattura extends Document
|
||||
|
||||
$file = $this->uploads()->where('name', '=', 'Fattura Elettronica')->first();
|
||||
if (empty($file)) {
|
||||
throw new InvalidArgumentException("Fattura Elettronica non trovata");
|
||||
throw new InvalidArgumentException('Fattura Elettronica non trovata');
|
||||
}
|
||||
|
||||
return $file->getContent();
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
use Ifsnop\Mysqldump\Mysqldump;
|
||||
use Util\FileSystem;
|
||||
use Util\Generator;
|
||||
use Util\Zip;
|
||||
|
||||
@ -148,6 +149,8 @@ class Backup
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
self::checkSpace();
|
||||
|
||||
$backup_dir = self::getDirectory();
|
||||
$backup_name = self::getNextName();
|
||||
|
||||
@ -276,6 +279,40 @@ class Backup
|
||||
delete(base_dir().'/database.sql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Effettua i controlli relativi allo spazio disponibile per l'esecuzione del backup;.
|
||||
*/
|
||||
public static function checkSpace()
|
||||
{
|
||||
$scarto = 1.1;
|
||||
|
||||
// Informazioni di base sui limiti di spazio
|
||||
$spazio_libero = disk_free_space('.');
|
||||
if (!empty(setting('Soft quota'))) {
|
||||
$soft_quota = (float) setting('Soft quota'); // Impostazione in GB
|
||||
$soft_quota = $soft_quota * (1024 ** 3); // Trasformazione in GB
|
||||
}
|
||||
|
||||
// Informazioni sullo spazio occupato
|
||||
$spazio_occupato = $spazio_necessario = FileSystem::folderSize(base_dir(), ['htaccess']);
|
||||
$cartelle_ignorate = [
|
||||
self::getDirectory(),
|
||||
'node_modules',
|
||||
'tests',
|
||||
'tmp',
|
||||
];
|
||||
foreach ($cartelle_ignorate as $path) {
|
||||
$spazio_necessario -= FileSystem::folderSize($path);
|
||||
}
|
||||
|
||||
// Errori visualizzati
|
||||
if (isset($soft_quota) && $soft_quota < ($spazio_necessario + $spazio_occupato) * $scarto) {
|
||||
throw new InvalidArgumentException('Spazio disponibile in esaurimento');
|
||||
} elseif ($spazio_libero < ($spazio_necessario) * $scarto) {
|
||||
throw new InvalidArgumentException('Spazio del server in esaurimento');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restituisce il percorso su cui salvare temporaneamente il dump del database.
|
||||
*
|
||||
|
@ -78,6 +78,7 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
|
||||
|
||||
/**
|
||||
* Restituisce tutte le righe collegate al documento.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection|iterable
|
||||
*/
|
||||
public function getRighe()
|
||||
@ -91,8 +92,10 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
|
||||
|
||||
/**
|
||||
* Restituisce la riga con tipo e identificativo corrispondente.
|
||||
*
|
||||
* @param $type
|
||||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRiga($type, $id)
|
||||
@ -106,6 +109,7 @@ abstract class Document extends Model implements ReferenceInterface, DocumentInt
|
||||
|
||||
/**
|
||||
* Restituisce le righe del documento raggruppate per documento di origine.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection|iterable
|
||||
*/
|
||||
public function getRigheRaggruppate()
|
||||
|
Loading…
x
Reference in New Issue
Block a user