• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / Yoast-SEO-for-TYPO3 / 13327579701

14 Feb 2025 10:43AM UTC coverage: 1.276%. First build
13327579701

push

github

web-flow
Merge pull request #597 from Yoast/feature/v11

[FEATURE] Release 11.0.0

21 of 894 new or added lines in 76 files covered. (2.35%)

35 of 2744 relevant lines covered (1.28%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/Updates/MigrateRedirects.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Updates;
6

7
use Doctrine\DBAL\Exception\TableNotFoundException;
8
use TYPO3\CMS\Core\Database\ConnectionPool;
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
use TYPO3\CMS\Core\Utility\MathUtility;
11
use TYPO3\CMS\Install\Attribute\UpgradeWizard;
12
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
13
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
14

15
#[UpgradeWizard('yoastRedirectsMigrate')]
16
class MigrateRedirects implements UpgradeWizardInterface
17
{
18
    protected const PAGE_LINK_PROTOCOL = 't3://page?uid=';
19

20
    public function getIdentifier(): string
21
    {
22
        return 'yoastRedirectsMigrate';
×
23
    }
24

25
    public function getTitle(): string
26
    {
27
        return 'Yoast SEO for TYPO3 - Migrate premium redirects';
×
28
    }
29

30
    public function getDescription(): string
31
    {
32
        return 'Migrate redirects from the old Yoast Premium redirects module to sys_redirect';
×
33
    }
34

35
    public function executeUpdate(): bool
36
    {
37
        $domains = $this->getDomains();
×
38
        $redirects = $this->getRedirects();
×
39
        foreach ($redirects as $redirect) {
×
40
            if (empty($redirect['old_host']) || $redirect['old_host'] === '*') {
×
41
                $sourceHost = '*';
×
42
            } else {
43
                $sourceHost = $domains[$redirect['old_host']] ?? '*';
×
44
            }
45

46
            if (MathUtility::canBeInterpretedAsInteger(
×
47
                $redirectPage = str_replace(self::PAGE_LINK_PROTOCOL, '', $redirect['new_url'])
×
48
            )) {
×
49
                $redirect['new_url'] = self::PAGE_LINK_PROTOCOL . $redirectPage;
×
50
                if ((int)$redirect['sys_language_uid'] > 0) {
×
51
                    $redirect['new_url'] .= '&L=' . (int)$redirect['sys_language_uid'];
×
52
                }
53
            }
54

55
            $sysRedirect = [
×
56
                'createdby' => $redirect['createdby'],
×
57
                'createdon' => $redirect['createdon'],
×
58
                'updatedon' => $redirect['updatedon'],
×
59
                'deleted' => $redirect['deleted'],
×
60
                'disabled' => $redirect['disabled'],
×
61
                'starttime' => $redirect['starttime'],
×
62
                'endtime' => $redirect['endtime'],
×
63

64
                'source_host' => $sourceHost,
×
65
                'source_path' => $redirect['old_url'],
×
66
                'is_regexp' => $redirect['is_regexp'],
×
67

68
                'force_https' => $redirect['force_https'],
×
69
                'keep_query_parameters' => $redirect['keep_query_parameters'],
×
70
                'target' => $redirect['new_url'],
×
71
                'target_statuscode' => $redirect['new_url_statuscode'],
×
72
            ];
×
73
            GeneralUtility::makeInstance(ConnectionPool::class)
×
74
                ->getConnectionForTable('sys_redirect')
×
75
                ->insert('sys_redirect', $sysRedirect);
×
76
        }
77
        return true;
×
78
    }
79

80
    public function updateNecessary(): bool
81
    {
82
        return count($this->getRedirects()) > 0;
×
83
    }
84

85
    protected function getDomains(): array
86
    {
87
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
×
88
            ->getQueryBuilderForTable('sys_domain');
×
89
        $queryBuilder->getRestrictions()->removeAll();
×
90

91
        try {
92
            $domains = $queryBuilder->select('*')
×
93
                ->from('sys_domain')
×
94
                ->executeQuery()->fetchAllAssociative();
×
95
        } catch (TableNotFoundException $e) {
×
96
            return [];
×
97
        }
98

99
        $domainArray = [];
×
100
        foreach ($domains as $domain) {
×
101
            $domainArray[$domain['uid']] = $domain['domainName'];
×
102
        }
103
        return $domainArray;
×
104
    }
105

106
    protected function getRedirects(): array
107
    {
108
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
×
109
            ->getQueryBuilderForTable('tx_yoast_seo_premium_redirect');
×
110
        $queryBuilder->getRestrictions()->removeAll();
×
111

112
        try {
113
            return $queryBuilder->select('*')
×
114
                ->from('tx_yoast_seo_premium_redirect')
×
115
                ->where(
×
116
                    $queryBuilder->expr()->eq('deleted', 0)
×
117
                )
×
118
                ->executeQuery()
×
119
                ->fetchAllAssociative();
×
120
        } catch (TableNotFoundException $e) {
×
121
            return [];
×
122
        }
123
    }
124

125
    public function getPrerequisites(): array
126
    {
127
        return [
×
NEW
128
            DatabaseUpdatedPrerequisite::class,
×
129
        ];
×
130
    }
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc