Skip to content

Commit

Permalink
Try to clear caches before updating (#522)
Browse files Browse the repository at this point in the history
* Try to clear caches before updating

* Add clear-compiled to maintenance cache list

* Formatting
  • Loading branch information
nabeelio authored Jan 30, 2020
1 parent 3c1b433 commit 51b5097
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/Contracts/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Contracts;

use App\Support\Database;
use DB;
use Illuminate\Support\Facades\Log;

/**
* Class Migration
Expand All @@ -23,6 +25,22 @@ public function down()
{
}

/**
* 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
*
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Admin/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function cache(Request $request)
$calls[] = 'config:cache';
$calls[] = 'cache:clear';
$calls[] = 'route:cache';
$calls[] = 'clear-compiled';
}

// If we want to clear only the views but keep everything else
Expand Down
18 changes: 18 additions & 0 deletions app/Services/Installer/InstallerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,6 +39,23 @@ public function isUpgradePending(): bool
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
*/
Expand Down
2 changes: 2 additions & 0 deletions modules/Updater/Http/Controllers/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function index()
*/
public function step1(Request $request)
{
$this->installerSvc->clearCaches();

if ($this->installerSvc->isUpgradePending()) {
Log::info('Upgrade is pending');
}
Expand Down

0 comments on commit 51b5097

Please sign in to comment.