diff --git a/Controller/ApiController.php b/Controller/ApiController.php index d39b35d..c1b5619 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -14,10 +14,11 @@ declare(strict_types=1); namespace Modules\Auditor\Controller; +use Modules\Admin\Models\NullAccount; use Modules\Auditor\Models\Audit; use Modules\Auditor\Models\AuditMapper; -use phpOMS\Account\Account; +use phpOMS\Account\Account; use phpOMS\Utils\StringUtils; /** @@ -65,7 +66,7 @@ final class ApiController extends Controller ) : void { $newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT); - $audit = new Audit($account, null, $newString, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), null, $newString, $type, $subtype, $module, $ref, $content); AuditMapper::create($audit); } @@ -101,7 +102,7 @@ final class ApiController extends Controller { $oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT); $newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT); - $audit = new Audit($account, $oldString, $newString, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $subtype, $module, $ref, $content); AuditMapper::create($audit); } @@ -136,7 +137,7 @@ final class ApiController extends Controller ) : void { $oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT); - $audit = new Audit($account, $oldString, null, $type, $subtype, $module, $ref, $content); + $audit = new Audit(new NullAccount($account), $oldString, null, $type, $subtype, $module, $ref, $content); AuditMapper::create($audit); } diff --git a/Models/Audit.php b/Models/Audit.php index 8f21fa3..d97a7ec 100644 --- a/Models/Audit.php +++ b/Models/Audit.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Auditor\Models; +use Modules\Admin\Models\NullAccount; use phpOMS\Account\Account; /** @@ -97,10 +98,10 @@ class Audit /** * Account. * - * @var int|Account + * @var Account * @since 1.0.0 */ - private $createdBy; + private Account $createdBy; /** * Created at. @@ -121,7 +122,7 @@ class Audit /** * Constructor. * - * @param int|Account $account Account of the creator + * @param Account $account Account of the creator * @param null|string $old Old value * @param null|string $new New value * @param int $type Type of the audit @@ -133,7 +134,7 @@ class Audit * @since 1.0.0 */ public function __construct( - $account = 0, + Account $account = null, string $old = null, string $new = null, int $type = 0, @@ -143,7 +144,7 @@ class Audit string $content = null ) { $this->createdAt = new \DateTime('now'); - $this->createdBy = $account; + $this->createdBy = $account ?? new NullAccount(); $this->old = $old; $this->new = $new; $this->type = $type; diff --git a/Models/AuditMapper.php b/Models/AuditMapper.php index d7d1ca8..c85a716 100644 --- a/Models/AuditMapper.php +++ b/Models/AuditMapper.php @@ -35,7 +35,7 @@ final class AuditMapper extends DataMapperAbstract */ protected static array $columns = [ 'auditor_audit_id' => ['name' => 'auditor_audit_id', 'type' => 'int', 'internal' => 'id'], - 'auditor_audit_created_by' => ['name' => 'auditor_audit_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'auditor_audit_created_by' => ['name' => 'auditor_audit_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'auditor_audit_created_at' => ['name' => 'auditor_audit_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'auditor_audit_ip' => ['name' => 'auditor_audit_ip', 'type' => 'int', 'internal' => 'ip'], 'auditor_audit_module' => ['name' => 'auditor_audit_module', 'type' => 'string', 'internal' => 'module'],