Correzioni per esecuzione aggiornamenti
This commit is contained in:
parent
011b33baf3
commit
735d3b2bf9
|
@ -613,7 +613,7 @@ function apriTab(link) {
|
||||||
function ajaxError(xhr, error, thrown) {
|
function ajaxError(xhr, error, thrown) {
|
||||||
swal({
|
swal({
|
||||||
title: globals.translations.errorTitle,
|
title: globals.translations.errorTitle,
|
||||||
html: globals.translations.errorMessage + (xhr.responseJSON ? ".<br><i>" + xhr.responseJSON.exception[0].message + "</i>" : ''),
|
html: globals.translations.errorMessage + (xhr.responseJSON ? ".<br><i>" + xhr.responseJSON.exception + ": " + xhr.responseJSON.message + "</i>" : ""),
|
||||||
type: "error",
|
type: "error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,12 +27,6 @@ use Illuminate\Support\Facades\Schema;
|
||||||
*/
|
*/
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
/** @var \Illuminate\Database\Capsule\Manager Gestore di connessione Laravel */
|
|
||||||
protected $capsule;
|
|
||||||
|
|
||||||
/** @var string Nome del database */
|
|
||||||
protected $database_name;
|
|
||||||
|
|
||||||
/** @var bool Stato di connessione del database */
|
/** @var bool Stato di connessione del database */
|
||||||
protected $is_connected;
|
protected $is_connected;
|
||||||
/** @var bool Stato di installazione del database */
|
/** @var bool Stato di installazione del database */
|
||||||
|
@ -122,7 +116,7 @@ class Database
|
||||||
*/
|
*/
|
||||||
public function getDatabaseName()
|
public function getDatabaseName()
|
||||||
{
|
{
|
||||||
return $this->database_name;
|
return DB::connection()->getDatabaseName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
147
src/Update.php
147
src/Update.php
|
@ -241,94 +241,85 @@ class Update
|
||||||
if (!self::isUpdateCompleted()) {
|
if (!self::isUpdateCompleted()) {
|
||||||
$update = self::getCurrentUpdate();
|
$update = self::getCurrentUpdate();
|
||||||
|
|
||||||
$file = base_dir().'/'.$update['directory'].$update['filename'];
|
$file = slashes(base_dir().substr($update['directory'], 1).$update['filename']);
|
||||||
|
|
||||||
$database = database();
|
$database = database();
|
||||||
|
|
||||||
try {
|
// Esecuzione delle query
|
||||||
// Esecuzione delle query
|
if (!empty($update['sql']) && (!empty($update['done']) || is_null($update['done'])) && file_exists($file.'.sql')) {
|
||||||
if (!empty($update['sql']) && (!empty($update['done']) || is_null($update['done'])) && file_exists($file.'.sql')) {
|
$queries = readSQLFile($file.'.sql', ';');
|
||||||
$queries = readSQLFile($file.'.sql', ';');
|
$count = count($queries);
|
||||||
$count = count($queries);
|
|
||||||
|
|
||||||
$start = empty($update['done']) ? 0 : $update['done'] - 2;
|
$start = empty($update['done']) ? 0 : $update['done'] - 2;
|
||||||
$end = ($start + $rate + 1) > $count ? $count : $start + $rate + 1;
|
$end = ($start + $rate + 1) > $count ? $count : $start + $rate + 1;
|
||||||
|
|
||||||
if ($start < $end) {
|
if ($start < $end) {
|
||||||
for ($i = $start; $i < $end; ++$i) {
|
for ($i = $start; $i < $end; ++$i) {
|
||||||
try {
|
try {
|
||||||
$database->query($queries[$i]);
|
$database->query($queries[$i]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new PDOException(tr('Aggiornamento fallito').': '.$queries[$i]);
|
throw new PDOException($queries[$i]);
|
||||||
}
|
|
||||||
|
|
||||||
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
|
||||||
':done' => $i + 3,
|
|
||||||
':id' => $update['id'],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restituisce l'indice della prima e dell'ultima query eseguita, con la differenza relativa per l'avanzamento dell'aggiornamento
|
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
||||||
return [
|
':done' => $i + 3,
|
||||||
$start,
|
':id' => $update['id'],
|
||||||
$end,
|
]);
|
||||||
$count,
|
}
|
||||||
|
|
||||||
|
// Restituisce l'indice della prima e dell'ultima query eseguita, con la differenza relativa per l'avanzamento dell'aggiornamento
|
||||||
|
return [
|
||||||
|
$start,
|
||||||
|
$end,
|
||||||
|
$count,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta l'aggiornamento nello stato di esecuzione dello script
|
||||||
|
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
||||||
|
':done' => 0,
|
||||||
|
':id' => $update['id'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Permessi di default delle viste
|
||||||
|
if ($database->tableExists('zz_views')) {
|
||||||
|
$gruppi = $database->fetchArray('SELECT `id` FROM `zz_groups`');
|
||||||
|
$viste = $database->fetchArray('SELECT `id` FROM `zz_views` WHERE `id` NOT IN (SELECT `id_vista` FROM `zz_group_view`)');
|
||||||
|
|
||||||
|
$array = [];
|
||||||
|
foreach ($viste as $vista) {
|
||||||
|
foreach ($gruppi as $gruppo) {
|
||||||
|
$array[] = [
|
||||||
|
'id_gruppo' => $gruppo['id'],
|
||||||
|
'id_vista' => $vista['id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!empty($array)) {
|
||||||
// Imposta l'aggiornamento nello stato di esecuzione dello script
|
$database->insert('zz_group_view', $array);
|
||||||
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
|
||||||
':done' => 0,
|
|
||||||
':id' => $update['id'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Permessi di default delle viste
|
|
||||||
if ($database->tableExists('zz_views')) {
|
|
||||||
$gruppi = $database->fetchArray('SELECT `id` FROM `zz_groups`');
|
|
||||||
$viste = $database->fetchArray('SELECT `id` FROM `zz_views` WHERE `id` NOT IN (SELECT `id_vista` FROM `zz_group_view`)');
|
|
||||||
|
|
||||||
$array = [];
|
|
||||||
foreach ($viste as $vista) {
|
|
||||||
foreach ($gruppi as $gruppo) {
|
|
||||||
$array[] = [
|
|
||||||
'id_gruppo' => $gruppo['id'],
|
|
||||||
'id_vista' => $vista['id'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($array)) {
|
|
||||||
$database->insert('zz_group_view', $array);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalizzazione di charset e collation
|
|
||||||
self::normalizeDatabase($database->getDatabaseName());
|
|
||||||
|
|
||||||
// Normalizzazione dei campi per l'API
|
|
||||||
self::executeScript(base_dir().'/update/api.php');
|
|
||||||
|
|
||||||
// Esecuzione dello script
|
|
||||||
if (!empty($update['script']) && file_exists($file.'.php')) {
|
|
||||||
self::executeScript($file.'.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Imposta l'aggiornamento come completato
|
|
||||||
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
|
||||||
':done' => 1,
|
|
||||||
':id' => $update['id'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Normalizzazione di charset e collation
|
|
||||||
self::normalizeDatabase($database->getDatabaseName());
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$logger = logger();
|
|
||||||
$logger->addRecord(\Monolog\Logger::EMERGENCY, $e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
// Normalizzazione di charset e collation
|
||||||
|
self::normalizeDatabase($database->getDatabaseName());
|
||||||
|
|
||||||
|
// Normalizzazione dei campi per l'API
|
||||||
|
self::executeScript(base_dir().'/update/api.php');
|
||||||
|
|
||||||
|
// Esecuzione dello script
|
||||||
|
if (!empty($update['script']) && file_exists($file.'.php')) {
|
||||||
|
self::executeScript($file.'.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imposta l'aggiornamento come completato
|
||||||
|
$database->query('UPDATE `updates` SET `done` = :done WHERE id = :id', [
|
||||||
|
':done' => 1,
|
||||||
|
':id' => $update['id'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Normalizzazione di charset e collation
|
||||||
|
self::normalizeDatabase($database->getDatabaseName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -437,8 +428,8 @@ class Update
|
||||||
// Inserimento degli aggiornamenti individuati
|
// Inserimento degli aggiornamenti individuati
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
// Individuazione di script e sql
|
// Individuazione di script e sql
|
||||||
$sql = file_exists($result['path'].'.sql') ? 1 : 0;
|
$sql = file_exists(base_dir().$result['path'].'.sql') ? 1 : 0;
|
||||||
$script = file_exists($result['path'].'.php') ? 1 : 0;
|
$script = file_exists(base_dir().$result['path'].'.php') ? 1 : 0;
|
||||||
|
|
||||||
// Reimpostazione degli stati per gli aggiornamenti precedentemente presenti
|
// Reimpostazione degli stati per gli aggiornamenti precedentemente presenti
|
||||||
$pos = array_search($result['path'], $versions);
|
$pos = array_search($result['path'], $versions);
|
||||||
|
@ -574,6 +565,8 @@ class Update
|
||||||
*/
|
*/
|
||||||
protected static function normalizeDatabase($database_name)
|
protected static function normalizeDatabase($database_name)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
ignore_user_abort(true);
|
ignore_user_abort(true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue