mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-01-30 14:08:40 +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]);
|
||||
|
||||
$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);
|
||||
$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'));
|
||||
|
||||
AuditMapper::create($audit);
|
||||
AuditMapper::create()->execute($audit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,6 +143,6 @@ final class ApiController extends Controller
|
|||
$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'));
|
||||
|
||||
AuditMapper::create($audit);
|
||||
AuditMapper::create()->execute($audit);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Modules\Auditor\Controller;
|
|||
|
||||
use Modules\Auditor\Models\AuditMapper;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
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));
|
||||
|
||||
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') {
|
||||
$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 {
|
||||
$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;
|
||||
|
|
@ -79,7 +80,7 @@ final class BackendController extends Controller
|
|||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
||||
|
||||
/** @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);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\Auditor\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -26,7 +25,7 @@ use phpOMS\DataStorage\Database\RelationType;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class AuditMapper extends DataMapperAbstract
|
||||
final class AuditMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const 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', '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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'auditor_audit_created_by',
|
||||
|
|
@ -67,7 +66,7 @@ final class AuditMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Audit::class;
|
||||
public const MODEL = Audit::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -75,7 +74,7 @@ final class AuditMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'auditor_audit';
|
||||
public const TABLE = 'auditor_audit';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -83,7 +82,7 @@ final class AuditMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'auditor_audit_id';
|
||||
public const PRIMARYFIELD ='auditor_audit_id';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -91,29 +90,5 @@ final class AuditMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = '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;
|
||||
}
|
||||
public const CREATED_AT = 'auditor_audit_created_at';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$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('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
public function testLogCreate() : void
|
||||
{
|
||||
$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) {
|
||||
if ($log->getId() > 0
|
||||
|
|
@ -121,7 +121,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
public function testLogUpdate() : void
|
||||
{
|
||||
$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;
|
||||
foreach($logs as $log) {
|
||||
|
|
@ -148,9 +148,9 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
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');
|
||||
$logs2 = AuditMapper::getAll();
|
||||
$logs2 = AuditMapper::getAll()->execute();
|
||||
|
||||
self::assertGreaterThan(0, \count($logs));
|
||||
self::assertEquals(\count($logs), \count($logs2));
|
||||
|
|
@ -164,7 +164,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
public function testLogDelete() : void
|
||||
{
|
||||
$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) {
|
||||
if ($log->getId() > 0
|
||||
|
|
|
|||
|
|
@ -21,31 +21,4 @@ use Modules\Auditor\Models\AuditMapper;
|
|||
*/
|
||||
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