diff --git a/app/Console/Commands/OptionsCacheCommand.php b/app/Console/Commands/OptionsCacheCommand.php index 66213474..db5eadc4 100644 --- a/app/Console/Commands/OptionsCacheCommand.php +++ b/app/Console/Commands/OptionsCacheCommand.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Services\Option; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; +use Illuminate\Foundation\Application; class OptionsCacheCommand extends Command { @@ -12,11 +13,15 @@ class OptionsCacheCommand extends Command protected $description = 'Cache Blessing Skin options'; - public function handle(Filesystem $filesystem, Option $options) + public function handle(Filesystem $filesystem, Application $app) { - $content = var_export($options->all(), true); + $path = storage_path('options/cache.php'); + $filesystem->delete($path); + $app->forgetInstance(Option::class); + + $content = var_export(resolve(Option::class)->all(), true); $content = 'put(storage_path('options/cache.php'), $content); + $filesystem->put($path, $content); $this->info('Options cached successfully.'); } } diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index accf7f77..fb123fc9 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -7,6 +7,7 @@ use Illuminate\Support\Arr; use Illuminate\Http\Request; use Composer\Semver\Comparator; use App\Services\PackageManager; +use Illuminate\Filesystem\Filesystem; class UpdateController extends Controller { @@ -40,7 +41,7 @@ class UpdateController extends Controller return json(['available' => $this->canUpdate()]); } - public function download(Request $request, PackageManager $package) + public function download(Request $request, PackageManager $package, Filesystem $filesystem) { if (! $this->canUpdate()) { return json([]); @@ -52,6 +53,9 @@ class UpdateController extends Controller try { $package->download($this->info['url'], $path)->extract(base_path()); + // Delete options cache. This allows us to update the version info which is recorded as an option. + $filesystem->delete(storage_path('options/cache.php')); + return json(trans('admin.update.complete'), 0); } catch (Exception $e) { report($e); diff --git a/tests/CommandsTest/OptionsCacheCommandTest.php b/tests/CommandsTest/OptionsCacheCommandTest.php index dd41291a..65497c64 100644 --- a/tests/CommandsTest/OptionsCacheCommandTest.php +++ b/tests/CommandsTest/OptionsCacheCommandTest.php @@ -11,6 +11,7 @@ class OptionsCacheCommandTest extends TestCase { $this->mock(Filesystem::class, function ($mock) { $mock->shouldReceive('exists')->andReturn(false); + $mock->shouldReceive('delete')->with(storage_path('options/cache.php'))->once(); $mock->shouldReceive('put') ->withArgs(function ($path, $content) { $this->assertEquals(storage_path('options/cache.php'), $path); diff --git a/tests/UpdateControllerTest.php b/tests/UpdateControllerTest.php index 7ca93004..d85a5797 100644 --- a/tests/UpdateControllerTest.php +++ b/tests/UpdateControllerTest.php @@ -89,6 +89,9 @@ class UpdateControllerTest extends TestCase $mock->shouldReceive('extract')->andReturn(true); $mock->shouldReceive('progress'); }); + $this->mock(\Illuminate\Filesystem\Filesystem::class, function ($mock) { + $mock->shouldReceive('delete')->with(storage_path('options/cache.php'))->once(); + }); $this->getJson('/admin/update/download?action=download') ->assertJson(['code' => 0, 'message' => trans('admin.update.complete')]);