From 5f1d7bc78b12de41cedf7fd8f8499d6915496af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20Ko=CC=88hnlein?= Date: Thu, 22 Feb 2024 09:20:31 +0100 Subject: [PATCH 1/7] =?UTF-8?q?[TASK]=C2=A0Add=20compatibility=20with=20sy?= =?UTF-8?q?mfony/console=20^7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/Command/ExportTableCommand.php | 2 +- Classes/Command/ImportTableCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/Command/ExportTableCommand.php b/Classes/Command/ExportTableCommand.php index d6afc34..1fe310c 100644 --- a/Classes/Command/ExportTableCommand.php +++ b/Classes/Command/ExportTableCommand.php @@ -188,7 +188,7 @@ protected function configure(): void * @param OutputInterface $output * @return int|void|null */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); // Output information about the command diff --git a/Classes/Command/ImportTableCommand.php b/Classes/Command/ImportTableCommand.php index 6dd8553..0fc1f11 100644 --- a/Classes/Command/ImportTableCommand.php +++ b/Classes/Command/ImportTableCommand.php @@ -76,7 +76,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v * @param OutputInterface $output * @return int|void|null */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $this->informationalHeader($io, $input); From a6dc33b8d12c408d520406e95ee5ec8a5466fab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Tue, 12 Nov 2024 15:54:01 +0100 Subject: [PATCH 2/7] =?UTF-8?q?[TASK]=C2=A0Allow=20to=20be=20installed=20w?= =?UTF-8?q?ith=20TYPO3=2013=20and=20symfony/yaml=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0f836aa..5c3dc2d 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,8 @@ } ], "require": { - "typo3/cms-core": "^11 || ^12", - "symfony/yaml": "2.6 - 4.99 || ^5 || ^6" + "typo3/cms-core": "^11 || ^12 || ^13", + "symfony/yaml": "2.6 - 4.99 || ^5 || ^6 || ^7" }, "extra": { "typo3/cms": { From ec38aade301dcb0531dae61c43969eb004bd58c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Wed, 13 Nov 2024 10:55:18 +0100 Subject: [PATCH 3/7] Convert from ->loadRequireJsModule() to ->loadJavaScriptModule() --- .../Backend/ButtonBar/YamlExportButton.php | 3 +- Configuration/JavaScriptModules.php | 7 ++++ Resources/Public/JavaScript/Backend.js | 36 +++++++++---------- composer.json | 4 +-- 4 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 Configuration/JavaScriptModules.php diff --git a/Classes/Backend/ButtonBar/YamlExportButton.php b/Classes/Backend/ButtonBar/YamlExportButton.php index a3ca27f..6a3df69 100644 --- a/Classes/Backend/ButtonBar/YamlExportButton.php +++ b/Classes/Backend/ButtonBar/YamlExportButton.php @@ -71,8 +71,7 @@ public function __invoke(ModifyButtonBarEvent $event): void // Add button directly to array instead of using ->getButtonBar as this needs too much memory $buttons[$options['buttonBarPosition']][$options['index']][] = $button; } - // @todo: Load Javascript with native ES6 modules instead of RequireJs (which is deprecated) - $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/YamlConfiguration/Backend'); + $this->pageRenderer->loadJavaScriptModule('@supseven/yaml-configuration/Backend.js'); // Persist final buttons configuration $event->setButtons($buttons); diff --git a/Configuration/JavaScriptModules.php b/Configuration/JavaScriptModules.php new file mode 100644 index 0000000..bbdf417 --- /dev/null +++ b/Configuration/JavaScriptModules.php @@ -0,0 +1,7 @@ + [ + '@supseven/yaml-configuration/' => 'EXT:yaml_configuration/Resources/Public/JavaScript/', + ], +]; diff --git a/Resources/Public/JavaScript/Backend.js b/Resources/Public/JavaScript/Backend.js index a7f59af..e4429bf 100644 --- a/Resources/Public/JavaScript/Backend.js +++ b/Resources/Public/JavaScript/Backend.js @@ -1,3 +1,5 @@ +import Notification from "@typo3/backend/notification.js"; + (function() { var httpRequest; document.getElementsByClassName('t3js-yaml-export')[0].addEventListener('click', makeRequest); @@ -20,29 +22,27 @@ if (httpRequest.status === 200) { var _response = JSON.parse(httpRequest.response); - Notification(_response) + notify(_response) } else { console.log("error"); } } } - function Notification(response) { - require(['TYPO3/CMS/Backend/Notification'], function(Notification) { - switch (response.status) { - case 1: - Notification.warning(response.title, response.message); - break; - case 255: - Notification.notice(response.title, response.message); - break; - case 500: - Notification.error(response.title, response.message); - break; - default: - Notification.success(response.title, response.message); - break; - } - }); + function notify(response) { + switch (response.status) { + case 1: + Notification.warning(response.title, response.message); + break; + case 255: + Notification.notice(response.title, response.message); + break; + case 500: + Notification.error(response.title, response.message); + break; + default: + Notification.success(response.title, response.message); + break; + } } })(); diff --git a/composer.json b/composer.json index 5c3dc2d..f37fb4c 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,8 @@ } ], "require": { - "typo3/cms-core": "^11 || ^12 || ^13", - "symfony/yaml": "2.6 - 4.99 || ^5 || ^6 || ^7" + "typo3/cms-core": "^12 || ^13", + "symfony/yaml": "^5 || ^6 || ^7" }, "extra": { "typo3/cms": { From 0495bf31fad9a2236bf9a98232dddd07a16efc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Wed, 13 Nov 2024 10:55:41 +0100 Subject: [PATCH 4/7] Introduce alternative parameter check for TYPO3 13 --- Classes/Backend/ButtonBar/YamlExportButton.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Classes/Backend/ButtonBar/YamlExportButton.php b/Classes/Backend/ButtonBar/YamlExportButton.php index 6a3df69..fbf0133 100644 --- a/Classes/Backend/ButtonBar/YamlExportButton.php +++ b/Classes/Backend/ButtonBar/YamlExportButton.php @@ -13,6 +13,7 @@ use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; /** * Class YamlExportButton @@ -110,11 +111,19 @@ protected function isButtonEnabled(string $table): bool */ protected function isApplicableTable(string $table): bool { - if (!array_key_exists('table', $this->getRequest()->getQueryParams())) { - return false; + $typo3Version = VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version()); + if ($typo3Version < 13000000) { // old check befor TYPO3 v13 + if (!array_key_exists('table', $this->getRequest()->getQueryParams())) { + return false; + } + return ($this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/module/web/list') && + ($this->getRequest()->getQueryParams()['table'] === $table); } - return ($this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/module/web/list') && - ($this->getRequest()->getQueryParams()['table'] === $table); + + return ( + $this->getRequest()->getAttributes()['routing']->getRoute()->getPath() === '/record/edit' + && isset($this->getRequest()->getQueryParams()['edit'][$table]) + ); } private function getRequest(): ServerRequestInterface From 42e9780b72691fc3fa095b10f94ae471a0c8c5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Wed, 13 Nov 2024 10:55:56 +0100 Subject: [PATCH 5/7] Fix PHP type errors --- Classes/Command/ExportTableCommand.php | 4 ++-- Classes/Service/YamlExportService.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Command/ExportTableCommand.php b/Classes/Command/ExportTableCommand.php index 1fe310c..7ecf55c 100644 --- a/Classes/Command/ExportTableCommand.php +++ b/Classes/Command/ExportTableCommand.php @@ -91,8 +91,8 @@ class ExportTableCommand extends AbstractTableCommand protected function initialize(InputInterface $input, OutputInterface $output): void { parent::initialize($input, $output); - $this->setSkipColumns(GeneralUtility::trimExplode(',', $input->getOption('skip-columns'), true)); - $this->setExplodeColumns(GeneralUtility::trimExplode(',', $input->getOption('explode-columns'), true)); + $this->setSkipColumns(GeneralUtility::trimExplode(',', $input->getOption('skip-columns') ?? '', true)); + $this->setExplodeColumns(GeneralUtility::trimExplode(',', $input->getOption('explode-columns') ?? '', true)); if ($input->getOption('use-only-columns')) { $this->setUseOnlyColumns(GeneralUtility::trimExplode(',', $input->getOption('use-only-columns'), true)); } diff --git a/Classes/Service/YamlExportService.php b/Classes/Service/YamlExportService.php index 2dcc504..e10e8bd 100644 --- a/Classes/Service/YamlExportService.php +++ b/Classes/Service/YamlExportService.php @@ -64,7 +64,7 @@ public function export(ServerRequestInterface $request): ResponseInterface ]); } - $output = ''; + $output = []; $returnValue = 0; $pathAndFileName = ExtensionManagementUtility::extPath($this->config['extensionName']) . $this->config['path'] . $this->config['table'] . '.yaml'; From 250f564b2c1d56ce292e62386ff80d581aaa616a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Wed, 13 Nov 2024 11:00:39 +0100 Subject: [PATCH 6/7] Include JavaScript only if a button was created --- Classes/Backend/ButtonBar/YamlExportButton.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/Backend/ButtonBar/YamlExportButton.php b/Classes/Backend/ButtonBar/YamlExportButton.php index fbf0133..655041e 100644 --- a/Classes/Backend/ButtonBar/YamlExportButton.php +++ b/Classes/Backend/ButtonBar/YamlExportButton.php @@ -72,7 +72,10 @@ public function __invoke(ModifyButtonBarEvent $event): void // Add button directly to array instead of using ->getButtonBar as this needs too much memory $buttons[$options['buttonBarPosition']][$options['index']][] = $button; } - $this->pageRenderer->loadJavaScriptModule('@supseven/yaml-configuration/Backend.js'); + + if (isset($button)) { // include JavaScript only if a button was created + $this->pageRenderer->loadJavaScriptModule('@supseven/yaml-configuration/Backend.js'); + } // Persist final buttons configuration $event->setButtons($buttons); From 115a71dea377c356fc3d1bfba97532f0ab170b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= Date: Wed, 13 Nov 2024 11:44:58 +0100 Subject: [PATCH 7/7] Update QueryBuilder methods --- Classes/Command/AbstractTableCommand.php | 10 +++++----- Classes/Command/ExportTableCommand.php | 2 +- Classes/Command/ImportTableCommand.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Command/AbstractTableCommand.php b/Classes/Command/AbstractTableCommand.php index 393ddb9..2f0d5d3 100644 --- a/Classes/Command/AbstractTableCommand.php +++ b/Classes/Command/AbstractTableCommand.php @@ -83,16 +83,16 @@ protected function getColumnNames(): array $result = $this->queryBuilderForTable($table) ->select('*') ->from($table) - ->execute() - ->fetch(); + ->executeQuery() + ->fetchAssociative(); if ($result) { $columnNames = \array_keys($result); $this->tableColumnCache[$table] = $columnNames; } else { $result = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table); - $result = $result->getSchemaManager()->listTableColumns($table); - foreach ($result as $columnName => $columnProperties) { - $columnNames[] = $columnName; + $result = $result->getSchemaInformation()->introspectTable($table)->getColumns(); + foreach ($result as $columnProperties) { + $columnNames[] = $columnProperties->getName(); } $this->tableColumnCache[$table] = $columnNames; } diff --git a/Classes/Command/ExportTableCommand.php b/Classes/Command/ExportTableCommand.php index 7ecf55c..e6f32af 100644 --- a/Classes/Command/ExportTableCommand.php +++ b/Classes/Command/ExportTableCommand.php @@ -271,7 +271,7 @@ protected function exportTable(SymfonyStyle $io): void ) ) ) - ->execute(); + ->executeQuery(); $usergroupsTitles = []; foreach ($usergroups as $singleUserGroup) { $usergroupsTitles[] = $singleUserGroup['title']; diff --git a/Classes/Command/ImportTableCommand.php b/Classes/Command/ImportTableCommand.php index 0fc1f11..fd2ebdd 100644 --- a/Classes/Command/ImportTableCommand.php +++ b/Classes/Command/ImportTableCommand.php @@ -146,7 +146,7 @@ protected function importData(SymfonyStyle $io): void ) ); } - $row = $row->where(...$whereClause)->execute()->fetch(); + $row = $row->where(...$whereClause)->executeQuery()->fetchAssociative(); } if ($row) { // Update row as the matched row exists in the table