FEATURE #1374: add logging for static pages

This commit is contained in:
Michal Kváček
2016-01-29 01:57:12 +01:00
parent 593506c646
commit ee55715093
16 changed files with 424 additions and 35 deletions
@@ -3,6 +3,11 @@ namespace Modules\StaticPages\Http\Controllers\Admin;
use App\Enumerations\ContentStatuses;
use App\Models\Content;
use Illuminate\Support\Facades\Event;
use Modules\StaticPages\Events\DeleteStaticPage;
use Modules\StaticPages\Events\EditStaticPage as EditStaticPageEvent;
use Modules\StaticPages\Events\MakeDraftFromStaticPage;
use Modules\StaticPages\Events\PublishStaticPage;
use Modules\StaticPages\Http\Requests\EditStaticPageRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -65,7 +70,7 @@ class EditStaticPage extends Controller
];
// save new values with history
$changedColumns = $page->updateWithHistory($fields, $request);
list($revision, $changedColumns) = $page->updateWithHistory($fields, $request->all());
// was something changed?
if ($changedColumns == 0) {
@@ -74,6 +79,9 @@ class EditStaticPage extends Controller
->with('error', trans('staticpages::admin.nothingToEdit'));
}
// fire event with
Event::fire(new EditStaticPageEvent($page, $revision));
// something was changed, inform user
return redirect()
->route('staticpage.edit', ['id' => $page->id])
@@ -108,22 +116,34 @@ class EditStaticPage extends Controller
// try to find this page
$page = Content::where('module_handler', config('staticpages.handler'))
->findOrFail($id);
// page found, save status
$page->status = $status;
$page->save();
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.statusChanged'));
} catch (NotFoundHttpException $e) {
// page not found
return redirect()
->route('staticpage.overview')
->with('error', trans('staticpages::admin.invalidPage'));
}
// try to change the page
list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => $status]);
// was something changed?
if ($changedColumns == 0) {
return redirect()
->route('staticpage.edit', ['id' => $page->id])
->with('error', trans('staticpages::admin.nothingToEdit'));
}
// fire events
if ($status != Content::STATUS_DRAFT) {
Event::fire(new PublishStaticPage($page, $revision));
} else {
Event::fire(new MakeDraftFromStaticPage($page, $revision));
}
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.statusChanged'));
}
/**
@@ -139,24 +159,31 @@ class EditStaticPage extends Controller
// try to find this page
$page = Content::where('module_handler', config('staticpages.handler'))
->findOrFail($id);
// page found, save status
$page->status = Content::STATUS_DELETED;
$page->save();
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.pageDeleted', [
'name' => $page->title,
'url' => $page->url
]));
} catch (NotFoundHttpException $e) {
// page not found
return redirect()
->route('staticpage.overview')
->with('error', trans('staticpages::admin.invalidPage'));
}
list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => Content::STATUS_DELETED]);
// was something changed?
if ($changedColumns == 0) {
return redirect()
->route('staticpage.edit', ['id' => $page->id])
->with('error', trans('staticpages::admin.nothingToEdit'));
}
// trigger delete event
Event::fire(new DeleteStaticPage($page, $revision));
// redirect back to overview with info for user
return redirect()
->route('staticpage.overview')
->with('success', trans('staticpages::admin.pageDeleted', [
'name' => $page->title,
'url' => $page->url
]));
}
}