mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-02-16 05:28:43 +00:00
Next step for audit implementation
This commit is contained in:
parent
2814932cb7
commit
97e605492e
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'PRE:Module:.*?\-create' => [
|
'POST:Module:.*?\-create' => [
|
||||||
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogCreate'],
|
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogCreate'],
|
||||||
],
|
],
|
||||||
'PRE:Module:.*?\-update' => [
|
'POST:Module:.*?\-update' => [
|
||||||
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogUpdate'],
|
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogUpdate'],
|
||||||
],
|
],
|
||||||
'PRE:Module:.*?\-delete' => [
|
'POST:Module:.*?\-delete' => [
|
||||||
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogDelete'],
|
'callback' => ['\Modules\Auditor\Controller\ApiController:apiLogDelete'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ use phpOMS\Account\Account;
|
||||||
use phpOMS\Account\PermissionType;
|
use phpOMS\Account\PermissionType;
|
||||||
use phpOMS\DataStorage\Database\RelationType;
|
use phpOMS\DataStorage\Database\RelationType;
|
||||||
|
|
||||||
|
use Modules\Auditor\Models\Audit;
|
||||||
|
use Modules\Auditor\Models\AuditMapper;
|
||||||
|
|
||||||
final class ApiController extends Controller
|
final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
public function apiLogCreate(
|
public function apiLogCreate(
|
||||||
|
|
@ -33,10 +36,12 @@ final class ApiController extends Controller
|
||||||
int $type = 0,
|
int $type = 0,
|
||||||
int $subtype = 0,
|
int $subtype = 0,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
|
string $ref = null,
|
||||||
string $content = null
|
string $content = null
|
||||||
) : void
|
) : void
|
||||||
{
|
{
|
||||||
|
$audit = new Audit($account, null, $new->__toString(), $type, $subtype, $module, $ref, $content);
|
||||||
|
AuditMapper::create($audit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apiLogUpdate(
|
public function apiLogUpdate(
|
||||||
|
|
@ -46,10 +51,12 @@ final class ApiController extends Controller
|
||||||
int $type = 0,
|
int $type = 0,
|
||||||
int $subtype = 0,
|
int $subtype = 0,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
|
string $ref = null,
|
||||||
string $content = null
|
string $content = null
|
||||||
) : void
|
) : void
|
||||||
{
|
{
|
||||||
|
$audit = new Audit($account, $old->__toString(), $new->__toString(), $type, $subtype, $module, $ref, $content);
|
||||||
|
AuditMapper::create($audit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apiLogDelete(
|
public function apiLogDelete(
|
||||||
|
|
@ -59,9 +66,11 @@ final class ApiController extends Controller
|
||||||
int $type = 0,
|
int $type = 0,
|
||||||
int $subtype = 0,
|
int $subtype = 0,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
|
string $ref = null,
|
||||||
string $content = null
|
string $content = null
|
||||||
) : void
|
) : void
|
||||||
{
|
{
|
||||||
|
$audit = new Audit($account, $new->__toString(), null, $type, $subtype, $module, $ref, $content);
|
||||||
|
AuditMapper::create($audit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
199
Models/Audit.php
199
Models/Audit.php
|
|
@ -16,80 +16,255 @@ namespace Modules\Auditor\Models;
|
||||||
|
|
||||||
use phpOMS\Account\Account;
|
use phpOMS\Account\Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audit class.
|
||||||
|
*
|
||||||
|
* @package Modules\Auditor
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
class Audit
|
class Audit
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Audit id.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $id = 0;
|
private $id = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audit account.
|
||||||
|
*
|
||||||
|
* @var int|Account
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $account = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audit type.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $type = 0;
|
private $type = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audit subtype.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $subtype = 0;
|
private $subtype = 0;
|
||||||
|
|
||||||
private $module = 0;
|
/**
|
||||||
|
* Audit module.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $module = null;
|
||||||
|
|
||||||
private $ref = '';
|
/**
|
||||||
|
* Audit reference.
|
||||||
|
*
|
||||||
|
* This could be used to reference other model ids
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $ref = null;
|
||||||
|
|
||||||
private $content = '';
|
/**
|
||||||
|
* Audit content.
|
||||||
|
*
|
||||||
|
* Additional audit information
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $content = null;
|
||||||
|
|
||||||
private $old = '';
|
/**
|
||||||
|
* Old value.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $old = null;
|
||||||
|
|
||||||
private $new = '';
|
/**
|
||||||
|
* New value.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $new = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account.
|
||||||
|
*
|
||||||
|
* @var Account|int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $createdBy = 0;
|
private $createdBy = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created at.
|
||||||
|
*
|
||||||
|
* @var \DateTime
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $createdAt = null;
|
private $createdAt = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ip of creator.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $ip = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @parram Account $account Account of the creator
|
||||||
|
* @parram string $old Old value
|
||||||
|
* @parram string $new New value
|
||||||
|
* @parram int $type Type of the audit
|
||||||
|
* @parram int $subtype Subtype of the audit
|
||||||
|
* @parram string $module Module id
|
||||||
|
* @parram string $content Additional audit information
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Account $account,
|
Account $account,
|
||||||
string $old,
|
?string $old,
|
||||||
string $new,
|
?string $new,
|
||||||
int $type = 0,
|
int $type = 0,
|
||||||
int $subtype = 0,
|
int $subtype = 0,
|
||||||
string $module = null,
|
string $module = null,
|
||||||
|
string $ref = null,
|
||||||
string $content = null
|
string $content = null
|
||||||
) {
|
) {
|
||||||
$this->createdAt = new \DateTime('now');
|
$this->createdAt = new \DateTime('now');
|
||||||
|
$this->account = $account;
|
||||||
|
$this->old = $old;
|
||||||
|
$this->new = $new;
|
||||||
|
$this->type = $type;
|
||||||
|
$this->subtype = $subtype;
|
||||||
|
$this->module = $module;
|
||||||
|
$this->ref = $ref;
|
||||||
|
$this->content = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getType() : int
|
public function getType() : int
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get subtype.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getSubType() : int
|
public function getSubType() : int
|
||||||
{
|
{
|
||||||
return $this->subtype;
|
return $this->subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModule() : int
|
/**
|
||||||
|
* Get Module.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getModule() : ?string
|
||||||
{
|
{
|
||||||
return $this->module;
|
return $this->module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRef() : string
|
/**
|
||||||
|
* Get reference.
|
||||||
|
*
|
||||||
|
* If existing this can be a reference to another model
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getRef() : ?string
|
||||||
{
|
{
|
||||||
return $this->ref;
|
return $this->ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent() : string
|
/**
|
||||||
|
* Get content.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getContent() : ?string
|
||||||
{
|
{
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOld() : string
|
/**
|
||||||
|
* Get old value.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getOld() : ?string
|
||||||
{
|
{
|
||||||
return $this->old;
|
return $this->old;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNew() : string
|
/**
|
||||||
|
* Get new value.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getNew() : ?string
|
||||||
{
|
{
|
||||||
return $this->new;
|
return $this->new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get created by.
|
||||||
|
*
|
||||||
|
* @return int|Account
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getCreatedBy()
|
public function getCreatedBy()
|
||||||
{
|
{
|
||||||
return $this->createdBy;
|
return $this->createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get created at.
|
||||||
|
*
|
||||||
|
* @return \DateTime
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getCreatedAt() : \DateTime
|
public function getCreatedAt() : \DateTime
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
|
|
|
||||||
|
|
@ -81,4 +81,28 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static $createdAt = 'auditor_audit_created_at';
|
protected static $createdAt = 'auditor_audit_created_at';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function update($obj, int $relations = RelationType::ALL, int $depth = 1)
|
||||||
|
{
|
||||||
|
// prevent updating
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function updateArray(array &$obj, int $relations = RelationType::ALL, int $depth = 1)
|
||||||
|
{
|
||||||
|
// prevent updating
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function delete($obj, int $relations = RelationType::REFERENCE)
|
||||||
|
{
|
||||||
|
// prevent deleting
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user