Remove subtype and store trigger instead

This commit is contained in:
Dennis Eichhorn 2020-12-19 20:21:32 +01:00
parent 9a47a38399
commit 1018ff835f
7 changed files with 40 additions and 45 deletions

View File

@ -26,9 +26,9 @@
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"auditor_audit_subtype": { "auditor_audit_trigger": {
"name": "auditor_audit_subtype", "name": "auditor_audit_trigger",
"type": "INT", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"auditor_audit_content": { "auditor_audit_content": {

View File

@ -36,7 +36,7 @@ final class ApiController extends Controller
* @param mixed $old Old value (always null) * @param mixed $old Old value (always null)
* @param mixed $new New value * @param mixed $new New value
* @param int $type Module model type * @param int $type Module model type
* @param int $subtype Module model subtype * @param string $trigger What triggered this log?
* @param string $module Module name * @param string $module Module name
* @param string $ref Reference to other model * @param string $ref Reference to other model
* @param string $content Message * @param string $content Message
@ -50,10 +50,10 @@ final class ApiController extends Controller
*/ */
public function apiLogCreate( public function apiLogCreate(
int $account, int $account,
$old, mixed $old,
$new, mixed $new,
int $type = 0, int $type = 0,
int $subtype = 0, string $trigger = '',
string $module = null, string $module = null,
string $ref = null, string $ref = null,
string $content = null, string $content = null,
@ -61,7 +61,7 @@ final class ApiController extends Controller
) : void ) : void
{ {
$newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT); $newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT);
$audit = new Audit(new NullAccount($account), null, $newString, $type, $subtype, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1')); $audit = new Audit(new NullAccount($account), null, $newString, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
AuditMapper::create($audit); AuditMapper::create($audit);
} }
@ -73,7 +73,7 @@ final class ApiController extends Controller
* @param mixed $old Old value * @param mixed $old Old value
* @param mixed $new New value * @param mixed $new New value
* @param int $type Module model type * @param int $type Module model type
* @param int $subtype Module model subtype * @param string $trigger What triggered this log?
* @param string $module Module name * @param string $module Module name
* @param string $ref Reference to other model * @param string $ref Reference to other model
* @param string $content Message * @param string $content Message
@ -87,10 +87,10 @@ final class ApiController extends Controller
*/ */
public function apiLogUpdate( public function apiLogUpdate(
int $account, int $account,
$old, mixed $old,
$new, mixed $new,
int $type = 0, int $type = 0,
int $subtype = 0, string $trigger = '',
string $module = null, string $module = null,
string $ref = null, string $ref = null,
string $content = null, string $content = null,
@ -104,7 +104,7 @@ final class ApiController extends Controller
return; return;
} }
$audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $subtype, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1')); $audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
AuditMapper::create($audit); AuditMapper::create($audit);
} }
@ -116,7 +116,7 @@ final class ApiController extends Controller
* @param mixed $old Old value * @param mixed $old Old value
* @param mixed $new New value (always null) * @param mixed $new New value (always null)
* @param int $type Module model type * @param int $type Module model type
* @param int $subtype Module model subtype * @param string $trigger What triggered this log?
* @param string $module Module name * @param string $module Module name
* @param string $ref Reference to other model * @param string $ref Reference to other model
* @param string $content Message * @param string $content Message
@ -130,10 +130,10 @@ final class ApiController extends Controller
*/ */
public function apiLogDelete( public function apiLogDelete(
int $account, int $account,
$old, mixed $old,
$new, mixed $new,
int $type = 0, int $type = 0,
int $subtype = 0, string $trigger = '',
string $module = null, string $module = null,
string $ref = null, string $ref = null,
string $content = null, string $content = null,
@ -141,7 +141,7 @@ final class ApiController extends Controller
) : void ) : void
{ {
$oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT); $oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT);
$audit = new Audit(new NullAccount($account), $oldString, null, $type, $subtype, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1')); $audit = new Audit(new NullAccount($account), $oldString, null, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
AuditMapper::create($audit); AuditMapper::create($audit);
} }

View File

@ -44,12 +44,12 @@ class Audit
private int $type; private int $type;
/** /**
* Audit subtype. * Audit trigger.
* *
* @var int * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private int $subtype; private string $trigger;
/** /**
* Audit module. * Audit module.
@ -126,7 +126,7 @@ class Audit
* @param null|string $old Old value * @param null|string $old Old value
* @param null|string $new New value * @param null|string $new New value
* @param int $type Type of the audit * @param int $type Type of the audit
* @param int $subtype Subtype of the audit * @param string $trigger Subtype of the audit
* @param null|string $module Module id * @param null|string $module Module id
* @param null|string $ref Dynamic reference to model * @param null|string $ref Dynamic reference to model
* @param null|string $content Additional audit information * @param null|string $content Additional audit information
@ -139,7 +139,7 @@ class Audit
string $old = null, string $old = null,
string $new = null, string $new = null,
int $type = 0, int $type = 0,
int $subtype = 0, string $trigger = '',
string $module = null, string $module = null,
string $ref = null, string $ref = null,
string $content = null, string $content = null,
@ -150,7 +150,7 @@ class Audit
$this->old = $old; $this->old = $old;
$this->new = $new; $this->new = $new;
$this->type = $type; $this->type = $type;
$this->subtype = $subtype; $this->trigger = $trigger;
$this->module = $module; $this->module = $module;
$this->ref = $ref; $this->ref = $ref;
$this->content = $content; $this->content = $content;
@ -188,9 +188,9 @@ class Audit
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getSubType() : int public function getTrigger() : string
{ {
return $this->subtype; return $this->trigger;
} }
/** /**

View File

@ -42,7 +42,7 @@ final class AuditMapper extends DataMapperAbstract
'auditor_audit_module' => ['name' => 'auditor_audit_module', 'type' => 'string', 'internal' => 'module'], 'auditor_audit_module' => ['name' => 'auditor_audit_module', 'type' => 'string', 'internal' => 'module'],
'auditor_audit_ref' => ['name' => 'auditor_audit_ref', 'type' => 'string', 'internal' => 'ref'], 'auditor_audit_ref' => ['name' => 'auditor_audit_ref', 'type' => 'string', 'internal' => 'ref'],
'auditor_audit_type' => ['name' => 'auditor_audit_type', 'type' => 'int', 'internal' => 'type'], 'auditor_audit_type' => ['name' => 'auditor_audit_type', 'type' => 'int', 'internal' => 'type'],
'auditor_audit_subtype' => ['name' => 'auditor_audit_subtype', 'type' => 'int', 'internal' => 'subtype'], 'auditor_audit_trigger' => ['name' => 'auditor_audit_trigger', 'type' => 'string', 'internal' => 'trigger'],
'auditor_audit_content' => ['name' => 'auditor_audit_content', 'type' => 'string', 'internal' => 'content'], 'auditor_audit_content' => ['name' => 'auditor_audit_content', 'type' => 'string', 'internal' => 'content'],
'auditor_audit_old' => ['name' => 'auditor_audit_old', 'type' => 'string', 'internal' => 'old'], 'auditor_audit_old' => ['name' => 'auditor_audit_old', 'type' => 'string', 'internal' => 'old'],
'auditor_audit_new' => ['name' => 'auditor_audit_new', 'type' => 'string', 'internal' => 'new'], 'auditor_audit_new' => ['name' => 'auditor_audit_new', 'type' => 'string', 'internal' => 'new'],

View File

@ -36,8 +36,6 @@ echo $this->getData('nav')->render(); ?>
<col style="width: 100px"> <col style="width: 100px">
<col style="width: 75px"> <col style="width: 75px">
<col> <col>
<col>
<col>
<col style="width: 125px"> <col style="width: 125px">
<col style="width: 75px"> <col style="width: 75px">
<col style="width: 150px"> <col style="width: 150px">
@ -47,9 +45,7 @@ echo $this->getData('nav')->render(); ?>
<td><?= $this->getHtml('ID', '0', '0'); ?> <td><?= $this->getHtml('ID', '0', '0'); ?>
<td ><?= $this->getHtml('Module'); ?> <td ><?= $this->getHtml('Module'); ?>
<td ><?= $this->getHtml('Type'); ?> <td ><?= $this->getHtml('Type'); ?>
<td ><?= $this->getHtml('Subtype'); ?> <td ><?= $this->getHtml('Trigger'); ?>
<td ><?= $this->getHtml('Old'); ?>
<td ><?= $this->getHtml('New'); ?>
<td ><?= $this->getHtml('Content'); ?> <td ><?= $this->getHtml('Content'); ?>
<td ><?= $this->getHtml('By'); ?> <td ><?= $this->getHtml('By'); ?>
<td ><?= $this->getHtml('Ref'); ?> <td ><?= $this->getHtml('Ref'); ?>
@ -61,16 +57,14 @@ echo $this->getData('nav')->render(); ?>
<td><?= $audit->getId(); ?> <td><?= $audit->getId(); ?>
<td><?= $this->printHtml($audit->getModule()); ?> <td><?= $this->printHtml($audit->getModule()); ?>
<td><?= $audit->getType(); ?> <td><?= $audit->getType(); ?>
<td><?= $audit->getSubtype(); ?> <td><?= $audit->getTrigger(); ?>
<td><?= $this->printHtml($audit->getOld()); ?>
<td><?= $this->printHtml($audit->getNew()); ?>
<td><?= $this->printHtml($audit->getContent()); ?> <td><?= $this->printHtml($audit->getContent()); ?>
<td><?= $this->printHtml($audit->createdBy->login); ?> <td><?= $this->printHtml($audit->createdBy->login); ?>
<td><?= $this->printHtml($audit->getRef()); ?> <td><?= $this->printHtml($audit->getRef()); ?>
<td><?= $audit->createdAt->format('Y-m-d H:i'); ?> <td><?= $audit->createdAt->format('Y-m-d H:i'); ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($count === 0) : ?> <?php if ($count === 0) : ?>
<tr><td colspan="10" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?> <tr><td colspan="8" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?> <?php endif; ?>
</table> </table>
<div class="portlet-foot"> <div class="portlet-foot">

View File

@ -13,6 +13,7 @@
declare(strict_types=1); declare(strict_types=1);
use phpOMS\Message\Http\HttpHeader; use phpOMS\Message\Http\HttpHeader;
use phpOMS\Uri\UriFactory;
use phpOMS\Views\ViewAbstract; use phpOMS\Views\ViewAbstract;
/** @var \phpOMS\Views\View $this */ /** @var \phpOMS\Views\View $this */
@ -51,13 +52,13 @@ echo $this->getData('nav')->render();
<tr> <tr>
<th>Created By <th>Created By
<td><?= $audit->createdBy->name1; ?> <td><a href="<?= UriFactory::build('{/prefix}admin/account/settings?{?}&id=' . $audit->createdBy->getId()); ?>"><?= $audit->createdBy->name1; ?></a>
<tr> <tr>
<th>Created At <th>Created At
<td><?= $this->getDateTime($audit->createdAt, 'very_long'); ?> <td><?= $this->getDateTime($audit->createdAt, 'very_long'); ?>
<tr> <tr>
<th>Module <th>Module
<td><?= $audit->getModule(); ?> <td><a href="<?= UriFactory::build('{/prefix}admin/module/settings?{?}&id=' . $audit->getModule()); ?>"><?= $audit->getModule(); ?></a>
<tr> <tr>
<th>IP <th>IP
<td><?= \long2ip($audit->getIp()); ?> <td><?= \long2ip($audit->getIp()); ?>

View File

@ -89,13 +89,13 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLogCreate() : void public function testLogCreate() : void
{ {
$this->module->apiLogCreate(1, null, ['id' => 1, 'test' => true], 1, 2, 'Auditor', 'abc', 'def'); $this->module->apiLogCreate(1, null, ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
$logs = AuditMapper::getAll(); $logs = AuditMapper::getAll();
foreach($logs as $log) { foreach($logs as $log) {
if ($log->getId() > 0 if ($log->getId() > 0
&& $log->getType() === 1 && $log->getType() === 1
&& $log->getSubtype() === 2 && $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor' && $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc' && $log->getRef() === 'abc'
&& $log->getContent() === 'def' && $log->getContent() === 'def'
@ -117,14 +117,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLogUpdate() : void public function testLogUpdate() : void
{ {
$this->module->apiLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 1, 'test' => true], 1, 2, 'Auditor', 'abc', 'def'); $this->module->apiLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
$logs = AuditMapper::getAll(); $logs = AuditMapper::getAll();
$found = false; $found = false;
foreach($logs as $log) { foreach($logs as $log) {
if ($log->getId() > 0 if ($log->getId() > 0
&& $log->getType() === 1 && $log->getType() === 1
&& $log->getSubtype() === 2 && $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor' && $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc' && $log->getRef() === 'abc'
&& $log->getContent() === 'def' && $log->getContent() === 'def'
@ -146,7 +146,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testLogUpdateWithoutChange() : void public function testLogUpdateWithoutChange() : void
{ {
$logs = AuditMapper::getAll(); $logs = AuditMapper::getAll();
$this->module->apiLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 2, 'test' => true], 1, 2, 'Auditor', 'abc', 'def'); $this->module->apiLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 2, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
$logs2 = AuditMapper::getAll(); $logs2 = AuditMapper::getAll();
self::assertGreaterThan(0, \count($logs)); self::assertGreaterThan(0, \count($logs));
@ -160,13 +160,13 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLogDelete() : void public function testLogDelete() : void
{ {
$this->module->apiLogDelete(1, ['id' => 1, 'test' => true], null, 1, 2, 'Auditor', 'abc', 'def'); $this->module->apiLogDelete(1, ['id' => 1, 'test' => true], null, 1, 'test-trigger', 'Auditor', 'abc', 'def');
$logs = AuditMapper::getAll(); $logs = AuditMapper::getAll();
foreach($logs as $log) { foreach($logs as $log) {
if ($log->getId() > 0 if ($log->getId() > 0
&& $log->getType() === 1 && $log->getType() === 1
&& $log->getSubtype() === 2 && $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor' && $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc' && $log->getRef() === 'abc'
&& $log->getContent() === 'def' && $log->getContent() === 'def'