‪TYPO3CMS  9.5
RedirectCacheService.php
Go to the documentation of this file.
1 <?php
2 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 
23 
31 {
35  protected ‪$cache;
36 
42  public function ‪__construct(‪CacheManager $cacheManager = null)
43  {
44  $cacheManager = $cacheManager ?? GeneralUtility::makeInstance(CacheManager::class);
45  $this->cache = $cacheManager->getCache('cache_pages');
46  }
47 
53  public function ‪getRedirects(): array
54  {
55  $redirects = $this->cache->get('redirects');
56  if (!is_array($redirects)) {
57  $redirects = $this->‪rebuild();
58  }
59  return $redirects;
60  }
61 
66  public function ‪rebuild(): array
67  {
68  $redirects = [];
69  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_redirect');
70  $queryBuilder->getRestrictions()->removeAll()
71  ->add(GeneralUtility::makeInstance(HiddenRestriction::class))
72  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
73  $statement = $queryBuilder
74  ->select('*')
75  ->from('sys_redirect')
76  ->execute();
77  while ($row = $statement->fetch()) {
78  $host = $row['source_host'] ?: '*';
79  if ($row['is_regexp']) {
80  $redirects[$host]['regexp'][$row['source_path']][$row['uid']] = $row;
81  } elseif ($row['respect_query_parameters']) {
82  $redirects[$host]['respect_query_parameters'][$row['source_path']][$row['uid']] = $row;
83  } else {
84  $redirects[$host]['flat'][rtrim($row['source_path'], '/') . '/'][$row['uid']] = $row;
85  }
86  }
87  $this->cache->set('redirects', $redirects);
88  return $redirects;
89  }
90 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:25
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\getRedirects
‪array getRedirects()
Definition: RedirectCacheService.php:52
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\$cache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cache
Definition: RedirectCacheService.php:34
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\__construct
‪__construct(CacheManager $cacheManager=null)
Definition: RedirectCacheService.php:41
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:31
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Redirects\Service
Definition: RedirectCacheService.php:3
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Redirects\Service\RedirectCacheService\rebuild
‪rebuild()
Definition: RedirectCacheService.php:65