FEATURE: add content page logging
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AttemptToEditInvalidContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $contentId;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($contentId)
|
||||
{
|
||||
$this->contentId = $contentId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class CreateNewContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Content $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class DeleteContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
public $revision;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Content $page
|
||||
* @param $revision
|
||||
*/
|
||||
public function __construct(Content $page, $revision)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class EditContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
public $revision;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Content $page
|
||||
* @param $revision
|
||||
*/
|
||||
|
||||
public function __construct(Content $page, $revision)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MakeDraftFromContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $revision;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Content $page, $revision)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PublishContent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
public $revision;
|
||||
|
||||
public function __construct(Content $page, $revision)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use App\Models\Content;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
|
||||
class SetHomepage extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Content
|
||||
*/
|
||||
public $page;
|
||||
public $revision;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Content $page
|
||||
* @param $revision
|
||||
*/
|
||||
public function __construct(Content $page, $revision)
|
||||
{
|
||||
$this->page = $page;
|
||||
$this->revision = $revision;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\ActiveContentStatuses;
|
||||
use App\Events\CreateNewContent as CreateNewContentEvent;
|
||||
use App\Http\Requests\CreateNewContentRequest;
|
||||
use App\Models\Content;
|
||||
use App\Models\File;
|
||||
use App\Models\Module;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -111,6 +113,9 @@ class CreateNewContent extends Controller
|
||||
|
||||
$page->save();
|
||||
|
||||
// fire event about creating new content page
|
||||
Event::fire(new CreateNewContentEvent($page));
|
||||
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->with('success', trans('admin/contents.successfullyCreated'));
|
||||
|
||||
@@ -3,12 +3,19 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Events\AttemptToEditInvalidContent;
|
||||
use App\Events\DeleteContent;
|
||||
use App\Events\EditContent as EditContentEvent;
|
||||
use App\Events\MakeDraftFromContent;
|
||||
use App\Events\PublishContent;
|
||||
use App\Events\SetHomepage;
|
||||
use App\Http\Requests\EditContentRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content;
|
||||
use App\Models\ContentHistory;
|
||||
use App\Models\File;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -38,6 +45,8 @@ class EditContent extends Controller
|
||||
*/
|
||||
public function getEdit($id)
|
||||
{
|
||||
dd(request()->header('User-agent'));
|
||||
|
||||
// select all content statuses
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
|
||||
@@ -80,6 +89,9 @@ class EditContent extends Controller
|
||||
$page = Content::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
|
||||
// log attempt of invalid edit
|
||||
Event::fire(new AttemptToEditInvalidContent($id));
|
||||
|
||||
// page for editing not found
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
@@ -126,7 +138,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// fire event with
|
||||
// Event::fire(new EditStaticPageEvent($page, $revision));
|
||||
Event::fire(new EditContentEvent($page, $revision));
|
||||
|
||||
// something was changed, inform user
|
||||
return redirect()
|
||||
@@ -178,11 +190,11 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// fire events
|
||||
// if ($status != Content::STATUS_DRAFT) {
|
||||
// Event::fire(new PublishStaticPage($page, $revision));
|
||||
// } else {
|
||||
// Event::fire(new MakeDraftFromStaticPage($page, $revision));
|
||||
// }
|
||||
if ($status != Content::STATUS_DRAFT) {
|
||||
Event::fire(new PublishContent($page, $revision));
|
||||
} else {
|
||||
Event::fire(new MakeDraftFromContent($page, $revision));
|
||||
}
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -219,7 +231,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// trigger delete event
|
||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||
Event::fire(new DeleteContent($page, $revision));
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -257,7 +269,7 @@ class EditContent extends Controller
|
||||
->update(['is_homepage' => 0]);
|
||||
|
||||
// set new homepage
|
||||
list (, $changedColumns) = $page->updateWithHistory(['is_homepage' => 'is_homepage'], ['is_homepage' => 1]);
|
||||
list ($revision, $changedColumns) = $page->updateWithHistory(['is_homepage' => 'is_homepage'], ['is_homepage' => 1]);
|
||||
|
||||
// was something changed?
|
||||
if ($changedColumns == 0) {
|
||||
@@ -267,7 +279,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// trigger delete event
|
||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||
Event::fire(new SetHomepage($page, $revision));
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\AttemptToEditInvalidContent;
|
||||
|
||||
class LogAttemptToInvalidContentEdit extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param AttemptToEditInvalidContent $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(AttemptToEditInvalidContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'contentId' => $event->contentId
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'invalidEditContentAttempt';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\CreateNewContent;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogCreateNewContent extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param CreateNewContent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(CreateNewContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'createNewContent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\DeleteContent;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogDeleteContent extends Logger
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param DeleteContent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(DeleteContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title,
|
||||
'revision' => $event->revision
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'deleteContent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\MakeDraftFromContent;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogDraftFromContent extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param MakeDraftFromContent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(MakeDraftFromContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title,
|
||||
'revision' => $event->revision
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'draftFromContent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\EditContent;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogEditContent extends Logger
|
||||
{
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param EditContent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(EditContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title,
|
||||
'revision' => $event->revision
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'editContent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\PublishContent;
|
||||
|
||||
class LogPublishContent extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param PublishContent $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(PublishContent $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title,
|
||||
'revision' => $event->revision
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'publishContent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\SetHomepage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class LogSetHomepage extends Logger
|
||||
{
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param SetHomepage $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(SetHomepage $event)
|
||||
{
|
||||
$parameters = [
|
||||
'id' => $event->page->id,
|
||||
'url' => $event->page->url,
|
||||
'title' => $event->page->title,
|
||||
'revision' => $event->revision
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'setHomepage';
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,27 @@ class EventServiceProvider extends ServiceProvider
|
||||
'App\Events\EditUser' => [
|
||||
'App\Listeners\LogEditUser',
|
||||
],
|
||||
'App\Events\CreateNewContent' => [
|
||||
'App\Listeners\LogCreateNewContent'
|
||||
],
|
||||
'App\Events\EditContent' => [
|
||||
'App\Listeners\LogEditContent'
|
||||
],
|
||||
'App\Events\PublishContent' => [
|
||||
'App\Listeners\LogPublishContent'
|
||||
],
|
||||
'App\Events\MakeDraftFromContent' => [
|
||||
'App\Listeners\LogDraftFromContent'
|
||||
],
|
||||
'App\Events\SetHomepage' => [
|
||||
'App\Listeners\LogSetHomepage'
|
||||
],
|
||||
'App\Events\AttemptToEditInvalidContent' => [
|
||||
'App\Listeners\LogAttemptToInvalidContentEdit'
|
||||
],
|
||||
'App\Events\DeleteContent' => [
|
||||
'App\Listeners\LogDeleteContent'
|
||||
],
|
||||
'App\Events\CreateNewCustomField' => [
|
||||
'App\Listeners\LogCreateCustomField',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user