mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-01-11 13:08:40 +00:00
org -> unit change, some new functionality
This commit is contained in:
parent
9c75f6001b
commit
de4f2ffb5f
13
Admin/Routes/Cli.php
Normal file
13
Admin/Routes/Cli.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^/admin/audit/blockchain/create.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Admin\Controller\CliController:cliGenerateBlockchain',
|
||||
'verb' => RouteVerb::ANY,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
@ -104,13 +104,7 @@ final class BackendController extends Controller
|
|||
|
||||
/** @var \Model\Setting[] $exportTemplates */
|
||||
$exportTemplates = $this->app->appSettings->get(
|
||||
names: [
|
||||
SettingsEnum::DEFAULT_PDF_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_EXCEL_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_CSV_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_WORD_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_EMAIL_EXPORT_TEMPLATE,
|
||||
],
|
||||
names: [SettingsEnum::DEFAULT_LIST_EXPORTS],
|
||||
module: 'Admin'
|
||||
);
|
||||
|
||||
|
|
|
|||
122
Controller/CliController.php
Normal file
122
Controller/CliController.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Admin
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Admin\Controller;
|
||||
|
||||
use Modules\Auditor\Models\AuditMapper;
|
||||
use Modules\Auditor\Models\NullAudit;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Views\View;
|
||||
|
||||
/**
|
||||
* Admin controller class.
|
||||
*
|
||||
* This class is responsible for the basic admin activities such as managing accounts, groups, permissions and modules.
|
||||
*
|
||||
* @package Modules\Admin
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class CliController extends Controller
|
||||
{
|
||||
/**
|
||||
* Method which generates the general settings view.
|
||||
*
|
||||
* In this view general settings for the entire application can be seen and adjusted. Settings which can be modified
|
||||
* here are localization, password, database, etc.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return RenderableInterface Response can be rendered
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function cliGenerateBlockchain(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : RenderableInterface
|
||||
{
|
||||
$view = new View($this->app->l11nManager, $request, $response);
|
||||
$view->setTemplate('/Modules/Auditor/Theme/Cli/blockchain');
|
||||
|
||||
$first = AuditMapper::get()
|
||||
->where('blockchain', null)
|
||||
->sort('id', OrderType::ASC)
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
if ($first->getId() === 1) {
|
||||
$first = AuditMapper::get()
|
||||
->where('id', $first->getId() + 1)
|
||||
->execute();
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
if (!($first instanceof NullAudit)) {
|
||||
$last = AuditMapper::get()
|
||||
->sort('id', OrderType::DESC)
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
$previous = AuditMapper::get()
|
||||
->where('id', $first->getId() - 1)
|
||||
->execute();
|
||||
|
||||
$current = $first;
|
||||
$endLastBatchId = $first->getId() - 1;
|
||||
|
||||
while ($current->getId() !== 0 && $current->getId() <= $last->getId()) {
|
||||
$batch = AuditMapper::getAll()
|
||||
->where('id', $endLastBatchId, '>')
|
||||
->sort('id', OrderType::ASC)
|
||||
->limit(50)
|
||||
->execute();
|
||||
|
||||
foreach ($batch as $audit) {
|
||||
$current = $audit;
|
||||
|
||||
$current->blockchain = \md5(
|
||||
$previous->blockchain
|
||||
. $current->getId()
|
||||
. $current->createdBy->getId()
|
||||
. $current->createdAt->format('Y-m-d H:i:s')
|
||||
. $current->type
|
||||
. $current->trigger
|
||||
. $current->module
|
||||
. $current->ref
|
||||
. $current->old
|
||||
. $current->new
|
||||
. $current->content
|
||||
);
|
||||
|
||||
AuditMapper::update()->with('blockchain')->execute($current);
|
||||
++$count;
|
||||
|
||||
$previous = $current;
|
||||
}
|
||||
|
||||
$endLastBatchId = $current->getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$view->setData('count', $count);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +119,14 @@ class Audit
|
|||
*/
|
||||
public int $ip = 0;
|
||||
|
||||
/**
|
||||
* Blockchain.
|
||||
*
|
||||
* @var null|string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public ?string $blockchain = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ final class AuditMapper extends DataMapperFactory
|
|||
'auditor_audit_content' => ['name' => 'auditor_audit_content', 'type' => 'string', 'internal' => 'content'],
|
||||
'auditor_audit_old' => ['name' => 'auditor_audit_old', 'type' => 'compress', 'internal' => 'old'],
|
||||
'auditor_audit_new' => ['name' => 'auditor_audit_new', 'type' => 'compress', 'internal' => 'new'],
|
||||
'auditor_audit_blockchain' => ['name' => 'auditor_audit_blockchain', 'type' => 'string', 'internal' => 'blockchain', 'readonly' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ declare(strict_types=1);
|
|||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var \Web\Backend\Views\TableView $this
|
||||
* @var \Modules\Audit\Models\Audit[] $audits
|
||||
*/
|
||||
$audits = $this->getData('audits') ?? [];
|
||||
|
||||
$tableView = $this->getData('tableView');
|
||||
$tableView->id = 'auditList';
|
||||
$tableView->baseUri = 'admin/audit/list';
|
||||
$tableView->baseUri = '{/lang}/{/app}/admin/audit/list';
|
||||
$tableView->exportUri = '{/api}auditor/list/export';
|
||||
$tableView->setObjects($audits);
|
||||
|
||||
|
|
|
|||
15
Theme/Cli/blockchain.tpl.php
Normal file
15
Theme/Cli/blockchain.tpl.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Auditor
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
echo 'Generated blockchain for ' . \escapeshellcmd($this->getData('count') ?? 0) . ' elements.' . "\n";
|
||||
|
|
@ -53,7 +53,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
|
|||
};
|
||||
|
||||
$this->app->dbPool = $GLOBALS['dbpool'];
|
||||
$this->app->orgId = 1;
|
||||
$this->app->unitId = 1;
|
||||
$this->app->accountManager = new AccountManager($GLOBALS['session']);
|
||||
$this->app->appSettings = new CoreSettings();
|
||||
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user