Skip to content
Merged
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
69 changes: 69 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# TS/JS-Files
[*.{ts,js}]
indent_size = 2

# JSON-Files
[*.json]
indent_style = tab

# ReST-Files
[*.{rst,rst.txt}]
indent_size = 4
max_line_length = 80

# Markdown-Files
[*.md]
max_line_length = 80

# YAML-Files
[*.{yaml,yml}]
indent_size = 2

# NEON-Files
[*.neon]
indent_size = 2
indent_style = tab

#.eslintrc.json
[.eslintrc.json]
indent_size = 2
indent_style = space

# stylelint
[.stylelintrc]
indent_size = 2

# package.json
[package.json]
indent_size = 2

# TypoScript
[*.{typoscript,tsconfig}]
indent_size = 2

# XLF-Files
[*.xlf]
indent_style = tab

# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
pull_request:

jobs:
static-analysis:
name: "PHPStan / PHP ${{ matrix.php }} / TYPO3 ${{ matrix.typo3 }}"
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php: "8.2"
typo3: "^13.4"
- php: "8.5"
typo3: "^14.3"

steps:
- uses: actions/checkout@v4

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer

- name: Require TYPO3 version
run: composer require typo3/cms-core "${{ matrix.typo3 }}" --no-update

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-plugins

- name: Validate composer.json
run: composer validate --strict

- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
vendor
public
.php-cs-fixer.cache
8 changes: 8 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()
->in(__DIR__)
;

return $config;
25 changes: 11 additions & 14 deletions Classes/Service/GeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand All @@ -33,7 +33,8 @@ class GeoService implements SingletonInterface
public function __construct(
protected readonly FrontendInterface $cache,
protected readonly ExtensionConfiguration $extensionConfiguration,
protected readonly RequestFactory $requestFactory
protected readonly RequestFactory $requestFactory,
private readonly ConnectionPool $connectionPool
) {
$geoCodingConfig = $extensionConfiguration->get('geocoding');
// load from extension configuration
Expand Down Expand Up @@ -68,7 +69,7 @@ public function getCoordinatesForAddress(?string $street = null, ?string $zip =
}

$address = ltrim(implode(',', $addressParts), ',');
if (empty($address)) {
if ($address === '' || $address === '0') {
return [];
}

Expand Down Expand Up @@ -115,7 +116,7 @@ public function calculateCoordinatesForAllRecordsInTable(
string $addWhereClause = ''
): int {
// Fetch all records without latitude/longitude
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
$connection = $this->connectionPool->getConnectionForTable($tableName);
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()
->removeAll()
Expand All @@ -124,18 +125,18 @@ public function calculateCoordinatesForAllRecordsInTable(
->select('*')
->from($tableName)
->where(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->isNull($latitudeField),
$queryBuilder->expr()->eq($latitudeField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq($latitudeField, $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq($latitudeField, 0.00000000000),
$queryBuilder->expr()->isNull($longitudeField),
$queryBuilder->expr()->eq($longitudeField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq($longitudeField, $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
$queryBuilder->expr()->eq($longitudeField, 0.00000000000)
)
)
->setMaxResults(500);

if (!empty($addWhereClause)) {
if ($addWhereClause !== '' && $addWhereClause !== '0') {
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($addWhereClause));
}

Expand All @@ -147,18 +148,14 @@ public function calculateCoordinatesForAllRecordsInTable(
if (($GLOBALS['TCA'][$tableName]['columns'][$countryField]['config']['type'] ?? '') === 'select') {
foreach ($GLOBALS['TCA'][$tableName]['columns'][$countryField]['config']['items'] ?? [] as $itm) {
if (($itm[1] ?? null) === $country) {
if (is_object($GLOBALS['TSFE'])) {
$country = $GLOBALS['TSFE']->sL($itm[0]);
} else {
$country = $GLOBALS['LANG']->sL($itm[0]);
}
$country = is_object($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->sL($itm[0]) : $GLOBALS['LANG']->sL($itm[0]);
}
}
}
// do the geocoding
if (!empty($record[$zipField]) || !empty($record[$cityField])) {
$coords = $this->getCoordinatesForAddress($record[$streetField] ?? null, $record[$zipField] ?? null, $record[$cityField] ?? null, $country);
if ($coords) {
if ($coords !== []) {
// Update the record to fill in the latitude and longitude values in the DB
$connection->update(
$tableName,
Expand Down
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license": "GPL-2.0-or-later",
"keywords": ["TYPO3 CMS", "TYPO3", "Google Geocoding"],
"require": {
"php": "^8.1",
"typo3/cms-core": "^11.5 || ^12.4"
"php": "^8.2",
"typo3/cms-core": "^13.4 || ^14.3"
},
"extra": {
"typo3/cms": {
Expand All @@ -18,5 +18,15 @@
"psr-4": {
"B13\\Geocoding\\": "Classes/"
}
},
"require-dev": {
"typo3/coding-standards": "^0.8.0",
"saschaegerer/phpstan-typo3": "^2.0 || ^3.0"
},
"config": {
"allow-plugins": {
"typo3/cms-composer-installers": true,
"typo3/class-alias-loader": true
}
}
}
11 changes: 4 additions & 7 deletions ext_emconf.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<?php

declare(strict_types=1);

$EM_CONF[$_EXTKEY] = [
'title' => 'Service: Geocoding via Google Maps',
'description' => 'Provides services for google maps GeoCoding API and radius search on the database.',
'category' => 'sv',
'author' => 'Benjamin Mack',
'author_email' => 'benjamin.mack@b13.com',
'author_company' => 'b13 GmbH',
'shy' => '',
'state' => 'stable',
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'version' => '5.0.0',
'version' => '6.0.0',
'constraints' => [
'depends' => [
'typo3' => '11.5.0-12.4.99',
'typo3' => '13.4.0-14.3.99',
],
'conflicts' => [
],
Expand Down
11 changes: 8 additions & 3 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php

defined('TYPO3') or die();
declare(strict_types=1);

use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;

defined('TYPO3') || die();

// Define state cache, if not already defined
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['geocoding'] ?? false)) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['geocoding'] = [
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
'frontend' => VariableFrontend::class,
'backend' => Typo3DatabaseBackend::class,
];
}
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- vendor/saschaegerer/phpstan-typo3/extension.neon

parameters:
level: 5
paths:
- Classes
treatPhpDocTypesAsCertain: false