From 101bac41581d9a3decf94f50ed85d38bcb0f00b5 Mon Sep 17 00:00:00 2001 From: Christian Rath-Ulrich Date: Sat, 1 Feb 2025 23:24:27 +0100 Subject: [PATCH 1/4] !![BRAKING][FETURE] add compatibility to typo3 12 and 13, Dropp compatibility to typo3 9 and 10 --- .../RandomdataCommandController.php | 31 +++++------ Classes/Event/RandomdataEvent.php | 37 +++++++++++++ Classes/Service/RandomdataService.php | 55 +++++++++---------- README.md | 8 ++- composer.json | 2 +- ext_localconf.php | 12 ++-- 6 files changed, 92 insertions(+), 53 deletions(-) create mode 100644 Classes/Event/RandomdataEvent.php diff --git a/Classes/Controller/RandomdataCommandController.php b/Classes/Controller/RandomdataCommandController.php index da9a5b5..8d619e8 100755 --- a/Classes/Controller/RandomdataCommandController.php +++ b/Classes/Controller/RandomdataCommandController.php @@ -15,25 +15,25 @@ */ use Faker\Factory; +use TYPO3\CMS\Extbase\Exception; +use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; use Symfony\Component\Console\Command\Command; +use WIND\Randomdata\Service\RandomdataService; +use WIND\Randomdata\Exception\ProviderException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use WIND\Randomdata\Exception\DataHandlerException; use Symfony\Component\Console\Output\OutputInterface; -use TYPO3\CMS\Core\Core\Bootstrap; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Exception; -use TYPO3\CMS\Extbase\Object\ObjectManager; -use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException; -use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException; -use WIND\Randomdata\Exception\ConfigurationFileNotFoundException; -use WIND\Randomdata\Exception\FieldsNotFoundForItemException; +use WIND\Randomdata\Exception\UnknownActionException; use WIND\Randomdata\Exception\PidNotFoundForItemException; use WIND\Randomdata\Exception\TableNotFoundInTcaException; -use WIND\Randomdata\Exception\UnknownActionException; use WIND\Randomdata\Exception\CountNotFoundForItemException; -use WIND\Randomdata\Exception\DataHandlerException; -use WIND\Randomdata\Exception\ProviderException; -use WIND\Randomdata\Service\RandomdataService; +use WIND\Randomdata\Exception\FieldsNotFoundForItemException; +use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException; +use WIND\Randomdata\Exception\ConfigurationFileNotFoundException; +use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException; /** * Randomdata Command Controller @@ -72,13 +72,12 @@ public function configure() * @throws InvalidSlotReturnException * @throws Exception */ - public function execute(InputInterface $input, OutputInterface $output) + public function execute(InputInterface $input, OutputInterface $output): int { Bootstrap::initializeBackendAuthentication(); - /** @var ObjectManager $objectManager */ - $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + /** @var RandomdataService $randomdataService */ - $randomdataService = $objectManager->get(RandomdataService::class); + $randomdataService = GeneralUtility::makeInstance(RandomdataService::class); $randomdataService->generate($input->getArgument('file'), $input->getArgument('locale'), $output); return 0; diff --git a/Classes/Event/RandomdataEvent.php b/Classes/Event/RandomdataEvent.php new file mode 100644 index 0000000..629fc81 --- /dev/null +++ b/Classes/Event/RandomdataEvent.php @@ -0,0 +1,37 @@ +arguments = $arguments; + $this->name = $name; + } + + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + public function getArguments() + { + return $this->arguments; + } +} \ No newline at end of file diff --git a/Classes/Service/RandomdataService.php b/Classes/Service/RandomdataService.php index 74cd9e6..b4f9baa 100755 --- a/Classes/Service/RandomdataService.php +++ b/Classes/Service/RandomdataService.php @@ -16,25 +16,26 @@ use Faker\Factory; use Faker\Generator; -use Symfony\Component\Console\Output\OutputInterface; -use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; -use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Database\Query\QueryBuilder; -use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Utility\GeneralUtility; +use WIND\Randomdata\Event\RandomdataEvent; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Extbase\Object\ObjectManager; -use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; -use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException; -use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException; -use WIND\Randomdata\Exception\ConfigurationFileNotFoundException; -use WIND\Randomdata\Exception\CountNotFoundForItemException; +use TYPO3\CMS\Core\DataHandling\DataHandler; +use TYPO3\CMS\Core\Database\Query\QueryBuilder; +use WIND\Randomdata\Provider\ProviderInterface; +use WIND\Randomdata\Exception\ProviderException; +use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; use WIND\Randomdata\Exception\DataHandlerException; -use WIND\Randomdata\Exception\FieldsNotFoundForItemException; +use Symfony\Component\Console\Output\OutputInterface; +use WIND\Randomdata\Exception\UnknownActionException; +use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; use WIND\Randomdata\Exception\PidNotFoundForItemException; -use WIND\Randomdata\Exception\ProviderException; use WIND\Randomdata\Exception\TableNotFoundInTcaException; -use WIND\Randomdata\Exception\UnknownActionException; -use WIND\Randomdata\Provider\ProviderInterface; +use WIND\Randomdata\Exception\CountNotFoundForItemException; +use WIND\Randomdata\Exception\FieldsNotFoundForItemException; +use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException; +use WIND\Randomdata\Exception\ConfigurationFileNotFoundException; +use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException; /** * Randomdata Service @@ -81,13 +82,7 @@ class RandomdataService */ protected $newUid = 0; - /** - * @param ObjectManager $objectManager - */ - public function injectObjectManager(ObjectManager $objectManager) - { - $this->objectManager = $objectManager; - } + /** * Generate random data @@ -179,7 +174,7 @@ protected function loadConfigurationFile($configurationFile) } /** @var YamlFileLoader $yamlLoader */ - $yamlLoader = $this->objectManager->get(YamlFileLoader::class); + $yamlLoader = GeneralUtility::makeInstance(YamlFileLoader::class); $this->configuration = $yamlLoader->load($configurationFile); } @@ -269,7 +264,7 @@ protected function getItemPid($configurationKey, array $itemConfiguration) $pageQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $page = $pageQueryBuilder->count('*')->from('pages')->where( $pageQueryBuilder->expr()->eq('uid', $pid) - )->execute()->fetchColumn(0); + )->executeQuery()->fetchColumn(0); if ($page !== 1) { throw new PidNotFoundForItemException('Page with uid "' . $pid . '" not found in database for item "' . $configurationKey . '"', 1554380475); @@ -403,15 +398,16 @@ protected function generateAndReplaceRecords($configurationKey, $table, $pid, ar { /** @var QueryBuilder $queryBuilder */ $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); - $records = $queryBuilder->select('uid')->from($table)->where($queryBuilder->expr()->eq('pid', $pid))->execute(); - + $records = $queryBuilder->select('uid')->from($table)->where($queryBuilder->expr()->eq('pid', $pid))->executeQuery()->fetchAllAssociative(); + if (!empty($records)) { $dataMap = [$table => []]; - + $this->addToDataMap = []; $this->addToCmdMap = []; - + foreach ($records as $record) { + $data = []; foreach ($fields as $field => $fieldConfiguration) { $fieldConfiguration['__table'] = $table; @@ -489,9 +485,8 @@ public function generateData($configurationKey, $field, array $fieldConfiguratio */ protected function dispatchSignalSlot($name, array $arguments) { - /** @var Dispatcher $signalSlotDispatcher */ - $signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class); - $signalSlotDispatcher->dispatch(__CLASS__, $name, $arguments); + $eventDispatcher = GeneralUtility::makeInstance(EventDispatcher::class); + $eventDispatcher->dispatch(new RandomdataEvent($name, $arguments)); } /** diff --git a/README.md b/README.md index 156ee2c..7f29bbe 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,14 @@ TYPO3 extensions to generate new random data or replace existing data with rando This extensions uses https://github.com/FakerPHP/Faker and was inspired by https://github.com/georgringer/faker. Thanks go out to the builders, contributors and maintainers of those projects. ## Requirements -- TYPO3 CMS 9.5, 10.4 or 11.5 -- PHP 7.2+ +- TYPO3 11.5 12.4 +- PHP 8.1+ - Licence: GPL 3.0 +## install +``` +composer require windinternet/randomdata +``` ## Manual After installing randomdata in TYPO3 you can run it using the following command: diff --git a/composer.json b/composer.json index 2cc6274..2e2dadf 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "typo3-cms-extension", "license": "GPL-3.0-or-later", "require": { - "typo3/cms-core": "^9.5.30 || ^10.4.20 || ^11.3.3", + "typo3/cms-core": "^11.5 || ^12.4 || ^13.0", "fakerphp/faker": "^1.19" }, "replace": { diff --git a/ext_localconf.php b/ext_localconf.php index 7cd2e96..6f77b7a 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,10 @@ Date: Thu, 20 Feb 2025 20:14:58 +0100 Subject: [PATCH 2/4] fix: usage of unknown method fetchColumn --- Classes/Service/RandomdataService.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Classes/Service/RandomdataService.php b/Classes/Service/RandomdataService.php index b4f9baa..ba27a42 100755 --- a/Classes/Service/RandomdataService.php +++ b/Classes/Service/RandomdataService.php @@ -62,10 +62,6 @@ class RandomdataService */ protected $faker; - /** - * @var ObjectManager - */ - protected $objectManager; /** * @var array @@ -100,8 +96,6 @@ class RandomdataService * @throws CountNotFoundForItemException * @throws DataHandlerException * @throws ProviderException - * @throws InvalidSlotException - * @throws InvalidSlotReturnException */ public function generate($configurationFile, $locale, $output = null) { @@ -264,9 +258,9 @@ protected function getItemPid($configurationKey, array $itemConfiguration) $pageQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $page = $pageQueryBuilder->count('*')->from('pages')->where( $pageQueryBuilder->expr()->eq('uid', $pid) - )->executeQuery()->fetchColumn(0); - - if ($page !== 1) { + )->executeQuery()->fetchFirstColumn(); + + if ($page[0] !== 1) { throw new PidNotFoundForItemException('Page with uid "' . $pid . '" not found in database for item "' . $configurationKey . '"', 1554380475); } } From 1d584de3e9deec679ac928ed01597ffd38c9a658 Mon Sep 17 00:00:00 2001 From: Christian Rath-Ulrich Date: Thu, 20 Feb 2025 20:47:49 +0100 Subject: [PATCH 3/4] fix: replace ->fetchFirstColumn() by ->fetchColumn(0) for compatibility to typo3 13.4 addapt docu to event as replacement of the signal slots --- Classes/Service/RandomdataService.php | 6 +++--- README.md | 2 +- composer.json | 2 +- ext_localconf.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Classes/Service/RandomdataService.php b/Classes/Service/RandomdataService.php index ba27a42..d99f126 100755 --- a/Classes/Service/RandomdataService.php +++ b/Classes/Service/RandomdataService.php @@ -204,7 +204,7 @@ protected function generateItem($configurationKey, array $itemConfiguration) $this->generateAndReplaceRecords($configurationKey, $table, $pid, $fields, $itemConfiguration); break; default: - $this->dispatchSignalSlot('generateItemCustomAction', [$configurationKey, $table, $pid, $action, $fields, $itemConfiguration, $this]); + $this->dispatchRandomdataEvent('generateItemCustomAction', [$configurationKey, $table, $pid, $action, $fields, $itemConfiguration, $this]); break; } } catch(\Throwable $e) { @@ -469,7 +469,7 @@ public function generateData($configurationKey, $field, array $fieldConfiguratio } /** - * Dispatch signal slot + * Dispatch Randomdata vent * * @param string $name * @param array $arguments @@ -477,7 +477,7 @@ public function generateData($configurationKey, $field, array $fieldConfiguratio * @throws InvalidSlotReturnException * @return void */ - protected function dispatchSignalSlot($name, array $arguments) + protected function dispatchRandomdataEvent($name, array $arguments) { $eventDispatcher = GeneralUtility::makeInstance(EventDispatcher::class); $eventDispatcher->dispatch(new RandomdataEvent($name, $arguments)); diff --git a/README.md b/README.md index 7f29bbe..4d34b8d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ TYPO3 extensions to generate new random data or replace existing data with rando This extensions uses https://github.com/FakerPHP/Faker and was inspired by https://github.com/georgringer/faker. Thanks go out to the builders, contributors and maintainers of those projects. ## Requirements -- TYPO3 11.5 12.4 +- TYPO3 11.5, 12.4 or 13.4 - PHP 8.1+ - Licence: GPL 3.0 diff --git a/composer.json b/composer.json index 2e2dadf..940facc 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "typo3-cms-extension", "license": "GPL-3.0-or-later", "require": { - "typo3/cms-core": "^11.5 || ^12.4 || ^13.0", + "typo3/cms-core": "^11.5 || ^12.4 || ^13.4", "fakerphp/faker": "^1.19" }, "replace": { diff --git a/ext_localconf.php b/ext_localconf.php index 6f77b7a..7f6d74d 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -5,6 +5,6 @@ call_user_func(static function () { - $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['randomdata']['allowedActions'] = ['insert', 'replace', 'foo']; + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['randomdata']['allowedActions'] = ['insert', 'replace']; }); From f864f3231d1d74b871ee8d04981870fc4bae8837 Mon Sep 17 00:00:00 2001 From: Christian Rath-Ulrich Date: Thu, 20 Feb 2025 21:08:37 +0100 Subject: [PATCH 4/4] doc: replace signal slot with event in doku --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d34b8d..4655aff 100644 --- a/README.md +++ b/README.md @@ -211,4 +211,4 @@ You can create a custom provider from your own extension by adding a class which You can set your custom provider in the configuration yaml file by setting the full class name in the `provider` option. For example `provider: \My\Custom\Provider` ## Custom action -If you need anything other than `insert` or `replace` as action, you can use the `generateItemCustomAction` signal slot. You also need to set your action in the `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['randomdata']['allowedActions']` array. +If you need anything other than `insert` or `replace` as action, you can use the `RandomdataEvent` Event. You also need to set your action in the `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['randomdata']['allowedActions']` array.