diff --git a/Admin/Install/db.json b/Admin/Install/db.json index b26d2fc..f4dd8af 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -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": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 6e8d00d..44ec491 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -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); } diff --git a/Models/Audit.php b/Models/Audit.php index 9c0fb89..ba07548 100755 --- a/Models/Audit.php +++ b/Models/Audit.php @@ -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; } /** diff --git a/Models/AuditMapper.php b/Models/AuditMapper.php index 805181a..6426b34 100755 --- a/Models/AuditMapper.php +++ b/Models/AuditMapper.php @@ -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'], diff --git a/Theme/Backend/audit-list.tpl.php b/Theme/Backend/audit-list.tpl.php index 8e9f928..4267390 100755 --- a/Theme/Backend/audit-list.tpl.php +++ b/Theme/Backend/audit-list.tpl.php @@ -36,8 +36,6 @@ echo $this->getData('nav')->render(); ?> - - @@ -47,9 +45,7 @@ echo $this->getData('nav')->render(); ?> getHtml('ID', '0', '0'); ?> getHtml('Module'); ?> getHtml('Type'); ?> - getHtml('Subtype'); ?> - getHtml('Old'); ?> - getHtml('New'); ?> + getHtml('Trigger'); ?> getHtml('Content'); ?> getHtml('By'); ?> getHtml('Ref'); ?> @@ -61,16 +57,14 @@ echo $this->getData('nav')->render(); ?> getId(); ?> printHtml($audit->getModule()); ?> getType(); ?> - getSubtype(); ?> - printHtml($audit->getOld()); ?> - printHtml($audit->getNew()); ?> + getTrigger(); ?> printHtml($audit->getContent()); ?> printHtml($audit->createdBy->login); ?> printHtml($audit->getRef()); ?> createdAt->format('Y-m-d H:i'); ?> - getHtml('Empty', '0', '0'); ?> + getHtml('Empty', '0', '0'); ?>
diff --git a/Theme/Backend/audit-single.tpl.php b/Theme/Backend/audit-single.tpl.php index 10178f0..a789e97 100755 --- a/Theme/Backend/audit-single.tpl.php +++ b/Theme/Backend/audit-single.tpl.php @@ -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(); Created By - createdBy->name1; ?> + createdBy->name1; ?> Created At getDateTime($audit->createdAt, 'very_long'); ?> Module - getModule(); ?> + getModule(); ?> IP getIp()); ?> diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 554f256..b8d3188 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -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'