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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
- name: 'CGL'
run: Build/Scripts/runTests.sh -n -p ${{ matrix.php }} -s cgl

- name: 'Execute unit tests'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s unit

- name: 'Execute functional tests'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -d mysql -s functional

Expand Down
21 changes: 10 additions & 11 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# EXT:examples test runner based on docker/podman.
# EXT:yellowpages test runner based on docker/podman.
#

trap 'cleanUp;exit 2' SIGINT
Expand Down Expand Up @@ -60,8 +60,8 @@ handleDbmsOptions() {
echo "Use \".Build/Scripts/runTests.sh -h\" to display help and valid options" >&2
exit 1
fi
[ -z "${DBMS_VERSION}" ] && DBMS_VERSION="10.4"
if ! [[ ${DBMS_VERSION} =~ ^(10.4|10.5|10.6|10.7|10.8|10.9|10.10|10.11|11.0|11.1)$ ]]; then
[ -z "${DBMS_VERSION}" ] && DBMS_VERSION="10.5"
if ! [[ ${DBMS_VERSION} =~ ^(10.5|10.6|10.7|10.8|10.9|10.10|10.11|11.0|11.1)$ ]]; then
echo "Invalid combination -d ${DBMS} -i ${DBMS_VERSION}" >&2
echo >&2
echo "Use \".Build/Scripts/runTests.sh -h\" to display help and valid options" >&2
Expand Down Expand Up @@ -125,7 +125,7 @@ handleDbmsOptions() {
loadHelp() {
# Load help text into $HELP
read -r -d '' HELP <<EOF
EXT:examples test runner. Check code styles, lint PHP files and some other details.
EXT:maps2 test runner. Check code styles, lint PHP files and some other details.

Usage: $0 [options] [file]

Expand Down Expand Up @@ -178,8 +178,7 @@ Options:
-i version
Specify a specific database version
With "-d mariadb":
- 10.4 short-term, maintained until 2024-06-18 (default)
- 10.5 short-term, maintained until 2025-06-24
- 10.5 short-term, maintained until 2025-06-24 (default)
- 10.6 long-term, maintained until 2026-06
- 10.7 short-term, no longer maintained
- 10.8 short-term, maintained until 2023-05
Expand All @@ -202,11 +201,11 @@ Options:
- 15 maintained until 2027-11-11
- 16 maintained until 2028-11-09

-p <8.1|8.2|8.3>
-p <8.2|8.3|8.4>
Specifies the PHP minor version to be used
- 8.1: use PHP 8.1
- 8.2: use PHP 8.2
- 8.2: use PHP 8.2 (default)
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4

-x
Only with -s functional|unit
Expand Down Expand Up @@ -254,7 +253,7 @@ TEST_SUITE="cgl"
DATABASE_DRIVER=""
DBMS="sqlite"
DBMS_VERSION=""
PHP_VERSION="8.1"
PHP_VERSION="8.2"
PHP_XDEBUG_ON=0
PHP_XDEBUG_PORT=9003
CGLCHECK_DRY_RUN=0
Expand Down Expand Up @@ -291,7 +290,7 @@ while getopts "a:b:d:i:s:p:xy:nhu" OPT; do
;;
p)
PHP_VERSION=${OPTARG}
if ! [[ ${PHP_VERSION} =~ ^(8.1|8.2|8.3)$ ]]; then
if ! [[ ${PHP_VERSION} =~ ^(8.2|8.3|8.4)$ ]]; then
INVALID_OPTIONS+=("p ${OPTARG}")
fi
;;
Expand Down
4 changes: 3 additions & 1 deletion Classes/Domain/Model/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace JWeiland\IndexNow\Domain\Model;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class Stack
{
public function __construct(
Expand All @@ -34,7 +36,7 @@ public function hasValidUrl(): bool
return false;
}

return filter_var($this->getUrl(), FILTER_VALIDATE_URL);
return GeneralUtility::isValidUrl($this->getUrl());
}

public function getHost(): string
Expand Down
52 changes: 36 additions & 16 deletions Classes/Domain/Repository/StackRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@
use Doctrine\DBAL\Exception;
use JWeiland\IndexNow\Domain\Model\Stack;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Repository to collect records from the table "tx_indexnow_stack"
*/
class StackRepository
{
private const TABLE_NAME = 'tx_indexnow_stack';
public const TABLE = 'tx_indexnow_stack';

public function __construct(
protected QueryBuilder $queryBuilder,
protected ConnectionPool $connectionPool,
) {}

/**
* @return Stack[]
*/
public function findAll(): array
{
$statement = $this->queryBuilder
$queryBuilder = $this->getQueryBuilder();

$statement = $queryBuilder
->select('uid', 'url')
->from(self::TABLE_NAME)
->from(self::TABLE)
->executeQuery();

$urlRecords = [];
Expand All @@ -46,20 +51,22 @@ public function findAll(): array
(string)$urlRecord['url'],
);
}
} catch (Exception $e) {
} catch (Exception) {
}

return $urlRecords;
}

public function deleteByUid(int $uid): void
{
$this->queryBuilder
->delete(self::TABLE_NAME)
$queryBuilder = $this->getQueryBuilder();

$queryBuilder
->delete(self::TABLE)
->where(
$this->queryBuilder->expr()->eq(
$queryBuilder->expr()->eq(
'uid',
$this->queryBuilder->createNamedParameter($uid, Connection::PARAM_INT),
$queryBuilder->createNamedParameter($uid, Connection::PARAM_INT),
),
)
->executeStatement();
Expand All @@ -70,8 +77,9 @@ public function insert(string $url): void
if (!$this->hasUrl($url)) {
$now = time();

$this->queryBuilder
->insert(self::TABLE_NAME)
$queryBuilder = $this->getQueryBuilder();
$queryBuilder
->insert(self::TABLE)
->values([
'url' => $url,
'tstamp' => $now,
Expand All @@ -85,18 +93,19 @@ public function insert(string $url): void
public function hasUrl(string $url): bool
{
try {
$existing = $this->queryBuilder
$queryBuilder = $this->getQueryBuilder();
$existing = $queryBuilder
->select('url_hash')
->from(self::TABLE_NAME)
->from(self::TABLE)
->where(
$this->queryBuilder->expr()->eq(
$queryBuilder->expr()->eq(
'url_hash',
$this->queryBuilder->createNamedParameter($this->hash($url)),
$queryBuilder->createNamedParameter($this->hash($url)),
),
)
->executeQuery()
->fetchOne();
} catch (Exception $e) {
} catch (Exception) {
// Return "true" here to prevent the insertion of new records if an exception is thrown during the query execution.
return true;
}
Expand All @@ -108,4 +117,15 @@ private function hash(string $url): string
{
return sha1($url);
}

protected function getQueryBuilder(): QueryBuilder
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE);
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));

return $queryBuilder;
}
}
8 changes: 3 additions & 5 deletions Classes/Hook/DataHandlerHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use JWeiland\IndexNow\Domain\Repository\StackRepository;
use JWeiland\IndexNow\Event\ModifyPageUidEvent;
use JWeiland\IndexNow\Notifier\SingleNotificationTrait;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\PreviewUriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
Expand All @@ -32,8 +32,6 @@
*/
class DataHandlerHook
{
use SingleNotificationTrait;

public function __construct(
protected StackRepository $stackRepository,
protected PageRenderer $pageRenderer,
Expand All @@ -55,7 +53,7 @@ public function processDatamap_beforeStart(DataHandler $dataHandler): void

// if the table is pages, we need to get sys_language_uid form $request object
if ($table === 'pages') {
if (isset($GLOBALS['TYPO3_REQUEST']) && $GLOBALS['TYPO3_REQUEST'] instanceof \Psr\Http\Message\ServerRequestInterface) {
if (isset($GLOBALS['TYPO3_REQUEST']) && $GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
$queryParams = $GLOBALS['TYPO3_REQUEST']->getQueryParams();
if (isset($queryParams['overrideVals']['pages']['sys_language_uid'])) {
$sysLanguageUid = (int)$queryParams['overrideVals']['pages']['sys_language_uid'];
Expand Down Expand Up @@ -142,7 +140,7 @@ protected function getPreviewUrl(int $pageUid, int $sysLanguageUid = 0): ?string

/**
* If NEW, $recordFromRequest will contain nearly all fields.
* If updated, $recordFromRequest will only contain modified fields. PID f.e. is missing.
* If updated, $recordFromRequest will only contain modified fields. PID f.e. Is missing.
* Use this method to get a merged record (DB and Request).
*/
protected function getMergedRecord(int|string $uid, string $table, array $recordFromRequest): array
Expand Down
4 changes: 2 additions & 2 deletions Classes/Notifier/SearchEngineNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class SearchEngineNotifier

public function __construct(
protected RequestFactory $requestFactory,
protected LoggerInterface $logger,
protected ExtConf $extConf,
protected LoggerInterface $logger,
) {}

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ protected function getUrlForSingleNotification(Stack $stack): string
$uri = $uri->withQuery(HttpUtility::buildQueryString([
'url' => $stack->getUrl(),
'key' => $this->extConf->getApiKey(),
], '&'));
]));
} catch (ApiKeyNotAvailableException) {
return '';
}
Expand Down
12 changes: 0 additions & 12 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ services:
JWeiland\IndexNow\Hook\DataHandlerHook:
public: true

querybuilder.tx_indexnow_stack:
class: 'TYPO3\CMS\Core\Database\Query\QueryBuilder'
factory:
- '@TYPO3\CMS\Core\Database\ConnectionPool'
- 'getQueryBuilderForTable'
arguments:
- 'tx_indexnow_stack'

JWeiland\IndexNow\Domain\Repository\StackRepository:
arguments:
$queryBuilder: '@querybuilder.tx_indexnow_stack'

JWeiland\IndexNow\EventListener\RespectPagesWithNoIndexEventListener:
tags:
- name: event.listener
Expand Down
Loading