mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
Fix cleaning options cache
This commit is contained in:
parent
5465399eda
commit
eb0818dc27
@ -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 = '<?php'.PHP_EOL.'return '.$content.';';
|
||||
$filesystem->put(storage_path('options/cache.php'), $content);
|
||||
$filesystem->put($path, $content);
|
||||
$this->info('Options cached successfully.');
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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')]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user