diff --git a/Classes/Command/CountryNameMigrationCommand.php b/Classes/Command/CountryNameMigrationCommand.php index cb9da87..3d68b17 100644 --- a/Classes/Command/CountryNameMigrationCommand.php +++ b/Classes/Command/CountryNameMigrationCommand.php @@ -13,19 +13,12 @@ class CountryNameMigrationCommand extends Command { - - /** - * @inheritdoc - */ protected function configure(): void { $this->setDescription('Migrate tt_address country field'); } - /** - * @inheritdoc - */ - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): int { $service = GeneralUtility::makeInstance(MigrationService::class); $count = $service->run(); @@ -33,5 +26,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void $io = new SymfonyStyle($input, $output); $io->title($this->getDescription()); $io->success(sprintf('Migrated %s records!', $count)); + + return Command::SUCCESS; } } diff --git a/Classes/Extending/Domain/Model/Address.php b/Classes/Extending/Domain/Model/Address.php index 77e2f83..57d76de 100644 --- a/Classes/Extending/Domain/Model/Address.php +++ b/Classes/Extending/Domain/Model/Address.php @@ -6,44 +6,27 @@ class Address extends \FriendsOfTYPO3\TtAddress\Domain\Model\Address { - - /** - * @var \SJBR\StaticInfoTables\Domain\Model\Country - */ + /** @var \SJBR\StaticInfoTables\Domain\Model\Country */ protected $countryRelation; - /** - * @var \SJBR\StaticInfoTables\Domain\Model\CountryZone - */ + /** @var \SJBR\StaticInfoTables\Domain\Model\CountryZone */ protected $regionRelation; - /** - * @return \SJBR\StaticInfoTables\Domain\Model\Country - */ public function getCountryRelation(): ?\SJBR\StaticInfoTables\Domain\Model\Country { return $this->countryRelation; } - /** - * @param \SJBR\StaticInfoTables\Domain\Model\Country $countryRelation - */ public function setCountryRelation(\SJBR\StaticInfoTables\Domain\Model\Country $countryRelation): void { $this->countryRelation = $countryRelation; } - /** - * @return \SJBR\StaticInfoTables\Domain\Model\CountryZone - */ public function getRegionRelation(): ?\SJBR\StaticInfoTables\Domain\Model\CountryZone { return $this->regionRelation; } - /** - * @param \SJBR\StaticInfoTables\Domain\Model\CountryZone $regionRelation - */ public function setRegionRelation(\SJBR\StaticInfoTables\Domain\Model\CountryZone $regionRelation): void { $this->regionRelation = $regionRelation; diff --git a/Classes/Migration/MigrationService.php b/Classes/Migration/MigrationService.php index db23e0b..a909206 100644 --- a/Classes/Migration/MigrationService.php +++ b/Classes/Migration/MigrationService.php @@ -4,7 +4,11 @@ namespace StudioMitte\TtaddressCountryRelation\Migration; +use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction; +use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; +use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction; use TYPO3\CMS\Core\Utility\GeneralUtility; class MigrationService @@ -14,15 +18,20 @@ public function run(): int $count = 0; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_address'); + $queryBuilder->getRestrictions() + ->removeByType(HiddenRestriction::class) + ->removeByType(StartTimeRestriction::class) + ->removeByType(EndTimeRestriction::class); + $rows = $queryBuilder ->select('uid', 'country') ->from('tt_address') ->where( - $queryBuilder->expr()->eq('country_relation', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)), - $queryBuilder->expr()->neq('country', $queryBuilder->createNamedParameter('', \PDO::PARAM_STR)), - ) - ->execute() - ->fetchAll(); + $queryBuilder->expr()->eq('country_relation', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)), + $queryBuilder->expr()->neq('country', $queryBuilder->createNamedParameter('', Connection::PARAM_STR))) + ->executeQuery() + ->fetchAllAssociative(); + foreach ($rows as $row) { if ($this->updateSingleRow($row['country'], $row['uid'])) { $count++; @@ -60,20 +69,16 @@ protected function getStaticCountryRow(string $countryName): int ->select('*') ->from('static_countries') ->where( - $queryBuilder->expr()->orX( - $queryBuilder->expr()->eq('cn_short_local', $queryBuilder->createNamedParameter($countryName, \PDO::PARAM_STR)), - $queryBuilder->expr()->eq('cn_short_en', $queryBuilder->createNamedParameter($countryName, \PDO::PARAM_STR)), - $queryBuilder->expr()->eq('cn_official_name_en', $queryBuilder->createNamedParameter($countryName, \PDO::PARAM_STR)), - $queryBuilder->expr()->eq('cn_iso_2', $queryBuilder->createNamedParameter($countryName, \PDO::PARAM_STR)), - $queryBuilder->expr()->eq('cn_iso_3', $queryBuilder->createNamedParameter($countryName, \PDO::PARAM_STR)) - ) - ) - ->setMaxResults(1) - ->execute() - ->fetch(); + $queryBuilder->expr()->or( + $queryBuilder->expr()->eq('cn_short_local', $queryBuilder->createNamedParameter($countryName, Connection::PARAM_STR)), + $queryBuilder->expr()->eq('cn_short_en', $queryBuilder->createNamedParameter($countryName, Connection::PARAM_STR)), + $queryBuilder->expr()->eq('cn_official_name_en', $queryBuilder->createNamedParameter($countryName, Connection::PARAM_STR)), + $queryBuilder->expr()->eq('cn_iso_2', $queryBuilder->createNamedParameter($countryName, Connection::PARAM_STR)), + $queryBuilder->expr()->eq('cn_iso_3', $queryBuilder->createNamedParameter($countryName, Connection::PARAM_STR))) + )->setMaxResults(1)->executeQuery()->fetchAssociative(); if ($row) { - return (int)$row['uid']; + return (int) $row['uid']; } return 0; diff --git a/Configuration/Commands.php b/Configuration/Commands.php deleted file mode 100644 index e637c46..0000000 --- a/Configuration/Commands.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'class' => \StudioMitte\TtaddressCountryRelation\Command\CountryNameMigrationCommand::class, - 'schedulable' => false, - ], -]; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..3da2fed --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,17 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + StudioMitte\TtaddressCountryRelation\Command\CountryNameMigrationCommand: + tags: + - name: 'console.command' + command: 'ttaddress_country_relation:migrate' + description: 'Migrate tt_address country field' + schedulable: false + + StudioMitte\TtaddressCountryRelation\Extending\Domain\Model\Address: + tags: + - name: 'extender.extends' + class: FriendsOfTYPO3\TtAddress\Domain\Model\Address diff --git a/Configuration/TCA/Overrides/tt_address.php b/Configuration/TCA/Overrides/tt_address.php index 9afb5cf..00051ec 100644 --- a/Configuration/TCA/Overrides/tt_address.php +++ b/Configuration/TCA/Overrides/tt_address.php @@ -1,7 +1,7 @@ 0, 'maxitems' => 1, 'type' => 'group', - 'internal_type' => 'db', 'allowed' => 'static_countries', 'foreign_table' => 'static_countries', 'suggestOptions' => [ @@ -41,7 +40,6 @@ function ($extKey): void { 'minitems' => 0, 'maxitems' => 1, 'type' => 'group', - 'internal_type' => 'db', 'allowed' => 'static_country_zones', 'foreign_table' => 'static_country_zones', 'suggestOptions' => [ diff --git a/composer.json b/composer.json index 3931440..91f886e 100755 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ ], "license": "GPL-2.0-or-later", "require": { - "typo3/cms-core": "^11.0", + "typo3/cms-core": "^11.0 || ^12.4 || ^13.4", "php": ">=7.4", - "friendsoftypo3/tt-address": "^5.3 || ^6", - "evoweb/extender": "^8.1", - "sjbr/static-info-tables": "^11.5" + "friendsoftypo3/tt-address": "^5.3 || ^6 || ^7 || ^8 || ^9", + "evoweb/extender": "^10.1 || ^11", + "sjbr/static-info-tables": "^11.5 || ^12.4 || ^13.4" }, "extra": { "typo3/cms": { diff --git a/ext_emconf.php b/ext_emconf.php index 430e6d9..4fdc318 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -7,16 +7,15 @@ 'description' => 'Use a relation to static_info_tables for the country field', 'category' => 'be', 'state' => 'stable', - 'clearCacheOnLoad' => true, 'author' => 'Georg Ringer', 'author_email' => 'gr@studiomitte.com', 'version' => '2.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '11.5.0-11.5.99', - 'tt_address' => '5.3.0-6.99.99', - 'static_info_tables' => '11.5.1-11.5.99', - 'extender' => '8.1.0-8.9.99', + 'typo3' => '11.5.0-13.4.99', + 'tt_address' => '5.3.0-9.99.99', + 'static_info_tables' => '11.5.1-12.4.99', + 'extender' => '10.1.0-10.99.99', ], 'conflicts' => [ ], diff --git a/ext_localconf.php b/ext_localconf.php deleted file mode 100644 index 75174ba..0000000 --- a/ext_localconf.php +++ /dev/null @@ -1,14 +0,0 @@ -