From bff69f27dca0a2a8db7df8fc0d66b77c1e5dd0d1 Mon Sep 17 00:00:00 2001 From: Benjamin Hummel <55982921+xprojects-de@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:07:14 +0100 Subject: [PATCH 01/27] bugfixes php8 warnings --- .idea/php.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.idea/php.xml b/.idea/php.xml index 7012789..771cf1b 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,14 @@ + + + + + + @@ -206,6 +215,11 @@ + + @@ -216,4 +230,8 @@ + + \ No newline at end of file From 106565d72ab1899d58432bc5e5b9ee6911bdc0b9 Mon Sep 17 00:00:00 2001 From: Benjamin Hummel <55982921+xprojects-de@users.noreply.github.com> Date: Wed, 7 Dec 2022 07:10:02 +0100 Subject: [PATCH 02/27] bugfixes --- .idea/alpdesk-core.iml | 1 + .idea/php.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/.idea/alpdesk-core.iml b/.idea/alpdesk-core.iml index cc0dfa1..d84e8df 100644 --- a/.idea/alpdesk-core.iml +++ b/.idea/alpdesk-core.iml @@ -191,6 +191,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index 771cf1b..7f8aa39 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -196,6 +196,7 @@ + From 36b01d0695c9565399f07f8279d9d9c703fb2e19 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Mon, 3 Jul 2023 21:30:08 +0200 Subject: [PATCH 03/27] update dependencies --- .idea/php.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.idea/php.xml b/.idea/php.xml index 7f8aa39..63fe98c 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -197,6 +197,25 @@ + + + + + + + + + + + + + + + + + + + From a49d79a131ee22cf663dcf2015e46ac0a31ae3cc Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 19 Oct 2023 12:48:12 +0200 Subject: [PATCH 04/27] update dependencies --- .idea/alpdesk-core.iml | 10 +++++++ .idea/codeception.xml | 12 +++++++++ .idea/inspectionProfiles/Project_Default.xml | 21 +-------------- .idea/php.xml | 28 +++++++------------- .idea/phpspec.xml | 13 +++++++++ 5 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 .idea/codeception.xml create mode 100644 .idea/phpspec.xml diff --git a/.idea/alpdesk-core.iml b/.idea/alpdesk-core.iml index d84e8df..7b154a1 100644 --- a/.idea/alpdesk-core.iml +++ b/.idea/alpdesk-core.iml @@ -192,6 +192,16 @@ + + + + + + + + + + diff --git a/.idea/codeception.xml b/.idea/codeception.xml new file mode 100644 index 0000000..330f2dd --- /dev/null +++ b/.idea/codeception.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index eaf0f78..380c3fb 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,11 +1,6 @@ \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml index 63fe98c..7506af6 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -197,25 +197,17 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/.idea/phpspec.xml b/.idea/phpspec.xml new file mode 100644 index 0000000..ec7e1d4 --- /dev/null +++ b/.idea/phpspec.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file From 4002d2f9f1431ec8c527e4d866853f172293e626 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 11:33:25 +0100 Subject: [PATCH 05/27] support darkMode --- .idea/deployment.xml | 3 ++- src/Resources/public/css/alpdeskcore_logs.css | 12 ++++++++++++ .../css/alpdeskcore_widget_databasemanager.css | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 2c0100e..2070d7c 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,7 +1,8 @@ - + + \ No newline at end of file diff --git a/src/Controller/Auth/AlpdeskCoreAuthController.php b/src/Controller/Auth/AlpdeskCoreAuthController.php index bd60585..c86a794 100644 --- a/src/Controller/Auth/AlpdeskCoreAuthController.php +++ b/src/Controller/Auth/AlpdeskCoreAuthController.php @@ -89,9 +89,9 @@ public function auth(Request $request): JsonResponse $this->framework->initialize(); - $authdata = (array)\json_decode($request->getContent(), true); + $authData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); - $response = (new AlpdeskCoreAuthToken($this->passwordHasherFactory))->generateToken($authdata); + $response = (new AlpdeskCoreAuthToken($this->passwordHasherFactory))->generateToken($authData); $event = new AlpdeskCoreAuthSuccessEvent($response); $this->eventService->getDispatcher()->dispatch($event, AlpdeskCoreAuthSuccessEvent::NAME); @@ -116,11 +116,10 @@ public function auth(Request $request): JsonResponse } /** - * @param Request $request * @param UserInterface $user * @return JsonResponse */ - public function verify(Request $request, UserInterface $user): JsonResponse + public function verify(UserInterface $user): JsonResponse { try { @@ -165,7 +164,7 @@ public function refresh(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); - $refreshData = (array)\json_decode($request->getContent(), true); + $refreshData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); $response = (new AlpdeskCoreAuthToken($this->passwordHasherFactory))->refreshToken($refreshData, $user); @@ -202,39 +201,39 @@ public function member(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); - $memberdata = (array)\json_decode($request->getContent(), true); - - if ($user->getIsAdmin() === true) { + $memberData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); - if (\array_key_exists('mandantid', $memberdata)) { + if (\array_key_exists('mandantid', $memberData) && $user->getIsAdmin() === true) { - $mandantId = (string)AlpdeskcoreInputSecurity::secureValue($memberdata['mandantid']); + $mandantId = (string)AlpdeskcoreInputSecurity::secureValue($memberData['mandantid']); - if ($mandantId !== "") { + if ($mandantId !== "") { - if ($mandantId === "0") { + if ($mandantId === "0") { - $memberObject = MemberModel::findByPk($user->getMemberId()); - if ($memberObject !== null) { - $memberObject->alpdeskcore_mandant = 0; - $memberObject->save(); - $user->setMandantPid(0); - } - } else { + $memberObject = MemberModel::findByPk($user->getMemberId()); + if ($memberObject !== null) { + $memberObject->alpdeskcore_mandant = 0; + $memberObject->save(); + $user->setMandantPid(0); + } + } else { - if (!\array_key_exists((int)$mandantId, $user->getMandantWhitelist())) { - throw new AlpdeskCoreAuthException('mandantid not in whitelistarray', AlpdeskCoreConstants::$ERROR_INVALID_MANDANT); - } + if (!\array_key_exists((int)$mandantId, $user->getMandantWhitelist())) { + throw new AlpdeskCoreAuthException('mandantid not in whitelistarray', AlpdeskCoreConstants::$ERROR_INVALID_MANDANT); + } - $memberObject = MemberModel::findByPk($user->getMemberId()); - if ($memberObject !== null) { - $memberObject->alpdeskcore_mandant = (int)$mandantId; - $memberObject->save(); - $user->setMandantPid((int)$mandantId); - } + $memberObject = MemberModel::findByPk($user->getMemberId()); + if ($memberObject !== null) { + $memberObject->alpdeskcore_mandant = (int)$mandantId; + $memberObject->save(); + $user->setMandantPid((int)$mandantId); } + } + } + } $response = [ @@ -262,11 +261,10 @@ public function member(Request $request, UserInterface $user): JsonResponse } /** - * @param Request $request * @param UserInterface $user * @return JsonResponse */ - public function logout(Request $request, UserInterface $user): JsonResponse + public function logout(UserInterface $user): JsonResponse { try { @@ -291,6 +289,7 @@ public function logout(Request $request, UserInterface $user): JsonResponse return $this->outputError($exception->getMessage(), $exception->getCode(), AlpdeskCoreConstants::$STATUSCODE_COMMONERROR); } + } } From ceb71c73a0eb55e07551f91cfa8e843e21d8ac7b Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 11:51:44 +0100 Subject: [PATCH 07/27] code cleanUp --- src/Controller/Logs/AlpdeskcoreLogsController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Controller/Logs/AlpdeskcoreLogsController.php b/src/Controller/Logs/AlpdeskcoreLogsController.php index c1adc03..00a1e39 100644 --- a/src/Controller/Logs/AlpdeskcoreLogsController.php +++ b/src/Controller/Logs/AlpdeskcoreLogsController.php @@ -10,9 +10,9 @@ use Contao\File; use Contao\Input; use Contao\System; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; @@ -44,9 +44,12 @@ public function __construct( $this->security = $security; } - private function getCurrentSession(): SessionInterface + /** + * @return SessionInterface|null + */ + private function getCurrentSession(): ?SessionInterface { - return $this->requestStack->getCurrentRequest()->getSession(); + return $this->requestStack->getCurrentRequest()?->getSession(); } /** @@ -138,9 +141,9 @@ private function checkFilter(): void $filterValue = Input::postRaw('filterValue'); if ($filterValue !== null) { - $this->getCurrentSession()->set('alpdeskcore_logsfilter', $filterValue); + $this->getCurrentSession()?->set('alpdeskcore_logsfilter', $filterValue); } else { - $this->getCurrentSession()->set('alpdeskcore_logsfilter', null); + $this->getCurrentSession()?->set('alpdeskcore_logsfilter', null); } Controller::redirect($this->router->generate('alpdesk_logs_backend')); @@ -184,7 +187,7 @@ public function endpoint(): Response System::loadLanguageFile('default'); - $filterValue = $this->getCurrentSession()->get('alpdeskcore_logsfilter'); + $filterValue = $this->getCurrentSession()?->get('alpdeskcore_logsfilter'); if ($filterValue === null) { $filterValue = ''; } From 01f73cc46267c9d525a5919a7fc31e375a86aa4c Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 11:53:05 +0100 Subject: [PATCH 08/27] code cleanUp --- src/Controller/Mandant/AlpdeskCoreMandantController.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Controller/Mandant/AlpdeskCoreMandantController.php b/src/Controller/Mandant/AlpdeskCoreMandantController.php index bd19399..61687d1 100644 --- a/src/Controller/Mandant/AlpdeskCoreMandantController.php +++ b/src/Controller/Mandant/AlpdeskCoreMandantController.php @@ -8,7 +8,6 @@ use Contao\CoreBundle\Framework\ContaoFramework; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Request; use Alpdesk\AlpdeskCore\Library\Mandant\AlpdeskCoreMandant; use Alpdesk\AlpdeskCore\Library\Constants\AlpdeskCoreConstants; use Alpdesk\AlpdeskCore\Events\AlpdeskCoreEventService; @@ -30,7 +29,6 @@ public function __construct( ) { $this->framework = $framework; - $this->eventService = $eventService; $this->logger = $logger; } @@ -79,11 +77,10 @@ private function outputError(string $data, mixed $code, int $statusCode): JsonRe } /** - * @param Request $request * @param UserInterface $user * @return JsonResponse */ - public function list(Request $request, UserInterface $user): JsonResponse + public function list(UserInterface $user): JsonResponse { try { @@ -111,12 +108,11 @@ public function list(Request $request, UserInterface $user): JsonResponse } /** - * @param Request $request * @param UserInterface $user * @return JsonResponse * @throws \Exception */ - public function edit(Request $request, UserInterface $user): JsonResponse + public function edit(UserInterface $user): JsonResponse { if (!($user instanceof AlpdeskcoreUser)) { throw new \Exception('invalid user type'); From 8e69afe94e691697fa4a5c18364b995c3567eef0 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 11:54:20 +0100 Subject: [PATCH 09/27] code cleanUp --- .../Filemanagement/AlpdeskCoreFilemanagementController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/Filemanagement/AlpdeskCoreFilemanagementController.php b/src/Controller/Filemanagement/AlpdeskCoreFilemanagementController.php index f4f046e..feb0db0 100644 --- a/src/Controller/Filemanagement/AlpdeskCoreFilemanagementController.php +++ b/src/Controller/Filemanagement/AlpdeskCoreFilemanagementController.php @@ -125,7 +125,7 @@ public function download(Request $request, UserInterface $user): BinaryFileRespo $this->framework->initialize(); - $downloadData = (array)\json_decode($request->getContent(), true); + $downloadData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); $file = (new AlpdeskCoreFilemanagement($this->rootDir, $this->eventService))->download($user, $downloadData); $this->logger->info('Download successfully', __METHOD__); @@ -155,7 +155,7 @@ public function finder(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); - $finderData = (array)\json_decode($request->getContent(), true); + $finderData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); $response = (new AlpdeskCoreFilemanagement($this->rootDir, $this->eventService))->finder($user, $finderData); $this->logger->info('Finder successfully', __METHOD__); From 953da81edcf31da69fe0d58765cf6916fbd98385 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 11:55:55 +0100 Subject: [PATCH 10/27] code cleanUp --- src/Controller/Plugin/AlpdeskCorePluginController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controller/Plugin/AlpdeskCorePluginController.php b/src/Controller/Plugin/AlpdeskCorePluginController.php index 68acd3e..cb83157 100644 --- a/src/Controller/Plugin/AlpdeskCorePluginController.php +++ b/src/Controller/Plugin/AlpdeskCorePluginController.php @@ -32,7 +32,6 @@ public function __construct( ) { $this->framework = $framework; - $this->eventService = $eventService; $this->logger = $logger; $this->rootDir = $rootDir; @@ -84,9 +83,9 @@ public function call(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); - $plugindata = (array)\json_decode($request->getContent(), true); + $pluginData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); - $response = (new AlpdeskCorePlugin($this->rootDir))->call($user, $plugindata); + $response = (new AlpdeskCorePlugin($this->rootDir))->call($user, $pluginData); $event = new AlpdeskCorePlugincallEvent($response); $this->eventService->getDispatcher()->dispatch($event, AlpdeskCorePlugincallEvent::NAME); @@ -101,6 +100,7 @@ public function call(Request $request, UserInterface $user): JsonResponse return $this->outputError($exception->getMessage(), $exception->getCode(), AlpdeskCoreConstants::$STATUSCODE_COMMONERROR); } + } } From 316a7607b70e7c2a99ef57db9c3c6b73bb11f7ff Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:03:33 +0100 Subject: [PATCH 11/27] code cleanUp --- src/Database/AlpdeskcoreMigration.php | 2 +- .../AlpdeskcoreDatabasemanagerWidget.php | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Database/AlpdeskcoreMigration.php b/src/Database/AlpdeskcoreMigration.php index 64f21cf..89de058 100644 --- a/src/Database/AlpdeskcoreMigration.php +++ b/src/Database/AlpdeskcoreMigration.php @@ -40,7 +40,7 @@ public function executeMigrations(array $commands): void public function showMigrations(): array { $schemaManager = $this->connection->createSchemaManager(); - $fromSchema = $schemaManager->createSchema(); + $fromSchema = $schemaManager->introspectSchema(); return (new Comparator())->compareSchemas($fromSchema, $this->parseSql())->toSql($this->connection->getDatabasePlatform()); diff --git a/src/Widget/AlpdeskcoreDatabasemanagerWidget.php b/src/Widget/AlpdeskcoreDatabasemanagerWidget.php index 4029a62..d5b7d62 100644 --- a/src/Widget/AlpdeskcoreDatabasemanagerWidget.php +++ b/src/Widget/AlpdeskcoreDatabasemanagerWidget.php @@ -35,10 +35,14 @@ public function generate(): string $username = $this->activeRecord->username; $password = $this->activeRecord->password; $database = $this->activeRecord->database; - if ($host !== '' && $username !== '' && $password !== '' && $database !== '') { + + if ($host !== '' && $username !== '' && $password !== '' && $database !== '' && $port > 0) { + $outputValue = $GLOBALS['TL_LANG']['tl_alpdeskcore_databasemanager']['valid_parameters'] . '
'; $connection = AlpdeskcoreDatabasemanagerModel::connectionById($id); + try { + if ($connection !== null) { $migrations = $this->checkMigrations($connection, $this->activeRecord->databasemodel); @@ -50,34 +54,51 @@ public function generate(): string AlpdeskcoreDatabasemanagerModel::destroy($id); $outputValue .= $GLOBALS['TL_LANG']['tl_alpdeskcore_databasemanager']['valid_connection'] . '
'; $outputValue .= '
'; + foreach ($structure as $key => $value) { + $outputValue .= '
'; $outputValue .= '' . $key . ''; if (is_array($value) && count($value) > 0) { $outputValue .= '
'; + foreach ($value as $cKey => $cValue) { + $outputValue .= ''; $outputValue .= '' . $cKey . '
'; $outputValue .= $cValue; $outputValue .= '

'; + } + $outputValue .= '
'; } + $outputValue .= '
'; } } else { $outputValue .= $GLOBALS['TL_LANG']['tl_alpdeskcore_databasemanager']['invalid_connection'] . '
'; } + } catch (\Exception $ex) { $outputValue .= $ex->getMessage() . '
'; } + } else { $outputValue .= $GLOBALS['TL_LANG']['tl_alpdeskcore_databasemanager']['invalid_parameters'] . '
'; } + } + return $migrationOutput . '
' . $outputValue . '
'; + } + /** + * @param Connection $connection + * @param mixed $modelUuid + * @return string + */ private function checkMigrations(Connection $connection, mixed $modelUuid): string { $migrations = ''; @@ -92,7 +113,7 @@ private function checkMigrations(Connection $connection, mixed $modelUuid): stri $jsonFile = new File($jsonModelFile->path); if ($jsonFile->exists()) { - $jsonModel = \json_decode($jsonFile->getContent(), true); + $jsonModel = \json_decode($jsonFile->getContent(), true, 512, JSON_THROW_ON_ERROR); if (\count($jsonModel) > 0) { @@ -121,14 +142,21 @@ private function checkMigrations(Connection $connection, mixed $modelUuid): stri } else { $migrations .= '

' . $GLOBALS['TL_LANG']['tl_alpdeskcore_databasemanager']['nomigrations'] . '

'; } + } + } + } + } + } catch (\Exception $ex) { $migrations = $ex->getMessage(); } return $migrations; + } + } From b8a929c5023adb2a9c312e311f5445e254633dbc Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:20:05 +0100 Subject: [PATCH 12/27] code cleanUp --- src/Database/AlpdeskcoreMigration.php | 124 ++++++++++++++++---------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/src/Database/AlpdeskcoreMigration.php b/src/Database/AlpdeskcoreMigration.php index 89de058..ccd71f5 100644 --- a/src/Database/AlpdeskcoreMigration.php +++ b/src/Database/AlpdeskcoreMigration.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; @@ -24,7 +25,7 @@ public function __construct(Connection $connection, array $model) /** * @param array $commands - * @throws \Doctrine\DBAL\Exception + * @throws \Exception */ public function executeMigrations(array $commands): void { @@ -42,7 +43,13 @@ public function showMigrations(): array $schemaManager = $this->connection->createSchemaManager(); $fromSchema = $schemaManager->introspectSchema(); - return (new Comparator())->compareSchemas($fromSchema, $this->parseSql())->toSql($this->connection->getDatabasePlatform()); + $databasePlatForm = $this->connection->getDatabasePlatform(); + + if (!$databasePlatForm instanceof AbstractPlatform) { + throw new \Exception('invalid DatabasePlatform'); + } + + return $databasePlatForm->getAlterSchemaSQL((new Comparator())->compareSchemas($fromSchema, $this->parseSql())); } @@ -79,83 +86,93 @@ private function parseSql(): Schema $table = $schema->createTable($currentTable['table']); if (\array_key_exists('fields', $currentTable)) { + foreach ($currentTable['fields'] as $field => $fieldattributes) { if (\is_array($fieldattributes)) { $this->parseField($table, $field, $fieldattributes); } } + } - if (\array_key_exists('primary', $currentTable)) { - if (\is_array($currentTable['primary'])) { - $table->setPrimaryKey($currentTable['primary']); - } + if (\array_key_exists('primary', $currentTable) && \is_array($currentTable['primary'])) { + $table->setPrimaryKey($currentTable['primary']); } - if (\array_key_exists('index', $currentTable)) { - if (\is_array($currentTable['index'])) { - foreach ($currentTable['index'] as $indexname => $indexfields) { + if (\array_key_exists('index', $currentTable) && \is_array($currentTable['index'])) { - if (\is_array($indexfields)) { - $table->addIndex($indexfields, $indexname); - } + foreach ($currentTable['index'] as $indexname => $indexfields) { + + if (\is_array($indexfields)) { + $table->addIndex($indexfields, $indexname); } + } + } - if (\array_key_exists('foreignKeys', $currentTable)) { - if (\is_array($currentTable['foreignKeys'])) { + if (\array_key_exists('foreignKeys', $currentTable) && \is_array($currentTable['foreignKeys'])) { - foreach ($currentTable['foreignKeys'] as $foreignTable => $columnMatching) { + foreach ($currentTable['foreignKeys'] as $foreignTable => $columnMatching) { - if (\is_array($columnMatching) && \count($columnMatching) > 0) { + if (\is_array($columnMatching) && \count($columnMatching) > 0) { - // avalible RESTRICT, CASCADE, NO ACTION - $options = [ - 'onDelete' => 'RESTRICT', - 'onUpdate' => 'RESTRICT' - ]; + // avalible RESTRICT, CASCADE, NO ACTION + $options = [ + 'onDelete' => 'RESTRICT', + 'onUpdate' => 'RESTRICT' + ]; - if (\array_key_exists('onDelete', $columnMatching)) { - $options['onDelete'] = $columnMatching['onDelete']; - } + if (\array_key_exists('onDelete', $columnMatching)) { + $options['onDelete'] = $columnMatching['onDelete']; + } - if (\array_key_exists('onUpdate', $columnMatching)) { - $options['onUpdate'] = $columnMatching['onUpdate']; - } + if (\array_key_exists('onUpdate', $columnMatching)) { + $options['onUpdate'] = $columnMatching['onUpdate']; + } - if (\array_key_exists('constraint', $columnMatching) && \is_array($columnMatching['constraint']) && \count($columnMatching['constraint']) > 0) { + if ( + \array_key_exists('constraint', $columnMatching) && + \is_array($columnMatching['constraint']) && \count($columnMatching['constraint']) > 0 + ) { - // Only one per Table // Maybe @TODO - foreach ($columnMatching['constraint'] as $localColumn => $foreignColumn) { + // Only one per Table // Maybe @TODO + $cCounter = 0; + foreach ($columnMatching['constraint'] as $localColumn => $foreignColumn) { - $table->addForeignKeyConstraint($foreignTable, [$localColumn], [$foreignColumn], $options); - break; + $table->addForeignKeyConstraint($foreignTable, [$localColumn], [$foreignColumn], $options); + $cCounter++; + if ($cCounter > 0) { + break; } } } + } + } + } - if (\array_key_exists('unique', $currentTable)) { - if (\is_array($currentTable['unique'])) { + if (\array_key_exists('unique', $currentTable) && \is_array($currentTable['unique'])) { - $uniqueValueArray = $currentTable['unique']; - foreach ($uniqueValueArray as $uValue) { + $uniqueValueArray = $currentTable['unique']; + foreach ($uniqueValueArray as $uValue) { - if (\is_array($uValue)) { - $table->addUniqueIndex($uValue); - } + if (\is_array($uValue)) { + $table->addUniqueIndex($uValue); } } + } + } + } return $schema; @@ -170,7 +187,7 @@ private function parseSql(): Schema * @param Table $table * @param string $field * @param array $fieldattributes - * @throws \Doctrine\DBAL\Exception + * @throws \Exception */ private function parseField(Table $table, string $field, array $fieldattributes): void { @@ -187,30 +204,36 @@ private function parseField(Table $table, string $field, array $fieldattributes) $precision = null; $unsigned = false; - if (\array_key_exists('unsigned', $fieldattributes)) { - if ($fieldattributes['unsigned'] === true && \in_array(strtolower($fieldattributes['type']), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'))) { - $unsigned = true; - } + if ( + \array_key_exists('unsigned', $fieldattributes) && + $fieldattributes['unsigned'] === true && + \in_array(strtolower($fieldattributes['type']), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint')) + ) { + $unsigned = true; } $autoincrement = false; - if (\array_key_exists('autoincrement', $fieldattributes)) { - if ($fieldattributes['autoincrement'] === true) { - $autoincrement = true; - } + if (\array_key_exists('autoincrement', $fieldattributes) && $fieldattributes['autoincrement'] === true) { + $autoincrement = true; } $default = null; if (\array_key_exists('default', $fieldattributes)) { + $default = $fieldattributes['default']; if ($autoincrement === true || $default === 'NULL') { $default = null; } + } $this->setLengthAndPrecisionByType($fieldattributes['type'], $dbType, $length, $scale, $precision, $fixed); - $type = $this->connection->getDatabasePlatform()->getDoctrineTypeMapping($fieldattributes['type']); + $type = $this->connection->getDatabasePlatform()?->getDoctrineTypeMapping($fieldattributes['type']); + if ($type === null) { + throw new \Exception('invalid type for ' . $fieldattributes['type']); + } + if (0 === $length) { $length = null; } @@ -235,8 +258,10 @@ private function parseField(Table $table, string $field, array $fieldattributes) ]; if (null !== $scale && null !== $precision) { + $options['scale'] = $scale; $options['precision'] = $precision; + } $platformOptions = []; @@ -257,6 +282,7 @@ private function parseField(Table $table, string $field, array $fieldattributes) } $table->addColumn($field, $type, $options); + } private function setLengthAndPrecisionByType(string $type, string $dbType, ?int &$length, ?int &$scale, ?int &$precision, bool &$fixed): void From 476a80471625b6b889edaf0546e25eb6cb2cb8ea Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:25:08 +0100 Subject: [PATCH 13/27] code cleanUp --- src/Events/Listener/AlpdeskCoreBackendMenuListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Events/Listener/AlpdeskCoreBackendMenuListener.php b/src/Events/Listener/AlpdeskCoreBackendMenuListener.php index 7602cdf..d1bc539 100644 --- a/src/Events/Listener/AlpdeskCoreBackendMenuListener.php +++ b/src/Events/Listener/AlpdeskCoreBackendMenuListener.php @@ -5,8 +5,8 @@ namespace Alpdesk\AlpdeskCore\Events\Listener; use Alpdesk\AlpdeskCore\Utils\Utils; -use Symfony\Component\Security\Core\Security; use Contao\CoreBundle\Event\MenuEvent; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\RouterInterface; use Contao\BackendUser; From 7de0b1f626af9fa2a06cc94531c4120a8649454c Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:28:59 +0100 Subject: [PATCH 14/27] code cleanUp --- src/Events/Callbacks/DcaCallbacks.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Events/Callbacks/DcaCallbacks.php b/src/Events/Callbacks/DcaCallbacks.php index 847a238..f53bd08 100644 --- a/src/Events/Callbacks/DcaCallbacks.php +++ b/src/Events/Callbacks/DcaCallbacks.php @@ -170,7 +170,7 @@ public function getCrudTables(?DataContainer $dc): array try { $schemaManager = $this->connection->createSchemaManager(); - $tables = $schemaManager->createSchema()->getTables(); + $tables = $schemaManager->introspectSchema()->getTables(); $preparedTables = []; foreach ($tables as $table) { @@ -183,8 +183,7 @@ public function getCrudTables(?DataContainer $dc): array return $preparedTables; - - } catch (\Throwable $tr) { + } catch (\Throwable) { return []; } From 4b53314786b97eb1de846d94b06736ec0354fa21 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:31:30 +0100 Subject: [PATCH 15/27] code cleanUp --- src/Jwt/JwtToken.php | 6 +++--- src/Logging/AlpdeskcoreLogger.php | 32 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Jwt/JwtToken.php b/src/Jwt/JwtToken.php index 637a5e6..1e1c920 100644 --- a/src/Jwt/JwtToken.php +++ b/src/Jwt/JwtToken.php @@ -93,14 +93,14 @@ public static function getClaim(string $token, string $name): mixed try { $tokenObject = self::parse($token); - + if (!$tokenObject instanceof UnencryptedToken) { throw new \Exception('invalid token instance'); } $value = $tokenObject->claims()->get($name); - } catch (\Exception $ex) { + } catch (\Exception) { $value = null; } @@ -136,7 +136,7 @@ public static function validateAndVerify(string $token, string $jti): bool $value = !$tokenObject->isExpired($now); } - } catch (\Exception $ex) { + } catch (\Exception) { $value = false; } diff --git a/src/Logging/AlpdeskcoreLogger.php b/src/Logging/AlpdeskcoreLogger.php index 667de73..6342dfa 100644 --- a/src/Logging/AlpdeskcoreLogger.php +++ b/src/Logging/AlpdeskcoreLogger.php @@ -3,7 +3,6 @@ namespace Alpdesk\AlpdeskCore\Logging; use Contao\Config; -use DateTimeZone; use Monolog\Formatter\LineFormatter; use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; @@ -26,6 +25,10 @@ public function __construct(ContaoFramework $framework, string $rootDir, string $this->environment = $environment; } + /** + * @return void + * @throws \Exception + */ private function initialize(): void { if ($this->initialized === false) { @@ -37,7 +40,7 @@ private function initialize(): void $this->logger = new Logger('alpdeskcorelogger'); $timeZone = Config::get('timeZone'); - $this->logger->setTimezone(new DateTimeZone($timeZone)); + $this->logger->setTimezone(new \DateTimeZone($timeZone)); $handler = new RotatingFileHandler($this->rootDir . '/var/logs/' . $this->environment . '-alpdesk.log', 0, ($this->environment === 'dev' ? Logger::DEBUG : Logger::WARNING)); @@ -54,27 +57,52 @@ private function initialize(): void } + /** + * @param mixed $strText + * @param mixed $strFunction + * @return void + * @throws \Exception + */ public function info(mixed $strText, mixed $strFunction): void { $this->initialize(); $this->logger->info($strFunction . ' => ' . $strText); } + /** + * @param mixed $strText + * @param mixed $strFunction + * @return void + * @throws \Exception + */ public function debug(mixed $strText, mixed $strFunction): void { $this->initialize(); $this->logger->debug($strFunction . ' => ' . $strText); } + /** + * @param mixed $strText + * @param mixed $strFunction + * @return void + * @throws \Exception + */ public function warning(mixed $strText, mixed $strFunction): void { $this->initialize(); $this->logger->warning($strFunction . ' => ' . $strText); } + /** + * @param mixed $strText + * @param mixed $strFunction + * @return void + * @throws \Exception + */ public function error(mixed $strText, mixed $strFunction): void { $this->initialize(); $this->logger->error($strFunction . ' => ' . $strText); } + } From d9302c696d0e967857f1f0ef96399c5d3a17611d Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:38:35 +0100 Subject: [PATCH 16/27] code cleanUp --- .../AlpdeskcoreDatabasemanagerModel.php | 54 ++++++++----------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/src/Model/Database/AlpdeskcoreDatabasemanagerModel.php b/src/Model/Database/AlpdeskcoreDatabasemanagerModel.php index 113b205..52f9bcd 100644 --- a/src/Model/Database/AlpdeskcoreDatabasemanagerModel.php +++ b/src/Model/Database/AlpdeskcoreDatabasemanagerModel.php @@ -18,16 +18,12 @@ class AlpdeskcoreDatabasemanagerModel extends Model private static function create(int $id, string $host, int $port, string $username, string $password, string $database): ?Connection { - if (\count(self::$connectionsTable) > 0 && \array_key_exists($id, self::$connectionsTable)) { - - if (self::$connectionsTable[$id] instanceof Connection) { - - if (self::$connectionsTable[$id] !== null && self::$connectionsTable[$id]->isConnected()) { - return self::$connectionsTable[$id]; - } - - } - + if ( + \array_key_exists($id, self::$connectionsTable) && + self::$connectionsTable[$id] instanceof Connection && + self::$connectionsTable[$id]->isConnected() + ) { + return self::$connectionsTable[$id]; } $params = [ @@ -50,7 +46,7 @@ private static function create(int $id, string $host, int $port, string $usernam return self::$connectionsTable[$id]; - } catch (\Exception $e) { + } catch (\Throwable) { } @@ -59,18 +55,13 @@ private static function create(int $id, string $host, int $port, string $usernam public static function destroy(int $id): void { - if (\array_key_exists($id, self::$connectionsTable)) { - - if (self::$connectionsTable[$id] instanceof Connection) { - - if (self::$connectionsTable[$id] !== null) { - - self::$connectionsTable[$id]->close(); - self::$connectionsTable[$id] = null; + if ( + \array_key_exists($id, self::$connectionsTable) && + self::$connectionsTable[$id] instanceof Connection + ) { - } - - } + self::$connectionsTable[$id]->close(); + self::$connectionsTable[$id] = null; } } @@ -93,7 +84,7 @@ public static function listTables(int $id, ?string $name): array try { - $tables = self::$connectionsTable[$id]->createSchemaManager()->createSchema()->getTables(); + $tables = self::$connectionsTable[$id]->createSchemaManager()->introspectSchema()->getTables(); $structure = array(); foreach ($tables as $table) { @@ -222,16 +213,12 @@ public static function listTables(int $id, ?string $name): array */ public static function connectionById(int $id): ?Connection { - if (\count(self::$connectionsTable) > 0 && \array_key_exists($id, self::$connectionsTable)) { - - if (self::$connectionsTable[$id] instanceof Connection) { - - if (self::$connectionsTable[$id] !== null && self::$connectionsTable[$id]->isConnected()) { - return self::$connectionsTable[$id]; - } - - } - + if ( + \array_key_exists($id, self::$connectionsTable) && + self::$connectionsTable[$id] instanceof Connection && + self::$connectionsTable[$id]->isConnected() + ) { + return self::$connectionsTable[$id]; } $result = self::findByPk($id); @@ -247,4 +234,5 @@ public static function connectionById(int $id): ?Connection return null; } + } From 239f37187d266a686e165b18b0c5998090cf939b Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:45:30 +0100 Subject: [PATCH 17/27] code cleanUp --- src/Logging/AlpdeskcoreLogger.php | 8 -------- src/Security/AlpdeskcoreUserProvider.php | 9 +++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Logging/AlpdeskcoreLogger.php b/src/Logging/AlpdeskcoreLogger.php index 6342dfa..c8443cc 100644 --- a/src/Logging/AlpdeskcoreLogger.php +++ b/src/Logging/AlpdeskcoreLogger.php @@ -25,10 +25,6 @@ public function __construct(ContaoFramework $framework, string $rootDir, string $this->environment = $environment; } - /** - * @return void - * @throws \Exception - */ private function initialize(): void { if ($this->initialized === false) { @@ -61,7 +57,6 @@ private function initialize(): void * @param mixed $strText * @param mixed $strFunction * @return void - * @throws \Exception */ public function info(mixed $strText, mixed $strFunction): void { @@ -73,7 +68,6 @@ public function info(mixed $strText, mixed $strFunction): void * @param mixed $strText * @param mixed $strFunction * @return void - * @throws \Exception */ public function debug(mixed $strText, mixed $strFunction): void { @@ -85,7 +79,6 @@ public function debug(mixed $strText, mixed $strFunction): void * @param mixed $strText * @param mixed $strFunction * @return void - * @throws \Exception */ public function warning(mixed $strText, mixed $strFunction): void { @@ -97,7 +90,6 @@ public function warning(mixed $strText, mixed $strFunction): void * @param mixed $strText * @param mixed $strFunction * @return void - * @throws \Exception */ public function error(mixed $strText, mixed $strFunction): void { diff --git a/src/Security/AlpdeskcoreUserProvider.php b/src/Security/AlpdeskcoreUserProvider.php index d22ce13..600e8e5 100644 --- a/src/Security/AlpdeskcoreUserProvider.php +++ b/src/Security/AlpdeskcoreUserProvider.php @@ -83,10 +83,11 @@ public function loadUserByUsername(string $username): AlpdeskcoreUser $alpdeskUser = AlpdeskcoreMandantModel::findByUsername($username); $sessionModel = AlpdeskcoreSessionsModel::findByUsername($alpdeskUser->getUsername()); - if ($sessionModel !== null) { - if (self::validateAndVerifyToken($sessionModel->token, $alpdeskUser->getUsername())) { - $alpdeskUser->setToken($sessionModel->token); - } + if ( + $sessionModel !== null && + self::validateAndVerifyToken($sessionModel->token, $alpdeskUser->getUsername()) + ) { + $alpdeskUser->setToken($sessionModel->token); } return $alpdeskUser; From 076a0340d8ec56abe3c7ee9ed626bbeea1c51276 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:46:44 +0100 Subject: [PATCH 18/27] code cleanUp --- src/Utils/Utils.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index 70d75cc..be5c6c0 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -25,16 +25,17 @@ public static function mergeUserGroupPermissions(UserInterface $backendUser): vo $time = Date::floorToMinute(); foreach ((array)$backendUser->groups as $id) { + $objGroup = Database::getInstance()->prepare("SELECT alpdeskcorelogs_enabled FROM tl_user_group WHERE id=? AND disable!='1' AND (start='' OR start<='$time') AND (stop='' OR stop>'$time')")->limit(1)->execute($id); - if ($objGroup->numRows > 0) { - if ((int)$backendUser->alpdeskcorelogs_enabled === 0) { - $backendUser->alpdeskcorelogs_enabled = $objGroup->alpdeskcorelogs_enabled; - } + if ($objGroup->numRows > 0 && (int)$backendUser->alpdeskcorelogs_enabled === 0) { + $backendUser->alpdeskcorelogs_enabled = $objGroup->alpdeskcorelogs_enabled; } } + } } + } /** @@ -54,7 +55,7 @@ public static function replaceInsertTags($strBuffer, bool $blnCache = true): str return $parser->replaceInline((string)$strBuffer); - } catch (\Exception $ex) { + } catch (\Exception) { return (string)$strBuffer; } From d81926c9a44ae30aeeb0e47ae70c83db9d2326cd Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:55:20 +0100 Subject: [PATCH 19/27] code cleanUp --- src/Library/Auth/AlpdeskCoreAuthToken.php | 2 +- src/Library/Backend/AlpdeskCoreDcaUtils.php | 6 +++--- src/Library/Database/CrudModel.php | 5 ++--- src/Library/Mandant/AlpdeskCoreMandant.php | 24 ++++++++++----------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Library/Auth/AlpdeskCoreAuthToken.php b/src/Library/Auth/AlpdeskCoreAuthToken.php index 91d1aad..100b85c 100644 --- a/src/Library/Auth/AlpdeskCoreAuthToken.php +++ b/src/Library/Auth/AlpdeskCoreAuthToken.php @@ -180,7 +180,7 @@ public function invalidToken(AlpdeskcoreUser $user): AlpdeskCoreAuthResponse try { $this->invalidTokenData($response->getUsername(), $response->getAlpdesk_token()); $response->setInvalid(true); - } catch (AlpdeskCoreAuthException $ex) { + } catch (AlpdeskCoreAuthException) { $response->setInvalid(false); } diff --git a/src/Library/Backend/AlpdeskCoreDcaUtils.php b/src/Library/Backend/AlpdeskCoreDcaUtils.php index 0b41037..b838b49 100644 --- a/src/Library/Backend/AlpdeskCoreDcaUtils.php +++ b/src/Library/Backend/AlpdeskCoreDcaUtils.php @@ -28,7 +28,7 @@ public function showSessionValid($row, $label, $dc, $args): array { try { $validateAndVerify = JwtToken::validateAndVerify($args[1], AlpdeskcoreUserProvider::createJti($args[0])); - } catch (\Exception $ex) { + } catch (\Exception) { $validateAndVerify = false; } @@ -110,12 +110,12 @@ public function pdfElementsloadCallback(DataContainer $dc): void try { (new AlpdeskCorePDFCreator())->generateById((int)Input::get('pdfid'), "files/tmp", time() . ".pdf"); - } catch (\Exception $ex) { - + } catch (\Exception) { } Controller::redirect('contao?do=' . Input::get('do') . '&table=' . Input::get('table') . '&id=' . Input::get('id') . '&rt=' . Input::get('rt')); } + } /** diff --git a/src/Library/Database/CrudModel.php b/src/Library/Database/CrudModel.php index 54c6e89..0b8caf8 100644 --- a/src/Library/Database/CrudModel.php +++ b/src/Library/Database/CrudModel.php @@ -51,7 +51,7 @@ public function getSchemaManager(): AbstractSchemaManager public function getSchema(): Schema { if ($this->schema === null) { - $this->schema = $this->getSchemaManager()->createSchema(); + $this->schema = $this->getSchemaManager()->introspectSchema(); } return $this->schema; @@ -151,8 +151,7 @@ private function getSQLErrorMessage(string $exMessage): string $message = \end($lastMessage); } - } catch (\Exception $ex) { - + } catch (\Exception) { } return \trim($message); diff --git a/src/Library/Mandant/AlpdeskCoreMandant.php b/src/Library/Mandant/AlpdeskCoreMandant.php index 5abb659..8e3ef11 100644 --- a/src/Library/Mandant/AlpdeskCoreMandant.php +++ b/src/Library/Mandant/AlpdeskCoreMandant.php @@ -48,17 +48,16 @@ private function getPlugins(int $mandantPid, array $invalidElements): array foreach ($plugins as $pluginElement) { $type = (string)$pluginElement->type; - if (!\in_array($type, $invalidElements, true)) { - - if (isset($pluginData[$type]) && isset($pluginInfo[$type])) { - - $data[] = array( - 'value' => $pluginElement->type, - 'label' => $pluginData[$type], - 'customTemplate' => ($pluginInfo[$type]['customTemplate'] ?? false) - ); - - } + if ( + isset($pluginData[$type], $pluginInfo[$type]) && + !\in_array($type, $invalidElements, true) + ) { + + $data[] = array( + 'value' => $pluginElement->type, + 'label' => $pluginData[$type], + 'customTemplate' => ($pluginInfo[$type]['customTemplate'] ?? false) + ); } } @@ -83,8 +82,7 @@ private function getData(int $mandantPid): array $data = $mData->row(); - unset($data['id']); - unset($data['tstamp']); + unset($data['id'], $data['tstamp']); $returnData = array(); From ecaa26cff92b5c32b01326995706ca80cd713777 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 12:59:12 +0100 Subject: [PATCH 20/27] code cleanUp --- src/Library/PDF/AlpdeskCorePDFCreator.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Library/PDF/AlpdeskCorePDFCreator.php b/src/Library/PDF/AlpdeskCorePDFCreator.php index a0eaa9e..8700da5 100644 --- a/src/Library/PDF/AlpdeskCorePDFCreator.php +++ b/src/Library/PDF/AlpdeskCorePDFCreator.php @@ -52,7 +52,7 @@ class AlpdeskCorePDFCreator extends \TCPDF public function __construct() { - parent::__construct(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); + parent::__construct(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT); } public function setFootersesstingsarray(array $footersesstingsarray): void @@ -230,7 +230,11 @@ public function generate($text, $filename, $path, $settingsarray): string $l['a_meta_dir'] = 'ltr'; $l['a_meta_charset'] = Config::get('characterSet'); - $locale = System::getContainer()->get('request_stack')->getCurrentRequest()->getLocale(); + $locale = System::getContainer()->get('request_stack')->getCurrentRequest()?->getLocale(); + if ($locale === null) { + $locale = 'de'; + } + $l['a_meta_language'] = $locale; $l['w_page'] = 'page'; @@ -299,16 +303,16 @@ public function generate($text, $filename, $path, $settingsarray): string $pageCount = \count($pageSplit); if ($pageCount > 1) { - $this->writeHTML($pageSplit[0], true, false, true, false); + $this->writeHTML($pageSplit[0], true, false, true); for ($i = 1; $i < $pageCount; $i++) { $this->AddPage(); - $this->writeHTML($pageSplit[$i], true, false, true, false); + $this->writeHTML($pageSplit[$i], true, false, true); } } else { - $this->writeHTML($html, true, false, true, false); + $this->writeHTML($html, true, false, true); } $this->lastPage(); @@ -329,12 +333,11 @@ public function generate($text, $filename, $path, $settingsarray): string $resultPath = $path . '/' . $filename; $finalResultFile = new File($resultPath); - if ($finalResultFile->exists()) { - if (Dbafs::shouldBeSynchronized($finalResultFile->path)) { - Dbafs::addResource($finalResultFile->path); - } + if ($finalResultFile->exists() && Dbafs::shouldBeSynchronized($finalResultFile->path)) { + Dbafs::addResource($finalResultFile->path); } return $resultPath; + } } From fe34e1871730ea2bf9c050404f67d70c1174337b Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 13:46:56 +0100 Subject: [PATCH 21/27] fix tests --- .idea/php-test-framework.xml | 1 + tests/Jwt/JwtTokenTest.php | 10 +++++----- tests/Library/Cryption/CryptionTest.php | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml index 1d85f19..7b6eaba 100644 --- a/.idea/php-test-framework.xml +++ b/.idea/php-test-framework.xml @@ -6,6 +6,7 @@ + diff --git a/tests/Jwt/JwtTokenTest.php b/tests/Jwt/JwtTokenTest.php index 51de731..ba58e1d 100644 --- a/tests/Jwt/JwtTokenTest.php +++ b/tests/Jwt/JwtTokenTest.php @@ -19,13 +19,13 @@ public function set(string $id, ?object $service): void } /** - * @param $id + * @param string $id * @param int $invalidBehavior - * @return object|void|null + * @return object|null */ - public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) + public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): ?object { - // TODO: Implement get() method. + return null; } /** @@ -95,7 +95,7 @@ protected function assertPreConditions(): void $this->assertNotEmpty(System::getContainer()->getParameter('kernel.secret')); } - private function nullParameter(\DateTimeImmutable $d): void + private function nullParameter(?\DateTimeImmutable $d): void { } diff --git a/tests/Library/Cryption/CryptionTest.php b/tests/Library/Cryption/CryptionTest.php index fe5cc32..d5cdafa 100644 --- a/tests/Library/Cryption/CryptionTest.php +++ b/tests/Library/Cryption/CryptionTest.php @@ -22,13 +22,13 @@ public function set(string $id, ?object $service): void } /** - * @param $id + * @param string $id * @param int $invalidBehavior - * @return object|void|null + * @return object|null */ - public function get($id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) + public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): ?object { - // TODO: Implement get() method. + return null; } /** From 717b8cd6eaaa501d81d40b1f169df91075d52fda Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 13:51:02 +0100 Subject: [PATCH 22/27] fix tests --- .github/workflows/ci_pr.yaml | 2 +- tests/Jwt/JwtTokenTest.php | 4 ++-- tests/Library/Cryption/CryptionTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_pr.yaml b/.github/workflows/ci_pr.yaml index a35737a..33e86c6 100644 --- a/.github/workflows/ci_pr.yaml +++ b/.github/workflows/ci_pr.yaml @@ -23,4 +23,4 @@ jobs: run: composer install --no-interaction --no-progress - name: Run the unit tests - run: vendor/bin/phpunit --colors=always \ No newline at end of file + run: vendor/bin/phpunit --no-configuration ./tests \ No newline at end of file diff --git a/tests/Jwt/JwtTokenTest.php b/tests/Jwt/JwtTokenTest.php index ba58e1d..e791392 100644 --- a/tests/Jwt/JwtTokenTest.php +++ b/tests/Jwt/JwtTokenTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Alpdesk\AlpdeskCoreTest\Jwt; +namespace Jwt; use Alpdesk\AlpdeskCore\Jwt\JwtToken; use Contao\System; @@ -50,7 +50,7 @@ public function initialized(string $id): bool * @param string $name * @return array|bool|float|int|mixed|string|null */ - public function getParameter(string $name) + public function getParameter(string $name): mixed { return $this->params[$name]; } diff --git a/tests/Library/Cryption/CryptionTest.php b/tests/Library/Cryption/CryptionTest.php index d5cdafa..b8f584c 100644 --- a/tests/Library/Cryption/CryptionTest.php +++ b/tests/Library/Cryption/CryptionTest.php @@ -53,7 +53,7 @@ public function initialized(string $id): bool * @param string $name * @return array|bool|float|int|mixed|string|null */ - public function getParameter(string $name) + public function getParameter(string $name): mixed { return $this->params[$name]; } From 50d5ee418d3446c30daa4198180d9059ce20484b Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 14:17:00 +0100 Subject: [PATCH 23/27] bugfix memberData --- .../Auth/AlpdeskCoreAuthController.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/Auth/AlpdeskCoreAuthController.php b/src/Controller/Auth/AlpdeskCoreAuthController.php index c86a794..e8b8332 100644 --- a/src/Controller/Auth/AlpdeskCoreAuthController.php +++ b/src/Controller/Auth/AlpdeskCoreAuthController.php @@ -201,7 +201,23 @@ public function member(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); - $memberData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); + $memberData = []; + + try { + + // Request could be empty + $memberRequest = $request->getContent(); + if (\is_string($memberRequest) && $memberRequest !== '') { + + $memberDataT = \json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); + if (\is_array($memberDataT)) { + $memberData = $memberDataT; + } + + } + + } catch (\Exception) { + } if (\array_key_exists('mandantid', $memberData) && $user->getIsAdmin() === true) { @@ -255,8 +271,10 @@ public function member(Request $request, UserInterface $user): JsonResponse return (new JsonResponse($event->getResultData()->getData(), AlpdeskCoreConstants::$STATUSCODE_OK)); } catch (\Exception $exception) { + $this->logger->error($exception->getMessage(), __METHOD__); return $this->outputError($exception->getMessage(), $exception->getCode(), AlpdeskCoreConstants::$STATUSCODE_COMMONERROR); + } } From a5676b5c0078fd15b5fbafe5c6e1461a2a39b035 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 14:20:33 +0100 Subject: [PATCH 24/27] bugfix --- src/Controller/Plugin/AlpdeskCorePluginController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/Plugin/AlpdeskCorePluginController.php b/src/Controller/Plugin/AlpdeskCorePluginController.php index cb83157..062cc0b 100644 --- a/src/Controller/Plugin/AlpdeskCorePluginController.php +++ b/src/Controller/Plugin/AlpdeskCorePluginController.php @@ -83,6 +83,7 @@ public function call(Request $request, UserInterface $user): JsonResponse $this->framework->initialize(); + // $request->getContent() must always be a valid JSON $pluginData = (array)\json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); $response = (new AlpdeskCorePlugin($this->rootDir))->call($user, $pluginData); @@ -94,7 +95,7 @@ public function call(Request $request, UserInterface $user): JsonResponse return $this->output($event->getResultData(), AlpdeskCoreConstants::$STATUSCODE_OK); - } catch (\Exception $exception) { + } catch (\Throwable $exception) { $this->logger->error($exception->getMessage(), __METHOD__); return $this->outputError($exception->getMessage(), $exception->getCode(), AlpdeskCoreConstants::$STATUSCODE_COMMONERROR); From f1552e78383ddf8c024d6ad45c1a0d1d3dc38e91 Mon Sep 17 00:00:00 2001 From: xprojects-de Date: Thu, 14 Dec 2023 14:25:59 +0100 Subject: [PATCH 25/27] bugfix --- .idea/inspectionProfiles/Project_Default.xml | 1 + src/Controller/Auth/AlpdeskCoreAuthController.php | 2 ++ .../Filemanagement/AlpdeskCoreFilemanagementController.php | 2 ++ src/Controller/Plugin/AlpdeskCorePluginController.php | 2 +- src/Widget/AlpdeskcoreDatabasemanagerWidget.php | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index ba9dc57..9dacadb 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -68,6 +68,7 @@