From 51b50972c83bb64d0ff015e0ead666b5ff3a97df Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Thu, 30 Jan 2020 14:59:48 -0500 Subject: [PATCH] Try to clear caches before updating (#522) * Try to clear caches before updating * Add clear-compiled to maintenance cache list * Formatting --- app/Contracts/Migration.php | 18 ++++++++++++++++++ .../Admin/MaintenanceController.php | 1 + app/Services/Installer/InstallerService.php | 18 ++++++++++++++++++ .../Http/Controllers/UpdateController.php | 2 ++ 4 files changed, 39 insertions(+) diff --git a/app/Contracts/Migration.php b/app/Contracts/Migration.php index c06efea7..5192b8fb 100644 --- a/app/Contracts/Migration.php +++ b/app/Contracts/Migration.php @@ -2,7 +2,9 @@ namespace App\Contracts; +use App\Support\Database; use DB; +use Illuminate\Support\Facades\Log; /** * Class Migration @@ -23,6 +25,22 @@ abstract class Migration extends \Illuminate\Database\Migrations\Migration { } + /** + * Seed a YAML file into the database + * + * @param string $file Full path to yml file to seed + */ + public function seedFile($file): void + { + try { + $path = base_path($file); + Database::seed_from_yaml_file($path, false); + } catch (\Exception $e) { + Log::error('Unable to load '.$file.' file'); + Log::error($e); + } + } + /** * Add rows to a table * diff --git a/app/Http/Controllers/Admin/MaintenanceController.php b/app/Http/Controllers/Admin/MaintenanceController.php index 8f1470e8..92264e2d 100644 --- a/app/Http/Controllers/Admin/MaintenanceController.php +++ b/app/Http/Controllers/Admin/MaintenanceController.php @@ -42,6 +42,7 @@ class MaintenanceController extends Controller $calls[] = 'config:cache'; $calls[] = 'cache:clear'; $calls[] = 'route:cache'; + $calls[] = 'clear-compiled'; } // If we want to clear only the views but keep everything else diff --git a/app/Services/Installer/InstallerService.php b/app/Services/Installer/InstallerService.php index f0ccdb35..dde48a75 100644 --- a/app/Services/Installer/InstallerService.php +++ b/app/Services/Installer/InstallerService.php @@ -3,6 +3,7 @@ namespace App\Services\Installer; use App\Contracts\Service; +use Illuminate\Support\Facades\Artisan; use Nwidart\Modules\Facades\Module; class InstallerService extends Service @@ -38,6 +39,23 @@ class InstallerService extends Service return false; } + /** + * Clear whatever caches we can by calling Artisan + */ + public function clearCaches(): void + { + $commands = [ + 'clear-compiled', + 'cache:clear', + 'route:clear', + 'view:clear', + ]; + + foreach ($commands as $cmd) { + Artisan::call($cmd); + } + } + /** * Disable the installer and importer modules */ diff --git a/modules/Updater/Http/Controllers/UpdateController.php b/modules/Updater/Http/Controllers/UpdateController.php index 406f96ec..ea205d57 100644 --- a/modules/Updater/Http/Controllers/UpdateController.php +++ b/modules/Updater/Http/Controllers/UpdateController.php @@ -49,6 +49,8 @@ class UpdateController extends Controller */ public function step1(Request $request) { + $this->installerSvc->clearCaches(); + if ($this->installerSvc->isUpgradePending()) { Log::info('Upgrade is pending'); }