From 1906bed5cac4e750ed2a585d02ffc620e0e1c914 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 12 Apr 2024 00:52:06 +0000 Subject: [PATCH] fix bugs --- .../DatabaseExchanger/Lang/en.lang.php | 4 ++ Admin/Install/Navigation.install.json | 8 +-- Admin/Installer.php | 2 + Controller/ApiController.php | 55 +++---------------- Controller/BackendController.php | 20 +++---- Theme/Backend/exchange-import.tpl.php | 2 - 6 files changed, 25 insertions(+), 66 deletions(-) diff --git a/Admin/Install/Interfaces/DatabaseExchanger/Lang/en.lang.php b/Admin/Install/Interfaces/DatabaseExchanger/Lang/en.lang.php index 3a2141b..582a2e8 100755 --- a/Admin/Install/Interfaces/DatabaseExchanger/Lang/en.lang.php +++ b/Admin/Install/Interfaces/DatabaseExchanger/Lang/en.lang.php @@ -29,6 +29,10 @@ return [ 'Connection' => 'Connection', 'Self' => 'Self', 'Custom' => 'Custom', + 'Column1' => 'Column1', + 'Column2' => 'Column2', + 'Filter1' => 'Filter1', + 'Filter2' => 'Filter2', 'SrcType' => 'Src-Type', 'DestType' => 'Dest-Type', 'IsPrimary' => 'Is Primary?', diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 1ff6246..86f5007 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -5,7 +5,7 @@ "type": 2, "subtype": 1, "name": "Exchange", - "uri": "{/base}/admin/exchange/log/list?{?}", + "uri": "{/base}/admin/exchange/log/list", "target": "self", "icon": null, "order": 50, @@ -19,7 +19,7 @@ "type": 3, "subtype": 1, "name": "Dashboard", - "uri": "{/base}/admin/exchange/log/list?{?}", + "uri": "{/base}/admin/exchange/log/list", "target": "self", "icon": null, "order": 1, @@ -34,7 +34,7 @@ "type": 3, "subtype": 1, "name": "Import", - "uri": "{/base}/admin/exchange/import/list?{?}", + "uri": "{/base}/admin/exchange/import/list", "target": "self", "icon": null, "order": 5, @@ -49,7 +49,7 @@ "type": 3, "subtype": 1, "name": "Export", - "uri": "{/base}/admin/exchange/export/list?{?}", + "uri": "{/base}/admin/exchange/export/list", "target": "self", "icon": null, "order": 10, diff --git a/Admin/Installer.php b/Admin/Installer.php index 2a8a654..940dfbc 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Exchange\Admin; +use Modules\Exchange\Admin\Install\Media; use Modules\Exchange\Models\NullInterfaceManager; use phpOMS\Application\ApplicationAbstract; use phpOMS\Config\SettingsInterface; @@ -46,6 +47,7 @@ final class Installer extends InstallerAbstract public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void { parent::install($app, $info, $cfgHandler); + Media::install($app, self::PATH); $interfaces = \scandir(__DIR__ . '/Install/Interfaces'); if ($interfaces === false) { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 31edf68..06ca87b 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -25,7 +25,6 @@ use Modules\Exchange\Models\PermissionCategory; use Modules\Exchange\Models\Report; use Modules\Exchange\Models\SettingsEnum; use Modules\Media\Models\CollectionMapper; -use Modules\Media\Models\MediaMapper; use Modules\Media\Models\NullCollection; use Modules\Media\Models\PathSettings; use Modules\Organization\Models\UnitMapper; @@ -205,62 +204,24 @@ final class ApiController extends Controller return; } - if (!empty($uploadedFiles = $request->files)) { - $path = '/Modules/Exchange/Interface/' . $request->getData('title'); + $files = new NullCollection(); + if (!empty($request->files)) { + $path = '/Modules/Exchange/Interfaces/' . $request->getData('title'); /** @var \Modules\Media\Models\Media[] $uploaded */ - $uploaded = $this->app->moduleManager->get('Media', 'Api')->uploadFiles( + $files = $this->app->moduleManager->get('Media', 'Api')->uploadFiles( names: $request->getDataList('names'), fileNames: $request->getDataList('filenames'), - files: $uploadedFiles, + files: $request->files, account: $request->header->account, basePath: __DIR__ . '/../../../Modules/Media/Files' . $path, virtualPath: $path, - pathSettings: PathSettings::FILE_PATH + pathSettings: PathSettings::FILE_PATH, + type: $request->getDataInt('type') ); - - $collection = null; - foreach ($uploaded as $media) { - if ($request->hasData('type')) { - $this->createModelRelation( - $request->header->account, - $media->id, - $request->getDataInt('type'), - MediaMapper::class, - 'types', - '', - $request->getOrigin() - ); - } - - if ($collection === null) { - /** @var \Modules\Media\Models\Collection $collection */ - $collection = MediaMapper::getParentCollection($path) - ->limit(1) - ->execute(); - - if ($collection->id === 0) { - $collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection( - $path, - $request->header->account, - __DIR__ . '/../../../Modules/Media/Files' . $path, - ); - } - } - - $this->createModelRelation( - $request->header->account, - $collection->id, - $media->id, - CollectionMapper::class, - 'sources', - '', - $request->getOrigin() - ); - } } - $interface = $this->createInterfaceFromRequest($request, $collection?->id ?? 0); + $interface = $this->createInterfaceFromRequest($request, empty($files->sources) ? 0 : $files->id); $this->createModel($request->header->account, $interface, InterfaceManagerMapper::class, 'interface', $request->getOrigin()); $this->createStandardCreateResponse($request, $response, $interface); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index aff5319..54c7b03 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -50,21 +50,15 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Exchange/Theme/Backend/exchange-log-list'); $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1007001001, $request, $response); - $mapper = ExchangeLogMapper::getAll() + $view->data['logs'] = ExchangeLogMapper::getAll() ->with('exchange') ->with('createdBy') - ->limit(50); - - if ($request->getData('ptype') === 'p') { - $view->data['logs'] = $mapper->where('id', $request->getDataInt('offset') ?? 0, '<') - ->execute(); - } elseif ($request->getData('ptype') === 'n') { - $view->data['logs'] = $mapper->where('id', $request->getDataInt('offset') ?? 0, '>') - ->execute(); - } else { - $view->data['logs'] = $mapper->where('id', 0, '>') - ->execute(); - } + ->limit(50) + ->paginate( + 'id', + $request->getDataString('ptype') ?? '', + $request->getDataInt('offset') + )->executeGetArray(); return $view; } diff --git a/Theme/Backend/exchange-import.tpl.php b/Theme/Backend/exchange-import.tpl.php index 4f853ec..80da4be 100755 --- a/Theme/Backend/exchange-import.tpl.php +++ b/Theme/Backend/exchange-import.tpl.php @@ -19,6 +19,4 @@ echo $this->data['nav']->render(); $interface = $this->data['interface']; -$a = $interface->source->getAbsolutePath(); - include $interface->source->getAbsolutePath() . '/import.tpl.php';