Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Xentral\Modules\ApiAccount;
use Xentral\Core\DependencyInjection\ContainerInterface;
use Xentral\Modules\ApiAccount\Service\ApiAccountService;
class Bootstrap
{
/**
* @return array
*/
public static function registerServices():array
{
return [
'ApiAccountService' => 'onInitApiAccountService'
];
}
/**
* @param ContainerInterface $container
*
* @return ApiAccountService
*/
public static function onInitApiAccountService(ContainerInterface $container):ApiAccountService
{
return new ApiAccountService(
$container->get('Database'),
$container->get('SystemConfigModule'),
$container->get('Logger')
);
}
}
@@ -0,0 +1,245 @@
<?php
declare(strict_types=1);
namespace Xentral\Modules\ApiAccount\Data;
final class ApiAccountData
{
/** @var int $id */
private $id;
/** @var string $name */
private $name;
/** @var string $initKey */
private $initKey;
/** @var string $importQueueName */
private $importQueueName;
/** @var string $eventUrl */
private $eventUrl;
/** @var string $remoteDomain */
private $remoteDomain;
/** @var bool $active */
private $active;
/** @var bool $importQueueActive */
private $importQueueActive;
/** @var bool $cleanUtf8Active */
private $cleanUtf8Active;
/** @var int $transferAccountId */
private $transferAccountId;
/** @var int $projectId */
private $projectId;
/** @var string $permissions */
private $permissions;
/** @var bool $isLegacy */
private $isLegacy;
/** @var bool */
private $isHtmlTransformation;
/**
* @param int $apiAccountId
* @param string $name
* @param string $initKey
* @param string $importQueueName
* @param string $eventUrl
* @param string $remoteDomain
* @param bool $active
* @param bool $importQueueActive
* @param bool $cleanUtf8Active
* @param int $transferAccountId
* @param int $projectId
* @param string|null $permissions
* @param bool $isLegacy
* @param bool $isHtmlTransformation
*/
public function __construct(
int $apiAccountId,
string $name,
string $initKey,
string $importQueueName,
string $eventUrl,
string $remoteDomain,
bool $active,
bool $importQueueActive,
bool $cleanUtf8Active,
int $transferAccountId,
int $projectId,
?string $permissions,
bool $isLegacy,
bool $isHtmlTransformation
) {
$this->id = $apiAccountId;
$this->name = $name;
$this->initKey = $initKey;
$this->importQueueName = $importQueueName;
$this->eventUrl = $eventUrl;
$this->remoteDomain = $remoteDomain;
$this->active = $active;
$this->importQueueActive = $importQueueActive;
$this->cleanUtf8Active = $cleanUtf8Active;
$this->transferAccountId = $transferAccountId;
$this->projectId = $projectId;
$this->permissions = $permissions;
$this->isLegacy = $isLegacy;
$this->isHtmlTransformation = $isHtmlTransformation;
}
/**
* @param array $formData
*
* @return ApiAccountData
*/
public static function fromFormData(array $formData): ApiAccountData
{
$apiAccountData = new self(
$formData['id'], $formData['name'], $formData['init_key'], $formData['import_queue_name'],
$formData['event_url'], $formData['remotedomain'], $formData['active'],
$formData['import_queue'], $formData['cleanutf8'], $formData['transfer_account_id'],
$formData['project_id'], $formData['permissions'], $formData['is_legacy'], $formData['is_html_transformation']
);
return $apiAccountData;
}
/**
* @param array $apiAccountRow
*
* @return ApiAccountData
*/
public static function fromDbState(array $apiAccountRow): ApiAccountData
{
$apiAccountData = new self(
$apiAccountRow['id'], $apiAccountRow['bezeichnung'], $apiAccountRow['initkey'],
$apiAccountRow['importwarteschlange_name'], $apiAccountRow['event_url'],
$apiAccountRow['remotedomain'], (bool) $apiAccountRow['aktiv'],
(bool) $apiAccountRow['importwarteschlange'], (bool) $apiAccountRow['cleanutf8'],
$apiAccountRow['uebertragung_account'], $apiAccountRow['projekt'],
$apiAccountRow['permissions'],
(bool) $apiAccountRow['is_legacy'], (bool) $apiAccountRow['ishtmltransformation']
);
return $apiAccountData;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return string
*/
public function getInitKey(): string
{
return $this->initKey;
}
/**
* @return string
*/
public function getImportQueueName(): string
{
return $this->importQueueName;
}
/**
* @return string
*/
public function getEventUrl(): string
{
return $this->eventUrl;
}
/**
* @return string
*/
public function getRemoteDomain(): string
{
return $this->remoteDomain;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
/**
* @return bool
*/
public function isImportQueueActive(): bool
{
return $this->importQueueActive;
}
/**
* @return bool
*/
public function isCleanUtf8Active(): bool
{
return $this->cleanUtf8Active;
}
/**
* @return int
*/
public function getTransferAccountId(): int
{
return $this->transferAccountId;
}
/**
* @return int
*/
public function getProjectId(): int
{
return $this->projectId;
}
/**
* @return string|null
*/
public function getPermissions(): ?string
{
return $this->permissions;
}
/**
* @return bool
*/
public function isLegacy(): bool
{
return $this->isLegacy;
}
public function isHtmlTransformationActive(): bool
{
return $this->isHtmlTransformation;
}
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\ApiAccount\Exception;
use Xentral\Core\Exception\ModuleExceptionInterface;
interface ApiAccountExceptionInterface extends ModuleExceptionInterface
{
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\ApiAccount\Exception;
use RuntimeException;
class ApiAccountNotFoundException extends RuntimeException implements ApiAccountExceptionInterface
{
}
@@ -0,0 +1,9 @@
<?php
namespace Xentral\Modules\ApiAccount\Exception;
use InvalidArgumentException as SplInvalidArgumentException;
class InvalidArgumentException extends SplInvalidArgumentException implements ApiAccountExceptionInterface
{
}
@@ -0,0 +1,197 @@
<?php
declare(strict_types=1);
namespace Xentral\Modules\ApiAccount\Service;
use Psr\Log\LogLevel;
use Xentral\Components\Database\Database;
use Xentral\Components\Logger\Logger;
use Xentral\Modules\ApiAccount\Data\ApiAccountData;
use Xentral\Modules\ApiAccount\Exception\ApiAccountNotFoundException;
use Xentral\Modules\ApiAccount\Exception\InvalidArgumentException;
use Xentral\Modules\SystemConfig\Exception\ConfigurationKeyNotFoundException;
use Xentral\Modules\SystemConfig\SystemConfigModule;
final class ApiAccountService
{
/** @var Database $db */
private $db;
/** @var SystemConfigModule */
private $systemConfig;
/** @var Logger */
private $logger;
public function __construct(Database $database, SystemConfigModule $systemConfig, Logger $logger)
{
$this->db = $database;
$this->systemConfig = $systemConfig;
$this->logger = $logger;
}
/**
* @param ApiAccountData $apiAccount
*
* @return int
*/
public function createApiAccount(ApiAccountData $apiAccount): int
{
$this->db->perform(
'INSERT INTO `api_account`
(`bezeichnung`,`initkey`, `importwarteschlange_name`, `event_url`, `remotedomain`, `aktiv`,
`importwarteschlange`, `cleanutf8`, `uebertragung_account`, `projekt`, `permissions`,
`is_legacy`, `ishtmltransformation`)
VALUES (:name, :init_key, :import_queue_name, :event_url, :remotedomain, :active, :import_queue,
:cleanutf8, :transfer_account_id, :project_id, :permissions, :is_legacy, :is_html_transformation)',
[
'name' => $apiAccount->getName(),
'init_key' => $apiAccount->getInitKey(),
'import_queue_name' => $apiAccount->getImportQueueName(),
'event_url' => $apiAccount->getEventUrl(),
'remotedomain' => $apiAccount->getRemoteDomain(),
'active' => $apiAccount->isActive(),
'import_queue' => $apiAccount->isImportQueueActive(),
'cleanutf8' => $apiAccount->isCleanUtf8Active(),
'transfer_account_id' => $apiAccount->getTransferAccountId(),
'project_id' => $apiAccount->getProjectId(),
'permissions' => $apiAccount->getPermissions(),
'is_legacy' => $apiAccount->isLegacy(),
'is_html_transformation' => $apiAccount->isHtmlTransformationActive(),
]
);
return $this->db->lastInsertId();
}
/**
* @param ApiAccountData $apiAccount
*
* @throws InvalidArgumentException
*
* @return void
*/
public function updateApiAccount(ApiAccountData $apiAccount): void
{
$apiAccountId = $apiAccount->getId();
if ($apiAccountId < 1) {
throw new InvalidArgumentException(sprintf('Api account with id %d not found', $apiAccountId));
}
$this->db->perform(
'UPDATE `api_account`
SET `bezeichnung` = :name,
`initkey` = :initkey,
`importwarteschlange_name` = :import_queue_name,
`event_url` = :event_url,
`remotedomain` = :remotedomain,
`aktiv` = :active,
`importwarteschlange` = :import_queue,
`cleanutf8` = :cleanutf8,
`uebertragung_account` = :transfer_account_id,
`projekt` = :project_id,
`permissions` = :permissions,
`is_legacy` = :is_legacy,
`ishtmltransformation` = :is_html_transformation
WHERE `id` = :id',
[
'name' => $apiAccount->getName(),
'initkey' => $apiAccount->getInitKey(),
'import_queue_name' => $apiAccount->getImportQueueName(),
'event_url' => $apiAccount->getEventUrl(),
'remotedomain' => $apiAccount->getRemoteDomain(),
'active' => $apiAccount->isActive(),
'import_queue' => $apiAccount->isImportQueueActive(),
'cleanutf8' => $apiAccount->isCleanUtf8Active(),
'transfer_account_id' => $apiAccount->getTransferAccountId(),
'project_id' => $apiAccount->getProjectId(),
'permissions' => $apiAccount->getPermissions(),
'is_legacy' => $apiAccount->isLegacy(),
'is_html_transformation' => $apiAccount->isHtmlTransformationActive(),
'id' => $apiAccountId,
]
);
}
/**
* @param int $apiAccountId
*
* @throws InvalidArgumentException
*
* @throws ApiAccountNotFoundException
*
* @return ApiAccountData
*/
public function getApiAccountById(int $apiAccountId): ApiAccountData
{
if ($apiAccountId === 0) {
try {
$this->logger->log(LogLevel::DEBUG, 'API account retrieved with id 0');
$apiAccountId = $this->systemConfig->getValue('apiaccount', 'migratedapiid');
} catch (ConfigurationKeyNotFoundException $e) {
throw new ApiAccountNotFoundException(sprintf('Api account with id %d not found', $apiAccountId), 0, $e);
}
}
$apiAccountRow = $this->db->fetchRow(
'SELECT a.id, a.bezeichnung, a.initkey, a.importwarteschlange_name, a.event_url, a.remotedomain, a.aktiv,
a.importwarteschlange, a.cleanutf8, a.uebertragung_account, a.projekt, a.permissions, a.is_legacy, a.ishtmltransformation
FROM `api_account` AS `a`
WHERE a.id = :id
LIMIT 1',
['id' => $apiAccountId]
);
if (empty($apiAccountRow)) {
throw new ApiAccountNotFoundException(sprintf('Api account with id %d not found', $apiAccountId));
}
return ApiAccountData::fromDbState($apiAccountRow);
}
/**
* @param string $apiAccountRemoteDomain
*
* @throws InvalidArgumentException
*
* @throws ApiAccountNotFoundException
*
* @return ApiAccountData
*/
public function getApiAccountByRemoteDomain(string $apiAccountRemoteDomain): ApiAccountData
{
if ($apiAccountRemoteDomain === '') {
throw new InvalidArgumentException(
sprintf('Api account with remote domain %s not found', $apiAccountRemoteDomain)
);
}
$apiAccountRow = $this->db->fetchRow(
'SELECT a.id, a.bezeichnung, a.initkey, a.importwarteschlange_name, a.event_url, a.remotedomain, a.aktiv,
a.importwarteschlange, a.cleanutf8, a.uebertragung_account, a.projekt, a.permissions, a.is_legacy, a.ishtmltransformation
FROM `api_account` AS `a`
WHERE a.remotedomain = :remotedomain
LIMIT 1',
['remotedomain' => $apiAccountRemoteDomain]
);
if (empty($apiAccountRow)) {
throw new ApiAccountNotFoundException(sprintf('Api account with id %d not found', $apiAccountRemoteDomain));
}
return ApiAccountData::fromDbState($apiAccountRow);
}
/**
* @param int $apiAccountId
*
* @return void
*/
public function deleteApiAccountById(int $apiAccountId): void
{
$this->db->perform(
'DELETE FROM `api_account` WHERE `id` = :id',
['id' => $apiAccountId]
);
}
}
@@ -0,0 +1,138 @@
var ApiAccount = function ($) {
'use strict';
var me = {
storage: {
actualId: null
},
selector: {
listTable: '#api_account_list',
editPopup: '#apiAccountPopup'
},
updateLiveTable: function () {
$('#api_account_list').DataTable().ajax.reload();
},
open: function (id) {
me.storage.actualId = id;
$.ajax({
url: 'index.php?module=api_account&action=list&cmd=get',
type: 'POST',
dataType: 'json',
data: {
id: me.storage.actualId
},
success: function (data) {
$('#api-account-id').text(data.id);
$('#aktiv').prop('checked', data.aktiv === '1');
$('#bezeichnung').val(data.bezeichnung);
$('#projekt').val(data.projekt);
$('#remotedomain').val(data.remotedomain);
$('#initkey').val(data.initkey);
$('#apitempkey').html(data.apitempkey);
$('#event_url').val(data.event_url);
$('#importwarteschlange_name').val(data.importwarteschlange_name);
$('#importwarteschlange').prop('checked', data.importwarteschlange === '1');
$('#cleanutf8').prop('checked', data.cleanutf8==='1');
$('#ishtmltransformation').prop('checked', data.ishtmltransformation === '1');
$('#apiAccountPopup').dialog('open');
var permissions = JSON.parse(data.permissions);
$('.permission-checkbox').each(function () {
var self = $(this)
if(permissions.indexOf(self.attr('name')) > -1){
self.prop('checked', true)
}
})
},
error: function (e) {
if (typeof e.responseJSON !== 'undefined' && typeof e.responseJSON.error !== 'undefined') {
alert(e.responseJSON.error);
}
},
beforeSend: function () {
}
});
},
init: function () {
if ($(me.selector.editPopup).length === 0) {
return;
}
$('#submenu-wrapper div.new a').on('click', function () {
me.open(0);
});
$(me.selector.listTable).on('afterreload', function () {
$('#api_account_list .get').on('click', function () {
me.open($(this).data('id'));
});
});
$(me.selector.listTable).trigger('afterreload');
$(me.selector.editPopup).dialog(
{
modal: true,
autoOpen: false,
minWidth: 940,
title: '',
buttons: {
'SPEICHERN': function () {
var permissions = {};
$('.permission-checkbox').each(function () {
var self = $(this)
permissions[self.attr('name')] = self.is(':checked')
})
$.ajax({
url: 'index.php?module=api_account&action=list&cmd=save',
type: 'POST',
dataType: 'json',
data: {
id: me.storage.actualId,
aktiv: $('#aktiv').prop('checked') ? 1 : 0,
bezeichnung: $('#bezeichnung').val(),
projekt: $('#projekt').val(),
remotedomain: $('#remotedomain').val(),
initkey: $('#initkey').val(),
event_url: $('#event_url').val(),
importwarteschlange_name: $('#importwarteschlange_name').val(),
importwarteschlange: $('#importwarteschlange').prop('checked') ? 1 : 0,
cleanutf8: $('#cleanutf8').prop('checked') ? 1 : 0,
ishtmltransformation: $('#ishtmltransformation').prop('checked') ? 1 : 0,
api_permissions: permissions,
},
success: function () {
me.storage.actualId = null;
me.updateLiveTable();
$(me.selector.editPopup).dialog('close');
},
error: function (e) {
if (typeof e.responseJSON !== 'undefined' && typeof e.responseJSON.error !==
'undefined') {
alert(e.responseJSON.error);
}
},
beforeSend: function () {
}
});
},
'ABBRECHEN': function () {
$(this).dialog('close');
me.storage.actualId = null;
}
},
close: function (event, ui) {
}
});
$(me.selector.editPopup).toggleClass('hidden', false);
}
};
return {
init: me.init
};
}(jQuery);
$(document).ready(function () {
ApiAccount.init();
});