Skip to content

Commit

Permalink
[WIP] Deprecated functions replaced, minor code style changes, README…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
kranz committed Mar 30, 2022
1 parent e9faf29 commit 008e24e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 22 deletions.
5 changes: 4 additions & 1 deletion Classes/Command/UpdateIpDatabaseCommand.php
Expand Up @@ -103,7 +103,10 @@ private function validateArguments(): bool
private function truncateTable(): void
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->table);
$connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSQL($this->table, true));
$databasePlatform = $connection->getDatabasePlatform();
if ($databasePlatform) {
$connection->executeStatement($databasePlatform->getTruncateTableSQL($this->table, true));
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/RegionRepository.php
Expand Up @@ -33,7 +33,7 @@ public function getCountriesForPage(int $id): array
->join('rmm', 'static_countries', 'c', 'c.uid = rmm.uid_foreign')
->where($qb->expr()->eq('pmm.uid_local', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
->execute()
->fetchAll();
->fetchAllAssociative();

foreach ($results as $result) {
$iso2Codes[$result['cn_iso_2']] = true;
Expand All @@ -52,7 +52,7 @@ public function shouldApplyWhenNoIpMatches(int $id): bool
->where($qb->expr()->eq('uid_local', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
->andWhere($qb->expr()->eq('uid_foreign', $qb->createNamedParameter(self::APPLY_WHEN_NO_IP_MATCHES, \PDO::PARAM_INT)))
->execute()
->fetchAll();
->fetchAllAssociative();

return !empty($results);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/FactProvider/IP2Country.php
Expand Up @@ -33,7 +33,7 @@ public function getBasename(): string
*/
public function process(): self
{
$iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP();
$iso2 = GeneralUtility::makeInstance(LocateUtility::class)->getCountryIso2FromIP() ?? '';
LocateUtility::mainstreamValue($iso2);
$this->facts[$this->getBasename()] = $iso2;

Expand Down
2 changes: 1 addition & 1 deletion Classes/Hook/OverrideIconOverlayHook.php
Expand Up @@ -52,6 +52,6 @@ private function countRegions(string $table, array $row): int
->from($table)
->where($qb->expr()->eq('uid', $row['uid']))
->execute()
->fetchColumn(0);
->fetchOne();
}
}
6 changes: 6 additions & 0 deletions Classes/Judge/Condition.php
Expand Up @@ -14,6 +14,7 @@
namespace Leuchtfeuer\Locate\Judge;

use Leuchtfeuer\Locate\FactProvider\AbstractFactProvider;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class Condition extends AbstractJudge
{
Expand All @@ -24,6 +25,11 @@ public function adjudicate(AbstractFactProvider $factProvider, int $priority = A
{
$prosecution = $this->configuration['prosecution'] ?? $this->configuration['prosecution.'] ?? null;

DebuggerUtility::var_dump($prosecution);
DebuggerUtility::var_dump($factProvider);
DebuggerUtility::var_dump($priority);
die;

if ($prosecution !== null && $factProvider->isGuilty($prosecution) && isset($this->configuration['verdict'])) {
$this->decision = (new Decision())->withVerdictName($this->configuration['verdict']);
$this->decision->setPriority($priority);
Expand Down
11 changes: 6 additions & 5 deletions Classes/Utility/LocateUtility.php
Expand Up @@ -27,7 +27,7 @@ class LocateUtility
public function getCountryIso2FromIP(?string $ip = null)
{
$ip = $this->getNumericIp($ip);
$tableName = self::getTableNameForIp($ip);
$tableName = $this->getTableNameForIp($ip);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);

return $queryBuilder
Expand All @@ -36,12 +36,12 @@ public function getCountryIso2FromIP(?string $ip = null)
->where($queryBuilder->expr()->lte('ip_from', $queryBuilder->createNamedParameter($ip)))
->andWhere($queryBuilder->expr()->gte('ip_to', $queryBuilder->createNamedParameter($ip)))
->execute()
->fetchColumn(0);
->fetchOne();
}

public function getNumericIp(?string $ip = null): string
{
$ip = $ip ?? GeneralUtility::getIndpEnv('REMOTE_ADDR');
$ip = $ip ?? (string)GeneralUtility::getIndpEnv('REMOTE_ADDR');

return strpos($ip, '.') !== false ? (string)ip2long($ip) : $this->convertIpv6($ip);
}
Expand All @@ -63,7 +63,8 @@ private function convertIpv6(string $ip): string
break;

case function_exists('bcadd'):
for ($i = 0; $i < strlen($bin); $i++) {
$max = strlen($bin);
for ($i = 0; $i < $max; $i++) {
$decimalIp = bcmul($decimalIp, '2');
$decimalIp = bcadd($decimalIp, $bin[$i]);
}
Expand All @@ -80,7 +81,7 @@ private function convertIpv6(string $ip): string
return $decimalIp;
}

public static function mainstreamValue(string &$value)
public static function mainstreamValue(string &$value): void
{
$value = mb_strtolower(str_replace('-', '_', $value));
}
Expand Down
18 changes: 9 additions & 9 deletions README.md
@@ -1,10 +1,11 @@
Language Utilities for TYPO3
============================

[![TYPO3 10](https://img.shields.io/badge/TYPO3-10-orange.svg)](https://get.typo3.org/version/10)
[![TYPO3 11](https://img.shields.io/badge/TYPO3-11-orange.svg)](https://get.typo3.org/version/11)
[![Latest Stable Version](https://poser.pugx.org/leuchtfeuer/locate/v/stable)](https://packagist.org/packages/leuchtfeuer/locate)
[![Build Status](https://github.com/Leuchtfeuer/locate/workflows/Continous%20Integration/badge.svg)](https://github.com/Leuchtfeuer/locate/actions)
[![Total Downloads](https://poser.pugx.org/leuchtfeuer/locate/downloads)](https://packagist.org/leuchtfeuer/locate)
[![Latest Unstable Version](https://poser.pugx.org/leuchtfeuer/locate/v/unstable)](https://packagist.org/leuchtfeuer/locate)
[![Code Climate](https://codeclimate.com/github/Leuchtfeuer/locate/badges/gpa.svg)](https://codeclimate.com/github/Leuchtfeuer/locate)
[![codecov](https://codecov.io/gh/Leuchtfeuer/locate/branch/master/graph/badge.svg?token=0GcE422Ms1)](https://codecov.io/gh/Leuchtfeuer/locate)
[![License](https://poser.pugx.org/leuchtfeuer/locate/license)](https://packagist.org/packages/leuchtfeuer/locate)
Expand All @@ -18,14 +19,13 @@ The full documentation for the latest releases can be found [here](https://docs.

We are currently supporting following TYPO3 versions:<br><br>

| Extension Version | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support |
| :-: | :-: | :-: | :-: |
| 11.x | x | - | - |
| 10.x | x | x | - |
| 9.x | - | x | - |
| 8.x | - | x | x |

_Beta support for TYPO3 v11.0 is available since version 11.0.0._
| Extension Version | TYPO3 v11 Support | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support |
|-------------------|-------------------|-------------------|------------------|------------------|
| 11.x | x | x | - | - |
| 10.x | - | x | x | - |
| 9.x | - | x | - | - |
| 8.x | - | x | x | - |
| 7.x | - | - | - | 8 |

### IPv6 Support

Expand Down
12 changes: 9 additions & 3 deletions composer.json
Expand Up @@ -27,8 +27,10 @@
}
],
"require": {
"typo3/cms-core": "^10.4.10 || ^11.5.0",
"typo3/cms-frontend": "^10.4.10 || ^11.5.0",
"typo3/cms-backend": "^10.4 || ^11.5",
"typo3/cms-core": "^10.4 || ^11.5",
"typo3/cms-extbase": "^10.4 || ^11.5",
"typo3/cms-frontend": "^10.4 || ^11.5",
"symfony/console": "^4.4 || ^5.0"
},
"suggest": {
Expand All @@ -53,7 +55,11 @@
},
"config": {
"vendor-dir": ".Build/vendor",
"bin-dir": ".Build/bin"
"bin-dir": ".Build/bin",
"allow-plugins": {
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true
}
},
"scripts": {
"post-autoload-dump": [
Expand Down

0 comments on commit 008e24e

Please sign in to comment.