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",
"null": false
},
"auditor_audit_subtype": {
"name": "auditor_audit_subtype",
"type": "INT",
"auditor_audit_trigger": {
"name": "auditor_audit_trigger",
"type": "VARCHAR(255)",
"null": false
},
"auditor_audit_content": {

View File

@ -36,7 +36,7 @@ final class ApiController extends Controller
* @param mixed $old Old value (always null)
* @param mixed $new New value
* @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 $ref Reference to other model
* @param string $content Message
@ -50,10 +50,10 @@ final class ApiController extends Controller
*/
public function apiLogCreate(
int $account,
$old,
$new,
mixed $old,
mixed $new,
int $type = 0,
int $subtype = 0,
string $trigger = '',
string $module = null,
string $ref = null,
string $content = null,
@ -61,7 +61,7 @@ final class ApiController extends Controller
) : void
{
$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);
}
@ -73,7 +73,7 @@ final class ApiController extends Controller
* @param mixed $old Old value
* @param mixed $new New value
* @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 $ref Reference to other model
* @param string $content Message
@ -87,10 +87,10 @@ final class ApiController extends Controller
*/
public function apiLogUpdate(
int $account,
$old,
$new,
mixed $old,
mixed $new,
int $type = 0,
int $subtype = 0,
string $trigger = '',
string $module = null,
string $ref = null,
string $content = null,
@ -104,7 +104,7 @@ final class ApiController extends Controller
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);
}
@ -116,7 +116,7 @@ final class ApiController extends Controller
* @param mixed $old Old value
* @param mixed $new New value (always null)
* @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 $ref Reference to other model
* @param string $content Message
@ -130,10 +130,10 @@ final class ApiController extends Controller
*/
public function apiLogDelete(
int $account,
$old,
$new,
mixed $old,
mixed $new,
int $type = 0,
int $subtype = 0,
string $trigger = '',
string $module = null,
string $ref = null,
string $content = null,
@ -141,7 +141,7 @@ final class ApiController extends Controller
) : void
{
$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);
}

View File

@ -44,12 +44,12 @@ class Audit
private int $type;
/**
* Audit subtype.
* Audit trigger.
*
* @var int
* @var string
* @since 1.0.0
*/
private int $subtype;
private string $trigger;
/**
* Audit module.
@ -126,7 +126,7 @@ class Audit
* @param null|string $old Old value
* @param null|string $new New value
* @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 $ref Dynamic reference to model
* @param null|string $content Additional audit information
@ -139,7 +139,7 @@ class Audit
string $old = null,
string $new = null,
int $type = 0,
int $subtype = 0,
string $trigger = '',
string $module = null,
string $ref = null,
string $content = null,
@ -150,7 +150,7 @@ class Audit
$this->old = $old;
$this->new = $new;
$this->type = $type;
$this->subtype = $subtype;
$this->trigger = $trigger;
$this->module = $module;
$this->ref = $ref;
$this->content = $content;
@ -188,9 +188,9 @@ class Audit
*
* @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_ref' => ['name' => 'auditor_audit_ref', 'type' => 'string', 'internal' => 'ref'],
'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_old' => ['name' => 'auditor_audit_old', 'type' => 'string', 'internal' => 'old'],
'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: 75px">
<col>
<col>
<col>
<col style="width: 125px">
<col style="width: 75px">
<col style="width: 150px">
@ -47,9 +45,7 @@ echo $this->getData('nav')->render(); ?>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td ><?= $this->getHtml('Module'); ?>
<td ><?= $this->getHtml('Type'); ?>
<td ><?= $this->getHtml('Subtype'); ?>
<td ><?= $this->getHtml('Old'); ?>
<td ><?= $this->getHtml('New'); ?>
<td ><?= $this->getHtml('Trigger'); ?>
<td ><?= $this->getHtml('Content'); ?>
<td ><?= $this->getHtml('By'); ?>
<td ><?= $this->getHtml('Ref'); ?>
@ -61,16 +57,14 @@ echo $this->getData('nav')->render(); ?>
<td><?= $audit->getId(); ?>
<td><?= $this->printHtml($audit->getModule()); ?>
<td><?= $audit->getType(); ?>
<td><?= $audit->getSubtype(); ?>
<td><?= $this->printHtml($audit->getOld()); ?>
<td><?= $this->printHtml($audit->getNew()); ?>
<td><?= $audit->getTrigger(); ?>
<td><?= $this->printHtml($audit->getContent()); ?>
<td><?= $this->printHtml($audit->createdBy->login); ?>
<td><?= $this->printHtml($audit->getRef()); ?>
<td><?= $audit->createdAt->format('Y-m-d H:i'); ?>
<?php endforeach; ?>
<?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; ?>
</table>
<div class="portlet-foot">

View File

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

View File

@ -89,13 +89,13 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/
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();
foreach($logs as $log) {
if ($log->getId() > 0
&& $log->getType() === 1
&& $log->getSubtype() === 2
&& $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc'
&& $log->getContent() === 'def'
@ -117,14 +117,14 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/
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();
$found = false;
foreach($logs as $log) {
if ($log->getId() > 0
&& $log->getType() === 1
&& $log->getSubtype() === 2
&& $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc'
&& $log->getContent() === 'def'
@ -146,7 +146,7 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
public function testLogUpdateWithoutChange() : void
{
$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();
self::assertGreaterThan(0, \count($logs));
@ -160,13 +160,13 @@ class ApiControllerTest extends \PHPUnit\Framework\TestCase
*/
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();
foreach($logs as $log) {
if ($log->getId() > 0
&& $log->getType() === 1
&& $log->getSubtype() === 2
&& $log->getTrigger() === 'test-trigger'
&& $log->getModule() === 'Auditor'
&& $log->getRef() === 'abc'
&& $log->getContent() === 'def'