• 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/MigratePremiumFocusKeywords.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Updates;
6

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

15
#[UpgradeWizard('yoastPremiumFocusKeywordsMigrate')]
16
class MigratePremiumFocusKeywords implements UpgradeWizardInterface
17
{
18
    protected const PREMIUM_TABLE = 'tx_yoast_seo_premium_focus_keywords';
19
    protected const NEW_TABLE = 'tx_yoastseo_related_focuskeyword';
20

21
    protected ConnectionPool $connectionPool;
22

23
    public function __construct()
24
    {
25
        $this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
×
26
    }
27

28
    public function getIdentifier(): string
29
    {
30
        return 'yoastPremiumFocusKeywordsMigrate';
×
31
    }
32

33
    public function getTitle(): string
34
    {
35
        return 'Yoast SEO for TYPO3 - Migrate premium focus keywords';
×
36
    }
37

38
    public function getDescription(): string
39
    {
40
        return 'Migrate focus keywords from the premium extension';
×
41
    }
42

43
    public function executeUpdate(): bool
44
    {
45
        $premiumFocusKeywords = $this->getPremiumFocusKeywords();
×
46
        $relatedTableColumns = $this->getRelatedTableColumns();
×
47
        foreach ($premiumFocusKeywords as $premiumFocusKeyword) {
×
48
            $premiumFocusKeyword['uid_foreign'] = $premiumFocusKeyword['parentid'];
×
49
            $premiumFocusKeyword['tablenames'] = $premiumFocusKeyword['parenttable'];
×
50
            unset(
×
51
                $premiumFocusKeyword['uid'],
×
52
                $premiumFocusKeyword['parentid'],
×
53
                $premiumFocusKeyword['parenttable']
×
54
            );
×
55
            $this->connectionPool->getConnectionForTable(self::NEW_TABLE)
×
56
                ->insert(
×
57
                    self::NEW_TABLE,
×
58
                    array_intersect_key($premiumFocusKeyword, $relatedTableColumns)
×
59
                );
×
60
        }
61

62
        $this->connectionPool->getConnectionForTable('pages')
×
63
            ->executeQuery(
×
64
                'UPDATE pages SET tx_yoastseo_focuskeyword_related = tx_yoastseo_focuskeyword_premium'
×
65
            );
×
66

67
        return true;
×
68
    }
69

70
    protected function getPremiumFocusKeywords(): array
71
    {
72
        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::PREMIUM_TABLE);
×
73
        $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
×
74
        return $queryBuilder
×
75
            ->select('*')
×
76
            ->from(self::PREMIUM_TABLE)
×
77
            ->executeQuery()
×
78
            ->fetchAllAssociative();
×
79
    }
80

81
    protected function getRelatedTableColumns(): array
82
    {
83
        $connection = $this->connectionPool->getConnectionForTable(self::NEW_TABLE);
×
84
        if (method_exists($connection, 'getSchemaManager')) {
×
85
            $schemaManager = $connection->getSchemaManager();
×
86
        } else {
87
            $schemaManager = $connection->createSchemaManager();
×
88
        }
89
        $columns = $schemaManager->listTableColumns(self::NEW_TABLE);
×
90
        return array_flip(array_keys($columns));
×
91
    }
92

93
    protected function premiumTableExists(): bool
94
    {
95
        try {
96
            $connection = $this->connectionPool->getConnectionForTable(self::PREMIUM_TABLE);
×
97
            if (method_exists($connection, 'getSchemaManager')) {
×
98
                $schemaManager = $connection->getSchemaManager();
×
99
            } else {
100
                $schemaManager = $connection->createSchemaManager();
×
101
            }
102
            return $schemaManager->tablesExist([self::PREMIUM_TABLE]);
×
103
        } catch (Exception $e) {
×
104
            return false;
×
105
        }
106
    }
107

108
    public function updateNecessary(): bool
109
    {
110
        return $this->premiumTableExists();
×
111
    }
112

113
    public function getPrerequisites(): array
114
    {
115
        return [
×
NEW
116
            DatabaseUpdatedPrerequisite::class,
×
117
        ];
×
118
    }
119
}
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