FIX: fix cache-related bug

This commit is contained in:
Michal Kváček
2017-09-13 14:34:55 +02:00
parent 7db8241a80
commit a41cb68a0a
2 changed files with 15 additions and 17 deletions
+12 -14
View File
@@ -1,10 +1,12 @@
<?php
namespace Templates\Base\OnePage\Http\Controllers\Admin;
use App\CMS\Contracts\Repositories\Content as IContent;
use App\CMS\Helpers\Settings;
use App\Http\Controllers\Admin\Controller;
use App\Models\Settings as SettingsModel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Templates\Base\OnePage\Events\AddPageIntoHomepage;
@@ -32,7 +34,6 @@ class SetHomepage extends Controller
/**
* Display form for organizing pages on homepage
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getPages()
@@ -90,18 +91,11 @@ class SetHomepage extends Controller
}
// try to get page config
$settingsEntry = SettingsModel::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
->where('language', LaravelLocalization::getCurrentLocale())
->first();
if (!$settingsEntry) {
$settingsEntry = new SettingsModel();
$settingsEntry->language = LaravelLocalization::getCurrentLocale();
$settingsEntry->key = OnePage::HOMEPAGE_PAGES_SETTINGS_KEY;
$usedPagesIds = [];
} else {
$usedPagesIds = (array)json_decode($settingsEntry->value);
}
$settingsEntry = SettingsModel::firstOrCreate([
'language' => LaravelLocalization::getCurrentLocale(),
'key' => OnePage::HOMEPAGE_PAGES_SETTINGS_KEY
]);
$usedPagesIds = (array)json_decode($settingsEntry->value);
// add page into list of used pages - if not already there
if (!in_array($id, $usedPagesIds)) {
@@ -111,6 +105,8 @@ class SetHomepage extends Controller
$settingsEntry->value = json_encode($usedPagesIds);
$settingsEntry->save();
Cache::forget('settings');
// inform other application parts about this event
Event::fire(new AddPageIntoHomepage($page));
@@ -145,10 +141,12 @@ class SetHomepage extends Controller
$pages = array_values($pages);
// update in database
SettingsModel::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
$val = SettingsModel::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
->where('language', LaravelLocalization::getCurrentLocale())
->update(['value' => json_encode($pages)]);
Cache::forget('settings');
// inform other application parts about this event
Event::fire(new RemovePageFromHomepage($page));
@@ -14,7 +14,7 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
@if(isset($homepage))
@include('admin.snippets.card', [
'type' => 'primary',
'title' => $homepage->title.' <small>'.trans($homepage->module_name).'</small>',
'title' => $homepage->title.' <small>'.trans($homepage->module->name).'</small>',
'body' => '<p>'.str_limit(strip_tags($homepage->content), 200).'</p>',
'footerClass' => 'text-right',
'footer' => '<a href="'.route('content.edit', ['page' => $homepage]).'" class="btn btn-secondary btn-sm"><i class="fa fa-fw fa-pencil"></i></a>'
@@ -34,7 +34,7 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
@include('admin.snippets.card', [
'title' => $allPages[$pageId]->title.' <small>'.trans($allPages[$pageId]->module_name).'</small>',
'title' => $allPages[$pageId]->title.' <small>'.trans($allPages[$pageId]->module->name).'</small>',
'body' => '<p>'.str_limit(strip_tags($allPages[$pageId]->content), 200).'</p>',
'footerClass' => 'text-right',
'footer' => '
@@ -55,7 +55,7 @@ Improvement: http://www.html5rocks.com/en/tutorials/dnd/basics/
<div class="card-header">
<div class="header-block">
<p class="title">{{$page->title}}
<small>@lang($page->module_name)</small>
<small>@lang($page->module->name)</small>
</p>
</div>
</div>