‪TYPO3CMS  10.4
RedirectCacheService.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 
25 
33 {
37  protected ‪$cache;
38 
44  public function ‪__construct(‪CacheManager $cacheManager = null)
45  {
46  $cacheManager = $cacheManager ?? GeneralUtility::makeInstance(CacheManager::class);
47  $this->cache = $cacheManager->getCache('pages');
48  }
49 
55  public function ‪getRedirects(): array
56  {
57  $redirects = $this->cache->get('redirects');
58  if (!is_array($redirects)) {
59  $redirects = $this->‪rebuild();
60  }
61  return $redirects;
62  }
63 
68  public function ‪rebuild(): array
69  {
70  $redirects = [];
71  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_redirect');
72  $queryBuilder->getRestrictions()->removeAll()
73  ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
74  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
75  $statement = $queryBuilder
76  ->select('*')
77  ->from('sys_redirect')
78  ->execute();
79  while ($row = $statement->fetch()) {
80  $host = $row['source_host'] ?: '*';
81  if ($row['is_regexp']) {
82  $redirects[$host]['regexp'][$row['source_path']][$row['uid']] = $row;
83  } elseif ($row['respect_query_parameters']) {
84  $redirects[$host]['respect_query_parameters'][$row['source_path']][$row['uid']] = $row;
85  } else {
86  $redirects[$host]['flat'][rtrim($row['source_path'], '/') . '/'][$row['uid']] = $row;
87  }
88  }
89  $this->cache->set('redirects', $redirects);
90  return $redirects;
91  }
92 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\getRedirects
‪array getRedirects()
Definition: RedirectCacheService.php:54
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\$cache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cache
Definition: RedirectCacheService.php:36
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\__construct
‪__construct(CacheManager $cacheManager=null)
Definition: RedirectCacheService.php:43
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:33
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Redirects\Service
Definition: IntegrityService.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\rebuild
‪rebuild()
Definition: RedirectCacheService.php:67