From a8d500e6749b5d18f487385af32d2b23cb0db904 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Mon, 2 Aug 2021 15:01:43 +0200 Subject: [PATCH] Ottimizzazione procedura di configurazione iniziale --- app/Http/Controllers/UpdateController.php | 7 ++++- app/Http/Middleware/EnsureConfiguration.php | 33 +++++++++++++++++++++ composer.json | 1 - 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index 37d8c77f1..77ab37280 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -70,6 +70,11 @@ class UpdateController extends Controller { $migrator = self::getMigrator(); + // Fallback per creazione tabella di migrazioni + if (!$migrator->getRepository()->repositoryExists()) { + $migrator->getRepository()->createRepository(); + } + $paths = array_merge( $migrator->paths(), [app()->databasePath().DIRECTORY_SEPARATOR.'migrations'] @@ -144,7 +149,7 @@ class UpdateController extends Controller $result = Update::doUpdate(self::$legacyUpdateRate); $rate = 0; - if (is_array($result)) { + if (!is_bool($result) && is_array($result)) { $rate = $result[1] - $result[0]; } elseif (!empty($update['script'])) { $rate = self::$legacyScriptValue; diff --git a/app/Http/Middleware/EnsureConfiguration.php b/app/Http/Middleware/EnsureConfiguration.php index 50b5a4513..fbb1c4de6 100644 --- a/app/Http/Middleware/EnsureConfiguration.php +++ b/app/Http/Middleware/EnsureConfiguration.php @@ -8,6 +8,7 @@ use App\Http\Controllers\RequirementsController; use App\Http\Controllers\UpdateController; use Closure; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; class EnsureConfiguration { @@ -70,10 +71,18 @@ class EnsureConfiguration */ protected function checkRequirements($route) { + // Controllo nella cache per evitare controlli in sequenza + $completed = Cache::get('requisiti_soddisfatti'); + if ($completed) { + return true; + } + $configuration_paths = ['requirements']; $requirements_satisfied = RequirementsController::isSatisfied(); if ($requirements_satisfied) { + Cache::put('requisiti_soddisfatti', true); + // Redirect nel caso in cui i requisiti siano soddisfatti if (in_array($route->getName(), $configuration_paths)) { $this->setRedirect(route('configuration')); @@ -97,10 +106,18 @@ class EnsureConfiguration */ protected function checkConfiguration($route) { + // Controllo nella cache per evitare controlli in sequenza + $completed = Cache::get('configurazione_completata'); + if ($completed) { + return true; + } + $configuration_paths = ['configuration', 'configuration-save', 'configuration-write', 'configuration-test']; $configuration_completed = ConfigurationController::isConfigured(); if ($configuration_completed) { + Cache::put('configurazione_completata', true); + // Redirect nel caso in cui la configurazione sia correttamente funzionante if (in_array($route->getName(), $configuration_paths)) { $this->setRedirect(route('update')); @@ -124,10 +141,18 @@ class EnsureConfiguration */ protected function checkMigrations($route) { + // Controllo nella cache per evitare controlli in sequenza + $completed = Cache::get('aggiornamenti_eseguiti'); + if ($completed) { + return true; + } + $update_paths = ['update', 'update-execute']; $update_completed = UpdateController::isCompleted(); if ($update_completed) { + Cache::put('aggiornamenti_eseguiti', true); + // Redirect nel caso in cui la configurazione sia correttamente funzionante if (in_array($route->getName(), $update_paths)) { $this->setRedirect(route('initialization')); @@ -151,10 +176,18 @@ class EnsureConfiguration */ protected function checkInitialization($route) { + // Controllo nella cache per evitare controlli in sequenza + $completed = Cache::get('inizializzazione_completata'); + if ($completed) { + return true; + } + $initialization_paths = ['initialization', 'initialization-save']; $initialization_completed = InitializationController::isInitialized(); if ($initialization_completed) { + Cache::put('inizializzazione_completata', true); + // Redirect nel caso in cui la configurazione sia correttamente funzionante if (in_array($route->getName(), $initialization_paths)) { $this->setRedirect(route('login')); diff --git a/composer.json b/composer.json index 837cb3daa..707d40623 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,6 @@ "league/csv": "^8.2", "mpdf/mpdf": "^8.0.10", "mpociot/vat-calculator": "^2.3", - "nwidart/laravel-modules": "^8.2", "owasp/csrf-protector-php": "^1.0", "phpmailer/phpmailer": "^6.0", "respect/validation": "^1.1",