Browse Source

Merge branch 'hotfix/V8-7245-voir-si-possible-de-rendre-dispo'

Olivier Massot 8 tháng trước cách đây
mục cha
commit
ec5fe232e6

+ 1 - 0
ot_admin/Classes/Controller/SiteController.php

@@ -545,6 +545,7 @@ class SiteController extends ActionController
             $include .= ",EXT:frontend_editing/Configuration/TypoScript/FluidStyledContent9";
             $include .= ",EXT:ot_templating/Configuration/TypoScript";
             $include .= ",EXT:hcaptcha/Configuration/TypoScript";
+            $include .= ",EXT:seo/Configuration/TypoScript/XmlSitemap";
 
             $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_template');
             $queryBuilder->insert('sys_template')

+ 45 - 0
ot_core/Classes/Middleware/Frontend/OtSitemapProvider.php

@@ -0,0 +1,45 @@
+<?php
+declare(strict_types = 1);
+namespace Opentalent\OtCore\Middleware\Frontend;
+
+use TYPO3\CMS\Core\Http\Response;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+/**
+ * Redirect sitemap requests
+ * @see https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Seo/XmlSitemap.html
+ */
+class OtSitemapProvider implements MiddlewareInterface
+{
+    /**
+     * Resolve the site/language information by checking the page ID or the URL.
+     *
+     * @param ServerRequestInterface $request
+     * @param RequestHandlerInterface $handler
+     * @return ResponseInterface
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        $path = $request->getUri()->getPath();
+        $devMode = ($_SERVER['TYPO3_CONTEXT'] ?? '') == "Development";
+
+        $isSitemapRequest = $devMode ?
+            preg_match("/[a-z0-9-]+\/sitemap\.xml/", $path) :
+            $path === 'sitemap.xml';
+
+        if ($isSitemapRequest) {
+            $path = $devMode ? substr($request->getUri()->getPath(), 0, -strlen('/sitemap.xml')) : '';
+
+            $url = $path . '/?type=1533906435';
+            $response = new Response();
+            return $response
+                ->withStatus(301) // ou 302 pour une redirection temporaire
+                ->withHeader('Location', $url);
+        }
+
+        return $handler->handle($request);
+    }
+}

+ 12 - 1
ot_core/Configuration/RequestMiddlewares.php

@@ -1,4 +1,6 @@
 <?php
+
+use Opentalent\OtCore\Middleware\Frontend\OtSitemapProvider;
 use Opentalent\OtCore\Middleware\Frontend\OtSiteResolver;
 
 /**
@@ -6,11 +8,20 @@ use Opentalent\OtCore\Middleware\Frontend\OtSiteResolver;
  */
 return [
     'frontend' => [
-        'typo3/cms-frontend/site' => [
+        'opentalent/frontend/site' => [
             'target' => OtSiteResolver::class,
             'before' => [
                 'typo3/cms-frontend/page-resolver'
             ]
         ],
+        'opentalent/frontend/sitemap' => [
+            'target' => OtSitemapProvider::class,
+            'after' => [
+                'opentalent/frontend/site'
+            ],
+            'before' => [
+                'typo3/cms-frontend/page-resolver'
+            ]
+        ],
     ],
 ];

+ 19 - 20
ot_optimizer/Classes/XClass/Core/Routing/OtPageSlugCandidateProvider.php

@@ -2,9 +2,11 @@
 namespace Opentalent\OtOptimizer\XClass\Core\Routing;
 
 use Doctrine\DBAL\Connection;
+use TYPO3\CMS\Core\Context\LanguageAspect;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
+use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
 use TYPO3\CMS\Core\Domain\Repository\PageRepository;
 use TYPO3\CMS\Core\Exception\SiteNotFoundException;
 use TYPO3\CMS\Core\Routing\PageSlugCandidateProvider;
@@ -66,22 +68,22 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
      */
     protected function getPagesFromDatabaseForCandidates(array $slugCandidates, int $languageId, array $excludeUids = []): array
     {
-        $searchLiveRecordsOnly = $this->context->getPropertyFromAspect('workspace', 'isLive');
+        $workspaceId = (int)$this->context->getPropertyFromAspect('workspace', 'id');
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable('pages');
         $queryBuilder
             ->getRestrictions()
             ->removeAll()
             ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
-            ->add(GeneralUtility::makeInstance(FrontendWorkspaceRestriction::class, null, null, $searchLiveRecordsOnly));
+            ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $workspaceId, true));
 
         $statement = $queryBuilder
-            ->select('uid', 'l10n_parent', 'pid', 'slug', 'mount_pid', 'mount_pid_ol', 't3ver_state', 'doktype', 't3ver_wsid', 't3ver_oid')
+            ->select('uid', 'sys_language_uid', 'l10n_parent', 'l18n_cfg', 'pid', 'slug', 'mount_pid', 'mount_pid_ol', 't3ver_state', 'doktype', 't3ver_wsid', 't3ver_oid')
             ->from('pages')
             ->where(
                 $queryBuilder->expr()->eq(
                     'sys_language_uid',
-                    $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
+                    $queryBuilder->createNamedParameter($languageId, \TYPO3\CMS\Core\Database\Connection::PARAM_INT)
                 ),
                 $queryBuilder->expr()->in(
                     'slug',
@@ -93,10 +95,12 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
             )
             // Exact match will be first, that's important
             ->orderBy('slug', 'desc')
+            // versioned records should be rendered before the live records
+            ->addOrderBy('t3ver_wsid', 'desc')
             // Sort pages that are not MountPoint pages before mount points
             ->addOrderBy('mount_pid_ol', 'asc')
             ->addOrderBy('mount_pid', 'asc')
-            ->execute();
+            ->executeQuery();
 
         $pages = [];
         $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
@@ -104,34 +108,30 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
         $isRecursiveCall = !empty($excludeUids);
 
         // <----
-        // special: patch 2021-10-05 by Opentalent, for performances reason
-        // >> made for typo3 v10.4
+        // special: patch by Opentalent, for performances reason
+        // >> updated for typo3 v12.4
         $siteRootPageUid = $this->site->getRootPageId();
         $sitePages = $this->getAllSubpagesUidFor($siteRootPageUid);
         // ---->
 
-        while ($row = $statement->fetch()) {
+
+        while ($row = $statement->fetchAssociative()) {
             $mountPageInformation = null;
-            // This changes the PID value and adds a _ORIG_PID value (only different in move actions)
-            // In live: This fetches everything in a bad way ! as there is no workspace limitation given, fetching all new and moved placeholders here!
-            // In a workspace: Filter out versioned records (t3ver_oid=0), leaving effectively the new/move placeholders in place, where the new placeholder
-            // However, this is checked in $siteFinder->getSiteByPageId() via RootlineUtility where overlays are happening
-            // so the fixVersioningPid() call is probably irrelevant.
-            $pageRepository->fixVersioningPid('pages', $row);
-            $pageIdInDefaultLanguage = (int)($languageId > 0 ? $row['l10n_parent'] : $row['uid']);
+            $pageIdInDefaultLanguage = (int)($languageId > 0 ? $row['l10n_parent'] : ($row['t3ver_oid'] ?: $row['uid']));
             // When this page was added before via recursion, this page should be skipped
             if (in_array($pageIdInDefaultLanguage, $excludeUids, true)) {
                 continue;
             }
 
             // <----
-            // special: patch 2021-10-05 by Opentalent, for performances reason
-            // >> made for typo3 v10.4
+            // special: patch by Opentalent, for performances reason
+            // >> updated for typo3 v12.4
             if (!in_array($pageIdInDefaultLanguage, $sitePages)) {
                 continue;
             }
             // ---->
 
+
             try {
                 $isOnSameSite = $siteFinder->getSiteByPageId($pageIdInDefaultLanguage)->getRootPageId() === $this->site->getRootPageId();
             } catch (SiteNotFoundException $e) {
@@ -159,7 +159,7 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
                 $row['MPvar'] = $mountPageInformation['MPvar'];
                 $mountedPage = $pageRepository->getPage_noCheck($mountPageInformation['mount_pid_rec']['uid']);
                 // Ensure to fetch the slug in the translated page
-                $mountedPage = $pageRepository->getPageOverlay($mountedPage, $languageId);
+                $mountedPage = $pageRepository->getLanguageOverlay('pages', $mountedPage, new LanguageAspect($languageId, $languageId));
                 // Mount wasn't connected properly, so it is skipped
                 if (!$mountedPage) {
                     continue;
@@ -168,7 +168,7 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
                 // it must never be accessible directly, but only in the MountPoint context. Therefore we change
                 // the current ID and slug.
                 // This needs to happen before the regular case, as the $pageToAdd contains the MPvar information
-                if (PageRepository::DOKTYPE_MOUNTPOINT === (int)$row['doktype'] && $row['mount_pid_ol']) {
+                if ((int)$row['doktype'] === PageRepository::DOKTYPE_MOUNTPOINT && $row['mount_pid_ol']) {
                     // If the mounted page was already added from above, this should not be added again (to include
                     // the mount point parameter).
                     if (in_array((int)$mountedPage['uid'], $excludeUids, true)) {
@@ -212,7 +212,6 @@ class OtPageSlugCandidateProvider extends PageSlugCandidateProvider
             }
         }
         return $pages;
-
     }
 
 }