bihor / backendtools

9 admin tools for extensions, slugs, redirects, files, images and links.
GNU General Public License v3.0
5 stars 3 forks source link

Uncatched PageNotFoundException when parent page does not exist #7

Closed tylkomat closed 1 year ago

tylkomat commented 1 year ago

A not existing parent results in a PageNotFoundException when entering the Backendtools page. Without manually fixing the entries in the database I wasn't able to use the plugin.

(1/1) #1343589451 TYPO3\CMS\Core\Exception\Page\PageNotFoundException

Could not fetch page data for uid 3440.
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/core/Classes/Utility/RootlineUtility.php line 258

                )
                ->execute()
                ->fetch();
            if (empty($row)) {
->              throw new PageNotFoundException('Could not fetch page data for uid ' . $uid . '.', 1343589451);
            }
            $this->pageRepository->versionOL('pages', $row, false, true);
            $this->pageRepository->fixVersioningPid('pages', $row);
            if (is_array($row)) {

at TYPO3\CMS\Core\Utility\RootlineUtility->getRecordArray()
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/core/Classes/Utility/RootlineUtility.php line 396

     * @throws CircularRootLineException
     */
    protected function generateRootlineCache()
    {
->      $page = $this->getRecordArray($this->pageUid);
        // If the current page is a mounted (according to the MP parameter) handle the mount-point
        if ($this->isMountedPage()) {
            $mountPoint = $this->getRecordArray($this->parsedMountPointParameters[$this->pageUid]);
            $page = $this->processMountedPage($page, $mountPoint);

at TYPO3\CMS\Core\Utility\RootlineUtility->generateRootlineCache()
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/core/Classes/Utility/RootlineUtility.php line 213

        }
        if (!isset(static::$localCache[$this->cacheIdentifier])) {
            $entry = static::$cache->get($this->cacheIdentifier);
            if (!$entry) {
->              $this->generateRootlineCache();
            } else {
                static::$localCache[$this->cacheIdentifier] = $entry;
                $depth = count($entry);
                // Populate the root-lines for parent pages as well

at TYPO3\CMS\Core\Utility\RootlineUtility->get()
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/core/Classes/Utility/RootlineUtility.php line 411

        $cacheTags = ['pageId_' . $page['uid']];
        if ($parentUid > 0) {
            // Get rootline of (and including) parent page
            $mountPointParameter = !empty($this->parsedMountPointParameters) ? $this->mountPointParameter : '';
->          $rootline = GeneralUtility::makeInstance(self::class, $parentUid, $mountPointParameter, $this->context)->get();
            // retrieve cache tags of parent rootline
            foreach ($rootline as $entry) {
                $cacheTags[] = 'pageId_' . $entry['uid'];
                if ($entry['uid'] == $this->pageUid) {

at TYPO3\CMS\Core\Utility\RootlineUtility->generateRootlineCache()
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/core/Classes/Utility/RootlineUtility.php line 213

        }
        if (!isset(static::$localCache[$this->cacheIdentifier])) {
            $entry = static::$cache->get($this->cacheIdentifier);
            if (!$entry) {
->              $this->generateRootlineCache();
            } else {
                static::$localCache[$this->cacheIdentifier] = $entry;
                $depth = count($entry);
                // Populate the root-lines for parent pages as well

at TYPO3\CMS\Core\Utility\RootlineUtility->get()
in /var/www/typo3/public/typo3conf/ext/backendtools/Classes/Domain/Repository/SessionRepository.php line 1210

    protected function getDomain($uid, $sys_language_uid = 0)
    {
        $domain = '';
        $rootLineUtility = new \TYPO3\CMS\Core\Utility\RootlineUtility($uid);
->      $rootline = $rootLineUtility->get();
        $root = array_pop($rootline);
        if ($root['is_siteroot']) {
            try {
                $site = $this->siteFinder->getSiteByPageId($root['uid']);   // oder $uid;

at Fixpunkt\Backendtools\Domain\Repository\SessionRepository->getDomain()
in /var/www/typo3/public/typo3conf/ext/backendtools/Classes/Domain/Repository/SessionRepository.php line 289

            }
            if ( $row["pdeleted"] ) {
                $row['domain'] = '';
            } else {
->              $row['domain'] = $this->getDomain($row['pid'], $row['sys_language_uid']);
            }
            $row['csvheader'] = str_replace('"', '\'', $row['header']);
            $row['csvtitle'] = str_replace('"', '\'', $row['title']);
            if (isset($row['tx_gridelements_backend_layout'])) {

at Fixpunkt\Backendtools\Domain\Repository\SessionRepository->getPagesWithExtensions()
in /var/www/typo3/public/typo3conf/ext/backendtools/Classes/Controller/SessionController.php line 153

        }

        $gridelements_loaded = ExtensionManagementUtility::isLoaded('gridelements');
        $pages = $this->sessionRepository->getPagesWithExtensions(
->          $my_c, $my_p, $my_type, $my_value, $my_flexform, $my_exclude, $my_orderby, $my_direction, $gridelements_loaded
        );
        $types = $this->sessionRepository->getAllTypes();
        if ($my_recursive > 0) {
            $pages = $this->sessionRepository->filterPagesRecursive($pages, $my_recursive);

at Fixpunkt\Backendtools\Controller\SessionController->listAction()
in /var/www/typo3/typo3_src-10.4.34/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php line 498

Reproduction: change the pid of an entry in pages table to a number which does not exist in pages.uid then try to access the Backendtools page.

bihor commented 1 year ago

I think I have fixed this in version 4.3.1. My function getDomain is not the same as yours. Can you check the version 4.3.1?

tylkomat commented 1 year ago

Yes, that version works. Sorry, I didn't refresh the plugin list in the backoffice and got the older version. Still it was a good oportunity to find these broken pages in our database. Maybe this might be another feature for your plugin.