‪TYPO3CMS  ‪main
PagesWithoutDescriptionDataProvider.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\Result;
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
28 
33 {
34  public function ‪__construct(
35  private readonly ‪SiteFinder $siteFinder,
36  private readonly ‪ConnectionPool $connectionPool,
37  private readonly array $excludedDoktypes,
38  private readonly int $limit
39  ) {}
40 
41  public function ‪getPages(): array
42  {
43  $backendUser = $this->‪getBackendUser();
44  $items = [];
45  if (!$backendUser->check('tables_modify', 'pages')) {
46  // Early return in case user is not allowed to modify pages at all
47  return $items;
48  }
49  $rowCount = 0;
50  $pagesResult = $this->‪getPotentialPages();
51  while ($row = $pagesResult->fetchAssociative()) {
52  if (!$backendUser->doesUserHaveAccess($row, ‪Permission::PAGE_EDIT)) {
53  continue;
54  }
55  BackendUtility::workspaceOL('pages', $row, $backendUser->workspace);
56  $pageId = $row['l10n_parent'] ?: $row['uid'];
57  try {
58  $site = $this->siteFinder->getSiteByPageId($pageId);
59  // make sure the language of the row actually exists in the site
60  $site->getLanguageById($row['sys_language_uid']);
61  } catch (‪SiteNotFoundException | \InvalidArgumentException) {
62  continue;
63  }
64  $router = $site->getRouter();
65  $row['frontendUrl'] = (string)$router->generateUri($pageId, ['_language' => $row['sys_language_uid']]);
66  $items[] = $row;
67  $rowCount++;
68  if ($rowCount >= $this->limit) {
69  return $items;
70  }
71  }
72  return $items;
73  }
74 
82  private function ‪getPotentialPages(): Result
83  {
84  $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
85  $queryBuilder->getRestrictions()->add(new ‪WorkspaceRestriction($this->‪getBackendUser()->workspace));
86  return $queryBuilder
87  ->select('uid', 'pid', 'title', 'slug', 'sys_language_uid', 'l10n_parent', 'perms_userid', 'perms_groupid', 'perms_user', 'perms_group', 'perms_everybody')
88  ->from('pages')
89  ->where(
90  $queryBuilder->expr()->notIn('doktype', $this->excludedDoktypes),
91  $queryBuilder->expr()->and(
92  $queryBuilder->expr()->eq('no_index', $queryBuilder->createNamedParameter(0)),
93  $queryBuilder->expr()->eq('canonical_link', $queryBuilder->createNamedParameter('')),
94  ),
95  $queryBuilder->expr()->or(
96  $queryBuilder->expr()->eq('description', $queryBuilder->createNamedParameter('')),
97  $queryBuilder->expr()->isNull('description')
98  ),
99  )
100  ->orderBy('tstamp', 'DESC')
101  ->executeQuery();
102  }
103 
105  {
106  return ‪$GLOBALS['BE_USER'];
107  }
108 }
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:25
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Seo\Widgets\Provider
Definition: PagesWithoutDescriptionDataProvider.php:18
‪TYPO3\CMS\Seo\Widgets\Provider\PagesWithoutDescriptionDataProvider\getBackendUser
‪getBackendUser()
Definition: PagesWithoutDescriptionDataProvider.php:104
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Seo\Widgets\Provider\PagesWithoutDescriptionDataProvider
Definition: PagesWithoutDescriptionDataProvider.php:33
‪TYPO3\CMS\Seo\Widgets\Provider\PagesWithoutDescriptionDataProvider\getPotentialPages
‪getPotentialPages()
Definition: PagesWithoutDescriptionDataProvider.php:82
‪TYPO3\CMS\Seo\Widgets\Provider\PagesWithoutDescriptionDataProvider\getPages
‪getPages()
Definition: PagesWithoutDescriptionDataProvider.php:41
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Seo\Widgets\Provider\PagesWithoutDescriptionDataProvider\__construct
‪__construct(private readonly SiteFinder $siteFinder, private readonly ConnectionPool $connectionPool, private readonly array $excludedDoktypes, private readonly int $limit)
Definition: PagesWithoutDescriptionDataProvider.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:40
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:39