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

fnagel / t3extblog / 32779998739

24 Aug 2026 09:26PM UTC coverage: 76.723% (-0.7%) from 77.395%
32779998739

push

github

fnagel
[FIX] WIP

2650 of 3454 relevant lines covered (76.72%)

7.96 hits per line

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

97.44
/Classes/Domain/Repository/AbstractRepository.php
1
<?php
2

3
namespace FelixNagel\T3extblog\Domain\Repository;
4

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

12
use Doctrine\DBAL\Platforms\SQLitePlatform;
13
use TYPO3\CMS\Core\Database\Connection;
14
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
15
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
16
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
17
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
18
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
19
use TYPO3\CMS\Extbase\Persistence\Repository;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3\CMS\Core\Database\ConnectionPool;
22

23
/**
24
 * AbstractRepository.
25
 */
26
abstract class AbstractRepository extends Repository
27
{
28
    public function createQuery(?int $pageUid = null): QueryInterface
110✔
29
    {
30
        $query = parent::createQuery();
110✔
31

32
        if ($pageUid !== null) {
110✔
33
            if ($pageUid >= 0) {
15✔
34
                $query->getQuerySettings()->setStoragePageIds([$pageUid]);
15✔
35
            } else {
36
                $query->getQuerySettings()->setRespectStoragePage(false);
×
37
            }
38
        }
39

40
        return $query;
110✔
41
    }
42

43
    public function getStoragePids(): array
1✔
44
    {
45
        return parent::createQuery()->getQuerySettings()->getStoragePageIds();
1✔
46
    }
47

48
    /**
49
     * Returns all objects with specific PID.
50
     */
51
    public function findByPage(
12✔
52
        ?int $pid = null,
53
        bool $respectEnableFields = true,
54
        ?int $limit = null
55
    ): QueryResultInterface {
56
        $query = $this->createQuery($pid);
12✔
57

58
        if (is_int($limit) && $limit >= 1) {
12✔
59
            $query->setLimit($limit);
1✔
60
        }
61

62
        if (!$respectEnableFields) {
12✔
63
            $query->getQuerySettings()->setIgnoreEnableFields(true);
4✔
64

65
            $query->matching(
4✔
66
                $query->equals('deleted', '0')
4✔
67
            );
4✔
68
        }
69

70
        return $query->execute();
12✔
71
    }
72

73
    protected function getFeEnableFields(string $table): string
3✔
74
    {
75
        $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
3✔
76
        $expressionBuilder = $this->getQueryBuilder($table)->expr();
3✔
77

78
        return $expressionBuilder->and(...$pageRepository->getDefaultConstraints($table));
3✔
79
    }
80

81
    protected function getTableName(?QueryInterface $query = null): string
40✔
82
    {
83
        if ($query === null) {
40✔
84
            $query = $this->createQuery();
40✔
85
        }
86

87
        return $this->getTableNameByClass($query->getType());
40✔
88
    }
89

90
    protected function getTableNameByClass(string $object): string
40✔
91
    {
92
        return GeneralUtility::makeInstance(DataMapper::class)->convertClassNameToTableName($object);
40✔
93
    }
94

95
    protected function escapeStrForLike(string $value, ?string $table = null): string
18✔
96
    {
97
        return $this->getQueryBuilder($table)->escapeLikeWildcards($value);
18✔
98
    }
99

100
    protected function getQueryBuilder(?string $table = null): QueryBuilder
40✔
101
    {
102
        if ($table === null) {
40✔
103
            $table = $this->getTableName();
18✔
104
        }
105

106
        return $this->getConnection($table)->createQueryBuilder();
40✔
107
    }
108

109
    protected function getConnection(string $table): Connection
40✔
110
    {
111
        return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
40✔
112
    }
113

114
    protected function isSQLite(string $table): bool
2✔
115
    {
116
        return $this->getConnection($table)->getDatabasePlatform() instanceof SQLitePlatform;
2✔
117
    }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc