‪TYPO3CMS  ‪main
ResolutionRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\Exception\TableNotFoundException;
24 
29 {
30  protected const ‪TABLE_NAME = 'sys_csp_resolution';
31 
32  public function ‪__construct(protected readonly ‪ConnectionPool $pool) {}
33 
37  public function ‪findAll(): array
38  {
39  $result = $this->‪getConnection()->select(
40  ['*'],
41  self::TABLE_NAME,
42  [],
43  [],
44  ['created' => 'asc']
45  );
46  return array_map(
47  static fn(array $row) => ‪Resolution::fromArray($row),
48  $result->fetchAllAssociative()
49  );
50  }
51 
55  public function ‪findByScope(‪Scope $scope): array
56  {
57  try {
58  $result = $this->‪getConnection()->select(
59  ['*'],
60  self::TABLE_NAME,
61  ['scope' => (string)$scope],
62  [],
63  ['created' => 'asc']
64  );
65  } catch (TableNotFoundException) {
66  // We usually don't take care of non-existing table throughout the system.
67  // This one however can happen when major upgrading TYPO3 and calling the
68  // backend first time. It is fair to catch this case to prevent forcing admins
69  // to unlock standalone install tool or to use cli to fix db schema.
70  return [];
71  }
72  return array_map(
73  static fn(array $row) => ‪Resolution::fromArray($row),
74  $result->fetchAllAssociative()
75  );
76  }
77 
78  public function ‪findBySummary(string $summary): ?‪Resolution
79  {
80  if ($summary === '') {
81  return null;
82  }
83  $result = $this->‪getConnection()->select(
84  ['*'],
85  self::TABLE_NAME,
86  ['summary' => $summary]
87  );
88  $row = $result->fetchAssociative();
89  if (empty($row)) {
90  return null;
91  }
92  return ‪Resolution::fromArray($row);
93  }
94 
98  public function ‪findByIdentifier(string ‪$identifier, bool $prefix = false): array
99  {
100  if (‪$identifier === '') {
101  return [];
102  }
103  if ($prefix) {
104  $queryBuilder = $this->pool->getQueryBuilderForTable(self::TABLE_NAME);
105  $result = $queryBuilder
106  ->select('*')
107  ->from(self::TABLE_NAME)
108  ->where($queryBuilder->expr()->like(
109  'mutation_identifier',
110  $queryBuilder->createNamedParameter($queryBuilder->escapeLikeWildcards(‪$identifier) . '%')
111  ))
112  ->executeQuery();
113  } else {
114  $result = $this->‪getConnection()->select(
115  ['*'],
116  self::TABLE_NAME,
117  ['mutation_identifier' => ‪$identifier]
118  );
119  }
120  return array_map(
121  static fn(array $row) => ‪Resolution::fromArray($row),
122  $result->fetchAllAssociative()
123  );
124  }
125 
126  public function ‪add(‪Resolution $resolution): bool
127  {
128  return $this->‪getConnection()->insert(
129  self::TABLE_NAME,
130  $resolution->‪toArray()
131  ) === 1;
132  }
133 
134  public function remove(string $summary): bool
135  {
136  return $this->‪getConnection()->delete(
137  self::TABLE_NAME,
138  ['summary' => $summary]
139  ) === 1;
140  }
141 
142  protected function ‪getConnection(): ‪Connection
143  {
144  return $this->pool->getConnectionForTable(self::TABLE_NAME);
145  }
146 }
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\__construct
‪__construct(protected readonly ConnectionPool $pool)
Definition: ResolutionRepository.php:32
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\add
‪add(Resolution $resolution)
Definition: ResolutionRepository.php:126
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\TABLE_NAME
‪const TABLE_NAME
Definition: ResolutionRepository.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\findByScope
‪list< Resolution > findByScope(Scope $scope)
Definition: ResolutionRepository.php:55
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\toArray
‪toArray()
Definition: Resolution.php:79
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\findAll
‪list< Resolution > findAll()
Definition: ResolutionRepository.php:37
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Scope
Definition: Scope.php:30
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting
Definition: Report.php:18
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\findByIdentifier
‪list< Resolution > findByIdentifier(string $identifier, bool $prefix=false)
Definition: ResolutionRepository.php:98
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution
Definition: Resolution.php:29
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\getConnection
‪getConnection()
Definition: ResolutionRepository.php:142
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\Resolution\fromArray
‪static fromArray(array $array)
Definition: Resolution.php:32
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository
Definition: ResolutionRepository.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ResolutionRepository\findBySummary
‪findBySummary(string $summary)
Definition: ResolutionRepository.php:78
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37