Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo3v13 support #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Classes/Command/CountryNameMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@

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();

$io = new SymfonyStyle($input, $output);
$io->title($this->getDescription());
$io->success(sprintf('Migrated %s records!', $count));

return Command::SUCCESS;
}
}
21 changes: 2 additions & 19 deletions Classes/Extending/Domain/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 22 additions & 17 deletions Classes/Migration/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions Configuration/Commands.php

This file was deleted.

17 changes: 17 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions Configuration/TCA/Overrides/tt_address.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

declare(strict_types=1);
defined('TYPO3_MODE') || die('Access denied.');
defined('TYPO3') || die('Access denied.');

call_user_func(
function ($extKey): void {
Expand All @@ -14,7 +14,6 @@ function ($extKey): void {
'minitems' => 0,
'maxitems' => 1,
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'static_countries',
'foreign_table' => 'static_countries',
'suggestOptions' => [
Expand All @@ -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' => [
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 4 additions & 5 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]',
'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' => [
],
Expand Down
14 changes: 0 additions & 14 deletions ext_localconf.php

This file was deleted.