mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-02-15 13:08:41 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
4066bfc044
commit
3f2295ea20
|
|
@ -45,6 +45,6 @@ class Media
|
||||||
$defaultTemplate = \reset($media['upload'][0]);
|
$defaultTemplate = \reset($media['upload'][0]);
|
||||||
|
|
||||||
$setting = new Setting();
|
$setting = new Setting();
|
||||||
SettingMapper::create($setting->with(0, 'default_pdf_template', (string) $defaultTemplate->getId(), '\\d+', 1, 'Auditor'));
|
SettingMapper::create()->execute($setting->with(0, 'default_pdf_template', (string) $defaultTemplate->getId(), '\\d+', 1, 'Auditor'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ final class ApiController extends Controller
|
||||||
$newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT);
|
$newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT);
|
||||||
$audit = new Audit(new NullAccount($account), null, $newString, $type, $trigger, $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()->execute($audit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +106,7 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
$audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $trigger, $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()->execute($audit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -143,6 +143,6 @@ final class ApiController extends Controller
|
||||||
$oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT);
|
$oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT);
|
||||||
$audit = new Audit(new NullAccount($account), $oldString, null, $type, $trigger, $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()->execute($audit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace Modules\Auditor\Controller;
|
||||||
|
|
||||||
use Modules\Auditor\Models\AuditMapper;
|
use Modules\Auditor\Models\AuditMapper;
|
||||||
use phpOMS\Contract\RenderableInterface;
|
use phpOMS\Contract\RenderableInterface;
|
||||||
|
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Views\View;
|
use phpOMS\Views\View;
|
||||||
|
|
@ -50,11 +51,11 @@ final class BackendController extends Controller
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
||||||
|
|
||||||
if ($request->getData('ptype') === 'p') {
|
if ($request->getData('ptype') === 'p') {
|
||||||
$view->setData('audits', AuditMapper::sortBy('createdAt', 'DESC')::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25));
|
$view->setData('audits', AuditMapper::getAll()->with('createdBy')->sort('createdAt', OrderType::DESC)->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute());
|
||||||
} elseif ($request->getData('ptype') === 'n') {
|
} elseif ($request->getData('ptype') === 'n') {
|
||||||
$view->setData('audits', AuditMapper::sortBy('createdAt', 'DESC')::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25));
|
$view->setData('audits', AuditMapper::getAll()->with('createdBy')->sort('createdAt', OrderType::DESC)->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute());
|
||||||
} else {
|
} else {
|
||||||
$view->setData('audits', AuditMapper::sortBy('createdAt', 'DESC')::getAfterPivot(0, null, 25, depth: 2));
|
$view->setData('audits', AuditMapper::getAll()->with('createdBy')->sort('createdAt', OrderType::DESC)->where('id', 0, '>')->limit(25)->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
|
|
@ -79,7 +80,7 @@ final class BackendController extends Controller
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
||||||
|
|
||||||
/** @var \Modules\Auditor\Models\Audit $audit */
|
/** @var \Modules\Auditor\Models\Audit $audit */
|
||||||
$audit = AuditMapper::get((int) $request->getData('id'));
|
$audit = AuditMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||||
$view->setData('audit', $audit);
|
$view->setData('audit', $audit);
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Auditor\Models;
|
namespace Modules\Auditor\Models;
|
||||||
|
|
||||||
use Modules\Admin\Models\AccountMapper;
|
use Modules\Admin\Models\AccountMapper;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
use phpOMS\DataStorage\Database\RelationType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapper class.
|
* Mapper class.
|
||||||
|
|
@ -26,7 +25,7 @@ use phpOMS\DataStorage\Database\RelationType;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
final class AuditMapper extends DataMapperAbstract
|
final class AuditMapper extends DataMapperFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
|
|
@ -34,7 +33,7 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
public const COLUMNS = [
|
||||||
'auditor_audit_id' => ['name' => 'auditor_audit_id', 'type' => 'int', 'internal' => 'id'],
|
'auditor_audit_id' => ['name' => 'auditor_audit_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'auditor_audit_created_by' => ['name' => 'auditor_audit_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'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' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'auditor_audit_created_at' => ['name' => 'auditor_audit_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
|
|
@ -54,7 +53,7 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, external:string}>
|
* @var array<string, array{mapper:string, external:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $belongsTo = [
|
public const BELONGS_TO = [
|
||||||
'createdBy' => [
|
'createdBy' => [
|
||||||
'mapper' => AccountMapper::class,
|
'mapper' => AccountMapper::class,
|
||||||
'external' => 'auditor_audit_created_by',
|
'external' => 'auditor_audit_created_by',
|
||||||
|
|
@ -67,7 +66,7 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $model = Audit::class;
|
public const MODEL = Audit::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary table.
|
* Primary table.
|
||||||
|
|
@ -75,7 +74,7 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $table = 'auditor_audit';
|
public const TABLE = 'auditor_audit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary field name.
|
* Primary field name.
|
||||||
|
|
@ -83,7 +82,7 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $primaryField = 'auditor_audit_id';
|
public const PRIMARYFIELD ='auditor_audit_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created at.
|
* Created at.
|
||||||
|
|
@ -91,29 +90,5 @@ final class AuditMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $createdAt = 'auditor_audit_created_at';
|
public const CREATED_AT = 'auditor_audit_created_at';
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public static function delete($obj, int $relations = RelationType::REFERENCE) : mixed
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public static function update($obj, int $relations = RelationType::ALL, int $depth = 3) : mixed
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public static function updateArray(array &$obj, int $relations = RelationType::ALL, int $depth = 1) : mixed
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
require_once __DIR__ . '/Autoloader.php';
|
require_once __DIR__ . '/Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DatabasePool;
|
use phpOMS\DataStorage\Database\DatabasePool;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
use phpOMS\DataStorage\Session\HttpSession;
|
use phpOMS\DataStorage\Session\HttpSession;
|
||||||
|
|
||||||
$CONFIG = [
|
$CONFIG = [
|
||||||
|
|
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
|
||||||
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
||||||
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||||
|
|
||||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||||
|
|
||||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
public function testLogCreate() : void
|
public function testLogCreate() : void
|
||||||
{
|
{
|
||||||
$this->module->eventLogCreate(1, null, ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
$this->module->eventLogCreate(1, null, ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
||||||
$logs = AuditMapper::getAll();
|
$logs = AuditMapper::getAll()->execute();
|
||||||
|
|
||||||
foreach($logs as $log) {
|
foreach($logs as $log) {
|
||||||
if ($log->getId() > 0
|
if ($log->getId() > 0
|
||||||
|
|
@ -121,7 +121,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
public function testLogUpdate() : void
|
public function testLogUpdate() : void
|
||||||
{
|
{
|
||||||
$this->module->eventLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
$this->module->eventLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 1, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
||||||
$logs = AuditMapper::getAll();
|
$logs = AuditMapper::getAll()->execute();
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach($logs as $log) {
|
foreach($logs as $log) {
|
||||||
|
|
@ -148,9 +148,9 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testLogUpdateWithoutChange() : void
|
public function testLogUpdateWithoutChange() : void
|
||||||
{
|
{
|
||||||
$logs = AuditMapper::getAll();
|
$logs = AuditMapper::getAll()->execute();
|
||||||
$this->module->eventLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 2, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
$this->module->eventLogUpdate(1, ['id' => 2, 'test' => true], ['id' => 2, 'test' => true], 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
||||||
$logs2 = AuditMapper::getAll();
|
$logs2 = AuditMapper::getAll()->execute();
|
||||||
|
|
||||||
self::assertGreaterThan(0, \count($logs));
|
self::assertGreaterThan(0, \count($logs));
|
||||||
self::assertEquals(\count($logs), \count($logs2));
|
self::assertEquals(\count($logs), \count($logs2));
|
||||||
|
|
@ -164,7 +164,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
||||||
public function testLogDelete() : void
|
public function testLogDelete() : void
|
||||||
{
|
{
|
||||||
$this->module->eventLogDelete(1, ['id' => 1, 'test' => true], null, 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
$this->module->eventLogDelete(1, ['id' => 1, 'test' => true], null, 1, 'test-trigger', 'Auditor', 'abc', 'def');
|
||||||
$logs = AuditMapper::getAll();
|
$logs = AuditMapper::getAll()->execute();
|
||||||
|
|
||||||
foreach($logs as $log) {
|
foreach($logs as $log) {
|
||||||
if ($log->getId() > 0
|
if ($log->getId() > 0
|
||||||
|
|
|
||||||
|
|
@ -21,31 +21,4 @@ use Modules\Auditor\Models\AuditMapper;
|
||||||
*/
|
*/
|
||||||
final class AuditMapperTest extends \PHPUnit\Framework\TestCase
|
final class AuditMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @covers Modules\Auditor\Models\AuditMapper
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testInvalidDelete() : void
|
|
||||||
{
|
|
||||||
self::assertEquals(-1, AuditMapper::delete(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Auditor\Models\AuditMapper
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testInvalidUpdate() : void
|
|
||||||
{
|
|
||||||
self::assertEquals(-1, AuditMapper::update(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Auditor\Models\AuditMapper
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testInvalidUpdateArray() : void
|
|
||||||
{
|
|
||||||
$arr = [];
|
|
||||||
self::assertEquals(-1, AuditMapper::updateArray($arr));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user