[BUGFIX] Show Broken Links of Pages on the Page itself 09/61709/18
authorLina Wolf <112@linawolf.de>
Sun, 15 Sep 2019 12:10:50 +0000 (14:10 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Wed, 23 Oct 2019 08:42:52 +0000 (10:42 +0200)
Choose pages by uid and other records by pid to determine which ones
should be shown for a certain level in the Backend Info module.

Resolves: #52917
Releases: master, 9.5
Change-Id: I1760400ad290e090bdef00e2016c73fbea1e8b91
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61709
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Sybille Peters <sypets@gmx.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php

index cd392da..cbd1b9b 100644 (file)
@@ -73,13 +73,6 @@ class LinkAnalyzer
     protected $hookObjectsArr = [];
 
     /**
-     * Array with information about the current page
-     *
-     * @var array
-     */
-    protected $extPageInTreeInfo = [];
-
-    /**
      * Reference to the current element with table:uid, e.g. pages:85
      *
      * @var string
@@ -115,9 +108,9 @@ class LinkAnalyzer
     /**
      * Store all the needed configuration values in class variables
      *
-     * @param array  $searchField List of fields in which to search for links
-     * @param string $pidList     List of comma separated page uids in which to search for links
-     * @param array  $tsConfig    The currently active TSconfig.
+     * @param array $searchField List of fields in which to search for links
+     * @param string $pidList List of comma separated page uids in which to search for links
+     * @param array $tsConfig The currently active TSconfig.
      */
     public function init(array $searchField, $pidList, $tsConfig)
     {
@@ -147,18 +140,21 @@ class LinkAnalyzer
         $queryBuilder->delete('tx_linkvalidator_link')
             ->where(
                 $queryBuilder->expr()->orX(
-                    $queryBuilder->expr()->in(
-                        'record_pid',
-                        $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
-                    ),
                     $queryBuilder->expr()->andX(
                         $queryBuilder->expr()->in(
                             'record_uid',
                             $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
                         ),
-                        $queryBuilder->expr()->eq(
+                        $queryBuilder->expr()->eq('table_name', $queryBuilder->createNamedParameter('pages'))
+                    ),
+                    $queryBuilder->expr()->andX(
+                        $queryBuilder->expr()->in(
+                            'record_pid',
+                            $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
+                        ),
+                        $queryBuilder->expr()->neq(
                             'table_name',
-                            $queryBuilder->createNamedParameter('pages', \PDO::PARAM_STR)
+                            $queryBuilder->createNamedParameter('pages')
                         )
                     )
                 ),
@@ -449,9 +445,21 @@ class LinkAnalyzer
             ->addSelectLiteral($queryBuilder->expr()->count('uid', 'nbBrokenLinks'))
             ->from('tx_linkvalidator_link')
             ->where(
-                $queryBuilder->expr()->in(
-                    'record_pid',
-                    $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
+                $queryBuilder->expr()->orX(
+                    $queryBuilder->expr()->andX(
+                        $queryBuilder->expr()->in(
+                            'record_uid',
+                            $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
+                        ),
+                        $queryBuilder->expr()->eq('table_name', $queryBuilder->createNamedParameter('pages'))
+                    ),
+                    $queryBuilder->expr()->andX(
+                        $queryBuilder->expr()->in(
+                            'record_pid',
+                            $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
+                        ),
+                        $queryBuilder->expr()->neq('table_name', $queryBuilder->createNamedParameter('pages'))
+                    )
                 )
             )
             ->groupBy('link_type')
@@ -509,7 +517,6 @@ class LinkAnalyzer
         while ($row = $result->fetch()) {
             if ($begin <= 0 && ($row['hidden'] == 0 || $considerHidden)) {
                 $theList .= $row['uid'] . ',';
-                $this->extPageInTreeInfo[] = [$row['uid'], htmlspecialchars($row['title'], $depth)];
             }
             if ($depth > 1 && (!($row['hidden'] == 1 && $row['extendToSubpages'] == 1) || $considerHidden)) {
                 $theList .= $this->extGetTreeList(
@@ -532,13 +539,14 @@ class LinkAnalyzer
      */
     public function getRootLineIsHidden(array $pageInfo)
     {
+        if ($pageInfo['pid'] === 0) {
+            return false;
+        }
+
         if ($pageInfo['extendToSubpages'] == 1 && $pageInfo['hidden'] == 1) {
             return true;
         }
 
-        if ($pageInfo['pid'] === 0) {
-            return false;
-        }
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
         $queryBuilder->getRestrictions()->removeAll();
 
index adbbfd3..0efbf01 100644 (file)
@@ -21,6 +21,8 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Localization\LanguageService;
@@ -210,13 +212,13 @@ class LinkValidatorReport
                 } else {
                     $this->checkOpt[$prefix][$linkType] = '0';
                 }
-                $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] =  $this->checkOpt[$prefix][$linkType];
+                $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = $this->checkOpt[$prefix][$linkType];
             } elseif (isset($this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType])) {
                 $this->checkOpt[$prefix][$linkType] = $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType];
             } else {
                 // use default
                 $this->checkOpt[$prefix][$linkType] = '0';
-                $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] =  $this->checkOpt[$prefix][$linkType];
+                $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = $this->checkOpt[$prefix][$linkType];
             }
             if (isset($this->pObj->MOD_SETTINGS[$other . '_' . $linkType])) {
                 $this->checkOpt[$other][$linkType] = $this->pObj->MOD_SETTINGS[$other . '_' . $linkType];
@@ -331,16 +333,18 @@ class LinkValidatorReport
         }
         $rootLineHidden = $this->linkAnalyzer->getRootLineIsHidden($this->pObj->pageinfo);
         if (!$rootLineHidden || $this->modTS['checkhidden'] == 1) {
+            $permsClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
             // Get children pages
             $pageList = $this->linkAnalyzer->extGetTreeList(
                 $this->id,
                 $this->searchLevel['check'],
                 0,
-                $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW),
+                $permsClause,
                 $this->modTS['checkhidden']
             );
             if ($this->pObj->pageinfo['hidden'] == 0 || $this->modTS['checkhidden']) {
                 $pageList .= $this->id;
+                $pageList = $this->addPageTranslationsToPageList($pageList, $permsClause);
             }
 
             $this->linkAnalyzer->init($searchFields, $pageList, $this->modTS);
@@ -441,7 +445,7 @@ class LinkValidatorReport
 
         $rootLineHidden = $this->linkAnalyzer->getRootLineIsHidden($this->pObj->pageinfo);
         if (!$rootLineHidden || (bool)$this->modTS['checkhidden']) {
-            $pageList = $this->getPageList($this->id);
+            $pageList = $this->getPageList();
             $result = false;
             if (!empty($linkTypes)) {
                 $result = $this->getLinkValidatorBrokenLinks($pageList, $linkTypes);
@@ -485,20 +489,21 @@ class LinkValidatorReport
      * Generates an array of page uids from current pageUid.
      * List does include pageUid itself.
      *
-     * @param int $currentPageUid
      * @return array
      */
-    protected function getPageList(int $currentPageUid): array
+    protected function getPageList(): array
     {
+        $permsClause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
         $pageList = $this->linkAnalyzer->extGetTreeList(
-            $currentPageUid,
+            $this->id,
             $this->searchLevel['report'],
             0,
-            $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW),
+            $permsClause,
             $this->modTS['checkhidden']
         );
         // Always add the current page, because we are just displaying the results
-        $pageList .= $currentPageUid;
+        $pageList .= $this->id;
+        $pageList = $this->addPageTranslationsToPageList($pageList, $permsClause);
 
         return GeneralUtility::intExplode(',', $pageList, true);
     }
@@ -518,9 +523,21 @@ class LinkValidatorReport
             ->select('*')
             ->from('tx_linkvalidator_link')
             ->where(
-                $queryBuilder->expr()->in(
-                    'record_pid',
-                    $queryBuilder->createNamedParameter($pageList, Connection::PARAM_INT_ARRAY)
+                $queryBuilder->expr()->orX(
+                    $queryBuilder->expr()->andX(
+                        $queryBuilder->expr()->in(
+                            'record_uid',
+                            $queryBuilder->createNamedParameter($pageList, Connection::PARAM_INT_ARRAY)
+                        ),
+                        $queryBuilder->expr()->eq('table_name', $queryBuilder->createNamedParameter('pages'))
+                    ),
+                    $queryBuilder->expr()->andX(
+                        $queryBuilder->expr()->in(
+                            'record_pid',
+                            $queryBuilder->createNamedParameter($pageList, Connection::PARAM_INT_ARRAY)
+                        ),
+                        $queryBuilder->expr()->neq('table_name', $queryBuilder->createNamedParameter('pages'))
+                    )
                 )
             )
             ->orderBy('record_uid')
@@ -854,4 +871,37 @@ class LinkValidatorReport
     {
         return GeneralUtility::makeInstance(PageRenderer::class);
     }
+
+    /**
+     * @param string $theList
+     * @param string $permsClause
+     * @return string
+     */
+    protected function addPageTranslationsToPageList(string $theList, string $permsClause): string
+    {
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+        $result = $queryBuilder
+            ->select('uid', 'title', 'hidden')
+            ->from('pages')
+            ->where(
+                $queryBuilder->expr()->eq(
+                    'l10n_parent',
+                    $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
+                ),
+                QueryHelper::stripLogicalOperatorPrefix($permsClause)
+            )
+            ->execute();
+
+        while ($row = $result->fetch()) {
+            if ($row['hidden'] === 0 || $this->modTS['checkhidden']) {
+                $theList .= ',' . $row['uid'];
+            }
+        }
+
+        return $theList;
+    }
 }