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

Yoast / Yoast-SEO-for-TYPO3 / 27939073002

22 Jun 2026 08:16AM UTC coverage: 21.137%. Remained the same
27939073002

push

github

RinyVT
Merge branch 'main' of github.com:Yoast/Yoast-SEO-for-TYPO3

4 of 5 new or added lines in 1 file covered. (80.0%)

3 existing lines in 1 file now uncovered.

580 of 2744 relevant lines covered (21.14%)

0.75 hits per line

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

79.17
/Classes/Service/SaveScoresService.php
1
<?php
2

3
/**
4
 * This file is part of the "yoast_seo" extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
namespace YoastSeoForTypo3\YoastSeo\Service;
13

14
use Doctrine\DBAL\Exception;
15
use TYPO3\CMS\Core\Database\Connection;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
18
use YoastSeoForTypo3\YoastSeo\Constants\TableNames;
19

20
class SaveScoresService
21
{
22
    public function __construct(
23
        protected ConnectionPool $connectionPool
24
    ) {}
4✔
25

26
    /**
27
     * @param array<string, string> $data
28
     */
29
    public function save(array $data): void
30
    {
31
        try {
32
            $record = $this->getRecord($data);
4✔
33
        } catch (\Exception) {
×
34
            return;
×
35
        }
36

37
        if ($record === null || !isset($data['readabilityScore'], $data['seoScore'])) {
4✔
38
            return;
2✔
39
        }
40

41
        $connection = $this->connectionPool->getConnectionForTable($data['table']);
2✔
42
        if (!$this->columnsExist($connection, $data['table'])) {
2✔
NEW
43
            return;
×
44
        }
45
        $connection->update($data['table'], [
2✔
46
            'tx_yoastseo_score_readability' => (string)$data['readabilityScore'],
2✔
47
            'tx_yoastseo_score_seo' => (string)$data['seoScore'],
2✔
48
        ], ['uid' => (int)$record['uid']]);
2✔
49
    }
50

51
    /**
52
     * @param array<string, string> $data
53
     * @return array<string, int|string>|null
54
     * @throws Exception
55
     */
56
    protected function getRecord(array $data): ?array
57
    {
58
        if ($data['table'] === TableNames::PAGES) {
4✔
59
            return $this->getPageRecord((int)$data['uid'], (int)($data['languageId'] ?? 0));
4✔
60
        }
61

UNCOV
62
        $connection = $this->connectionPool->getConnectionForTable($data['table']);
×
UNCOV
63
        $record = $connection->select(
×
UNCOV
64
            ['uid'],
×
65
            $data['table'],
×
66
            ['uid' => (int)$data['uid']],
×
67
        )->fetchAssociative();
×
68
        return $record === false ? null : $record;
×
69
    }
70

71
    /**
72
     * @return array<string, int|string>|null
73
     * @throws Exception
74
     */
75
    protected function getPageRecord(int $pageUid, int $languageId): ?array
76
    {
77
        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(TableNames::PAGES);
4✔
78
        $queryBuilder->getRestrictions()->removeAll()->add(new DeletedRestriction());
4✔
79
        $queryBuilder->select('uid', 'tx_yoastseo_disable_analysis')->from(TableNames::PAGES);
4✔
80
        if ($languageId > 0) {
4✔
81
            $queryBuilder->where(
1✔
82
                $queryBuilder->expr()->and(
1✔
83
                    $queryBuilder->expr()->eq(
1✔
84
                        $GLOBALS['TCA'][TableNames::PAGES]['ctrl']['transOrigPointerField'],
1✔
85
                        $queryBuilder->createNamedParameter($pageUid, Connection::PARAM_INT)
1✔
86
                    ),
1✔
87
                    $queryBuilder->expr()->eq(
1✔
88
                        $GLOBALS['TCA'][TableNames::PAGES]['ctrl']['languageField'],
1✔
89
                        $queryBuilder->createNamedParameter($languageId, Connection::PARAM_INT)
1✔
90
                    ),
1✔
91
                    $queryBuilder->expr()->eq('tx_yoastseo_disable_analysis', 0),
1✔
92
                )
1✔
93
            );
1✔
94
        } else {
95
            $queryBuilder->where(
3✔
96
                $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pageUid, Connection::PARAM_INT)),
3✔
97
                $queryBuilder->expr()->eq('tx_yoastseo_disable_analysis', 0),
3✔
98
            );
3✔
99
        }
100
        $record = $queryBuilder->executeQuery()->fetchAssociative();
4✔
101
        return $record === false ? null : $record;
4✔
102
    }
103

104
    protected function columnsExist(Connection $connection, string $table): bool
105
    {
106
        $schemaManager = $connection->createSchemaManager();
2✔
107
        $columns = $schemaManager->listTableColumns($table);
2✔
108
        return isset($columns['tx_yoastseo_score_readability'], $columns['tx_yoastseo_score_seo']);
2✔
109
    }
110
}
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