Migration von realurl Pfaden

Beim TYPO3 Update von TYPO3 v8 auf eine aktuellere Version müssen die Realurl-Pfade gegebenenfalls migriert werden. Insbesondere für News-Elemente war es sinnvoll eine 4-stellige Ziffer an die sprechende URL anzuhängen. Folgende Methode kann für die Abbildung dieser URLs in TYPO3 v9 und neuer verwendet werden.

realurl.conf (<= TYPO3 v8)

Früher wurden häufiger derartige realurl-Konfigurtionen für die News-Detailansicht verwendet.
Im alias_field finde die Verknüpfung von dem News-Titel mit dem uid+1432 statt, wobei die 1432 willkürlich gewählt ist. Der Grund dafür lag darin begründet, dass Google damals für News-Seiten eine 4-stellige eindeute Ziffer forderte.

...
'article' => array (
                array (
                        'GETvar' =>'tx_news_pi1[news]',
                        'lookUpTable' => array (
                                'table' => 'tx_news_domain_model_news',
                                'id_field' => 'uid',
                                'alias_field' => 'concat(title," ",(uid+1432))',
                                'addWhereClause' =>' AND NOT deleted',
                                'useUniqueCache' => 1,
                                'useUniqueCache_conf'=>
                                array (
                                  'strtolower' => 1,
                                  'spaceCharacter' => '-',
                                ),
                                'languageGetVar' => 'L',
                                'languageExceptionUids' => '',
                                'languageField' => 'sys_language_uid',
                                'transOrigPointerField' => 'l10n_parent',
                                'autoUpdate' => 1,
                                'expireDays' => 180,
                        ),
                ),
        ),
...

config.yaml (>= TYPO3 v9)

Möchte man die Pfade mit den 4-stelligen Ziffern am Ende beibehalten, kann folgende Vorgehensweise verwendet werden. Diese SQL-Anweisungen können beispielsweise direkt in phpmyadmin ausgeführt werden.

DROP FUNCTION IF EXISTS `cool_url`;
DELIMITER ;;
CREATE FUNCTION `cool_url` (`original` varchar(512) CHARSET utf8mb4 COLLATE utf8mb4_bin, `uidplus` int(11)) RETURNS varchar(512) CHARSET utf8mb4
BEGIN
    DECLARE translit VARCHAR(512) DEFAULT '';
    DECLARE len INT(3) DEFAULT 0;
    DECLARE pos INT(3) DEFAULT 1;
    DECLARE letter VARCHAR(2);
    SET original = TRIM(LOWER(original));
    SET uidplus = uidplus + 1432;
    SET len = CHAR_LENGTH(original);
    WHILE (pos <= len) DO
        # get one letter from original
        SET letter = SUBSTRING(original, pos, 1) COLLATE utf8mb4_bin;
CASE TRUE
    # basic chars
    WHEN letter IN ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9' COLLATE utf8mb4_bin) THEN SET letter = letter;
    # chars with diacritics and azbuka
    WHEN letter IN('á','à','â','å','ā','ą','ă' COLLATE utf8mb4_bin) THEN SET letter = 'a';
    WHEN letter IN('ä' COLLATE utf8mb4_bin) THEN SET letter = 'ae';
    WHEN letter IN('б' COLLATE utf8mb4_bin) THEN SET letter = 'b';
    WHEN letter IN('č','ć','ç','ć' COLLATE utf8mb4_bin) THEN SET letter = 'c';
    WHEN letter IN('ď','đ','д' COLLATE utf8mb4_bin) THEN SET letter = 'd';
    WHEN letter IN('é','ě','ë','ё','è','ê','ē','ę','ь','э','œ' COLLATE utf8mb4_bin) THEN SET letter = 'e';
    WHEN letter IN('ф','ѳ' COLLATE utf8mb4_bin) THEN SET letter = 'f';
    WHEN letter IN('ģ','ğ','г' COLLATE utf8mb4_bin) THEN SET letter = 'g';
    WHEN letter IN('í','î','ï','ī','î','і','и','й' COLLATE utf8mb4_bin) THEN SET letter = 'i';
    WHEN letter IN('ķ','к' COLLATE utf8mb4_bin) THEN SET letter = 'k';
    WHEN letter IN('ľ','ĺ','ļ','ł','л' COLLATE utf8mb4_bin) THEN SET letter = 'l';
    WHEN letter IN('м' COLLATE utf8mb4_bin) THEN SET letter = 'm';
    WHEN letter IN('ň','ņ','ń','ñ','н' COLLATE utf8mb4_bin) THEN SET letter = 'n';
    WHEN letter IN('ó','ø','õ','ô','ő','ơ','о' COLLATE utf8mb4_bin) THEN SET letter = 'o';
    WHEN letter IN('ö' COLLATE utf8mb4_bin) THEN SET letter = 'oe';
    WHEN letter IN('п' COLLATE utf8mb4_bin) THEN SET letter = 'p';
    WHEN letter IN('ŕ','ř','р' COLLATE utf8mb4_bin) THEN SET letter = 'r';
    WHEN letter IN('š','ś','ș','ş','с','ß' COLLATE utf8mb4_bin) THEN SET letter = 's';
    WHEN letter IN('ť','ț','т' COLLATE utf8mb4_bin) THEN SET letter = 't';
    WHEN letter IN('ú','ů','ù','û','ū','ű','ư','у' COLLATE utf8mb4_bin) THEN SET letter = 'u';
    WHEN letter IN('ü' COLLATE utf8mb4_bin) THEN SET letter = 'ue';
    WHEN letter IN('в' COLLATE utf8mb4_bin) THEN SET letter = 'v';
    WHEN letter IN('ý','ы','ѵ' COLLATE utf8mb4_bin) THEN SET letter = 'y';
    WHEN letter IN('ž','ź','ż','з' COLLATE utf8mb4_bin) THEN SET letter = 'z';
ELSE SET letter = '-';
END CASE;
        # joining new string
        SET translit = CONCAT(translit, letter);
        SET pos = pos + 1;
END WHILE;
    # replacing more dashes by one
    WHILE (translit REGEXP '\-{2,}') DO
        SET translit = REPLACE(translit, '--', '-');
END WHILE;
RETURN CONCAT(TRIM(BOTH '-' FROM translit),'-',uidplus);
#RETURN TRIM(BOTH '-' FROM translit);
END;;
DELIMITER ;
update tx_news_domain_model_news set path_segment = cool_url(title,uid);

Erstellt am: