mirror of
https://github.com/Karaka-Management/oms-Exchange.git
synced 2026-01-31 02:08:40 +00:00
start language import/export exchanger
This commit is contained in:
parent
2d199d2227
commit
b0a3bb4123
|
|
@ -160,6 +160,47 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public function apiExchangeExport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$export = $this->exportDataFromRequest($request);
|
||||
$status = NotificationLevel::ERROR;
|
||||
$message = 'Export failed.';
|
||||
|
||||
if ($export) {
|
||||
$status = NotificationLevel::OK;
|
||||
$message = 'Export succeeded.';
|
||||
}
|
||||
|
||||
$response->set($request->uri->__toString(), [
|
||||
'status' => $status,
|
||||
'title' => 'Exchange',
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to export data based on a request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function exportDataFromRequest(RequestAbstract $request) : bool
|
||||
{
|
||||
/** @var \Modules\Exchange\Models\InterfaceManager[] $interfaces */
|
||||
$interfaces = InterfaceManagerMapper::getAll();
|
||||
foreach ($interfaces as $interface) {
|
||||
if ($request->getData('exchange') ?? '' === $interface->getInterfacePath()) {
|
||||
$class = '\\Modules\\Exchange\\Interfaces\\' . $interface->getInterfacePath() . '\\Exporter';
|
||||
$exporter = new $class($this->app->dbPool->get());
|
||||
|
||||
return $exporter->exportFromRequest($request);
|
||||
}
|
||||
}
|
||||
|
||||
Directory::delete(__DIR__ . '/../tmp/');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
0
Interfaces/OMS/Export/LanguageExport.php
Normal file
0
Interfaces/OMS/Export/LanguageExport.php
Normal file
102
Interfaces/OMS/Exporter.php
Normal file
102
Interfaces/OMS/Exporter.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Interfaces
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Exchange\Interfaces\OMS;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
|
||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
use phpOMS\Utils\IO\Zip\Zip;
|
||||
|
||||
/**
|
||||
* OMS export class
|
||||
*
|
||||
* @package Modules\Exchange\Models\Interfaces\OMS
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Exporter extends ExporterAbstract
|
||||
{
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var ConnectionAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ConnectionAbstract $remote;
|
||||
|
||||
/**
|
||||
* Account
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $account = 1;
|
||||
|
||||
/**
|
||||
* Export all data in time span
|
||||
*
|
||||
* @param \DateTime $start Start time (inclusive)
|
||||
* @param \DateTime $end End time (inclusive)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function export(\DateTime $start, \DateTime $end) : void
|
||||
{
|
||||
$this->exportLanguage($start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export data from request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function exportFromRequest(RequestAbstract $request) : bool
|
||||
{
|
||||
$start = new \DateTime($request->getData('start') ?? 'now');
|
||||
$end = new \DateTime($request->getData('end') ?? 'now');
|
||||
|
||||
$this->account = $request->header->account;
|
||||
|
||||
if (((bool) ($request->getData('language') ?? false))) {
|
||||
$this->exportLanguage();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export language
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function exportLanguage() : void
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
0
Interfaces/OMS/Import/LanguageImport.php
Normal file
0
Interfaces/OMS/Import/LanguageImport.php
Normal file
121
Interfaces/OMS/Importer.php
Normal file
121
Interfaces/OMS/Importer.php
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Interfaces
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Exchange\Interfaces\OMS;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
|
||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
use phpOMS\Utils\IO\Zip\Zip;
|
||||
use Modules\Media\Controller\ApiController;
|
||||
|
||||
/**
|
||||
* OMS import class
|
||||
*
|
||||
* @package Modules\Exchange\Models\Interfaces\OMS
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Importer extends ImporterAbstract
|
||||
{
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var ConnectionAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ConnectionAbstract $remote;
|
||||
|
||||
/**
|
||||
* Account
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $account = 1;
|
||||
|
||||
/**
|
||||
* Import all data in time span
|
||||
*
|
||||
* @param \DateTime $start Start time (inclusive)
|
||||
* @param \DateTime $end End time (inclusive)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function import(\DateTime $start, \DateTime $end) : void
|
||||
{
|
||||
$this->importLanguage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import data from request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function importFromRequest(RequestAbstract $request) : bool
|
||||
{
|
||||
$start = new \DateTime($request->getData('start') ?? 'now');
|
||||
$end = new \DateTime($request->getData('end') ?? 'now');
|
||||
|
||||
if ($request->getData('db') !== null) {
|
||||
$this->remote = ConnectionFactory::create([
|
||||
'db' => (string) ($request->getData('db') ?? ''),
|
||||
'host' => (string) ($request->getData('host') ?? ''),
|
||||
'port' => (int) ($request->getData('port') ?? 0),
|
||||
'database' => (string) ($request->getData('database') ?? ''),
|
||||
'login' => (string) ($request->getData('login') ?? ''),
|
||||
'password' => (string) ($request->getData('password') ?? ''),
|
||||
'datetimeformat' => (string) ($request->getData('datetimeformat') ?? 'Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$this->remote->connect();
|
||||
|
||||
if ($this->remote->getStatus() !== DatabaseStatus::OK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->account = $request->header->account;
|
||||
|
||||
if (((bool) ($request->getData('language') ?? false))) {
|
||||
$this->importLanguage($request);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import language
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function importLanguage(RequestAbstract $request) : void
|
||||
{
|
||||
$upload = ApiController::uploadFilesToDestination($request->getFiles());
|
||||
}
|
||||
}
|
||||
0
Interfaces/OMS/export.tpl.php
Normal file
0
Interfaces/OMS/export.tpl.php
Normal file
19
Interfaces/OMS/import.tpl.php
Normal file
19
Interfaces/OMS/import.tpl.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<section class="portlet">
|
||||
<form id="fImport" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/api}admin/exchange/import/profile?{?}&exchange=OMS&type=language&csrf={$CSRF}'); ?>">
|
||||
<div class="portlet-head"><?= $this->getHtml('Langauge'); ?> - OMS</div>
|
||||
<div class="portlet-body">
|
||||
<table class="layout wf-100" style="table-layout: fixed">
|
||||
<tbody>
|
||||
<tr><td><label for="iFile"><?= $this->getHtml('File'); ?></label>
|
||||
<tr><td><input type="file" id="iFile" name="file" placeholder=" <?= $this->getHtml('File'); ?>" required>
|
||||
</table>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<input type="submit" value="<?= $this->getHtml('Import'); ?>">
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,5 +4,5 @@
|
|||
"website": "",
|
||||
"path": "OMS",
|
||||
"export": true,
|
||||
"import": false
|
||||
"import": true
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user