Skip to content

Commit

Permalink
Added setting for pruning old recors on admin requests
Browse files Browse the repository at this point in the history
Fixes #44
  • Loading branch information
sjelfull committed Dec 4, 2018
1 parent cc1f53a commit cf58e7f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.3 - 2018-12-04

## Added
- Added setting for pruning old records on admin requests

## 1.0.2 - 2018-12-03

## Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ return [

// Enable logging
'enabled' => true,

// Prune old records when a admin is logged in
'pruneRecordsOnAdminRequests' => false,

// Enable geolocation status
'enabledGeolocation' => true,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "superbig/craft-audit",
"description": "Log adding/updating/deleting of elements",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down
7 changes: 6 additions & 1 deletion src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ function(PluginEvent $event) {
* before our event listeners kick in
*/
// Handler: EVENT_AFTER_LOAD_PLUGINS
if (!Craft::$app->getRequest()->getIsConsoleRequest() && $this->tableSchemaExists()) {
$request = Craft::$app->getRequest();
if (!$request->getIsConsoleRequest() && $this->tableSchemaExists()) {
if ($this->getSettings()->enabled) {
Event::on(
Plugins::class,
Expand All @@ -130,6 +131,10 @@ function() {
$this->initLogEvents();
});
}

if ($this->getSettings()->pruneRecordsOnAdminRequests && ($request->getIsCpRequest() && !$request->getIsActionRequest() && Craft::$app->getUser()->getIsAdmin())) {
self::$plugin->auditService->pruneLogs();
}
}

Event::on(
Expand Down
3 changes: 3 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
// Enable logging
'enabled' => true,

// Prune old records when a admin is logged in
'pruneRecordsOnAdminRequests' => false,

// Enable geolocation status
'enabledGeolocation' => true,
];
5 changes: 5 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class Settings extends Model
*/
public $enabled = true;

/**
* Prune old records when a admin is logged in
*/
public $pruneRecordsOnAdminRequests = false;

/**
* Enabled status
*/
Expand Down
7 changes: 7 additions & 0 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
on: settings.enabled,
}) }}

{{ forms.lightswitchField({
name: 'pruneRecordsOnAdminRequests',
label: 'Prune old records when a admin is logged in',
description: 'This will prune old records when a admin is logged in and browsing the control panel',
on: settings.pruneRecordsOnAdminRequests,
}) }}

<hr>

<h2>Geolocation</h2>
Expand Down

0 comments on commit cf58e7f

Please sign in to comment.