RedirectIntegrityCheckEvent 

New in version 14.2

The PSR-14 event \TYPO3\CMS\Redirects\Event\RedirectIntegrityCheckEvent is dispatched for each redirect record during integrity checks, allowing extensions to validate redirect targets (such as t3://record links) and flag broken or invalid redirects. It is dispatched in \TYPO3\CMS\Redirects\Service\IntegrityService->checkRedirectTargetIntegrity() for each redirect record.

Additionally, the following class constants allow the shared reuse of conflict statuses that extensions developers can set in custom event listeners: RedirectConflict::INVALID_TARGET , RedirectConflict::NO_CONFLICT and RedirectConflict::SELF_REFERENCE .

Extensions can now validate redirects during an integrity check by listening to this event. Broken or invalid redirects are reported as well as self-reference conflicts in the redirects:checkintegrity command output.

Example: Check that a record link target exists 

An event listener that validates t3://record targets:

EXT:my_extension/Classes/Redirects/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Redirects\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Redirects\Event\RedirectIntegrityCheckEvent;
use TYPO3\CMS\Redirects\Utility\RedirectConflict;

final readonly class MyEventListener
{
  public function __construct(
    private ConnectionPool $connectionPool,
  ) {}

  #[AsEventListener('my-extension/validate-redirect-target')]
  public function __invoke(RedirectIntegrityCheckEvent $event): void
  {
    $target = $event->getTarget();
    if (!str_starts_with($target, 't3://record')) {
      return;
    }
    // Parse t3://record?identifier=tx_news&uid=456
    parse_str((string)parse_url($target, PHP_URL_QUERY), $params);
    $table = $params['identifier'] ?? '';
    $uid = (int)($params['uid'] ?? 0);
    if ($table === '' || $uid === 0) {
      $event->setIntegrityStatus(RedirectConflict::INVALID_TARGET);
      return;
    }
    $count = $this->connectionPool
        ->getConnectionForTable($table)
        ->count('uid', $table, ['uid' => $uid]);
    if ($count === 0) {
      $event->setIntegrityStatus(RedirectConflict::INVALID_TARGET);
      return;
    }
    // Set to NO_CONFLICT - will not be reported as conflicting redirect
    // but will clear out already other integrity status.
    $event->setIntegrityStatus(RedirectConflict::NO_CONFLICT);
  }
}
Copied!

API 

final class RedirectIntegrityCheckEvent
Fully qualified name
\TYPO3\CMS\Redirects\Event\RedirectIntegrityCheckEvent

This event is fired in \TYPO3\CMS\Redirects\Service\IntegrityService->checkRedirectTargetIntegrity() for each redirect record.

It can be used to perform custom validation on redirect targets and flag broken or invalid targets.

getRedirect()
Returns
array<string,string|int|float|null>
getUid()
Returns
int
getPid()
Returns
int
getDeleted()
Returns
bool
getDisabled()
Returns
bool
getSourceHost()
Returns
string
getSourcePath()
Returns
string
getIsRegExp()
Returns
bool
getProtected()
Returns
bool
getForceHttps()
Returns
bool
getRespectQueryParameters()
Returns
bool
getKeepQueryParameters()
Returns
bool
getTarget()
Returns
string
getTargetStatusCode()
Returns
int
getCreationType()
Returns
int
getOriginalIntegrityStatus()
Returns
string
getIntegrityStatus()

Be aware that this has been possible set by another earlier PSR-14 event listener already.

Could be any of the \TYPO3\CMS\Redirects\Event\RedirectConflict constants, a custom value or NULL. In case of NULL no further handlinge are processed or regonized as conflict during the integrity checks.

This is not initialized with the sys_redirect.integirty_status value.

Returns
?string
setIntegrityStatus(?string $integrityStatus)

Set the integrity status, could be one of the RedirectConflict constants, a custom value or NULL.

In case of NULL no further handlinge are processed or regonized as conflict during the integrity checks.

param $integrityStatus

the integrityStatus