Prechádzať zdrojové kódy

create a new ot_router extension

Olivier Massot 4 rokov pred
rodič
commit
80044c0816

+ 1 - 0
README.md

@@ -26,6 +26,7 @@ du répertoire de l'application typo3
                 "Opentalent\\OtTemplating\\": "public/typo3conf/ext/ot_templating/Classes",
                 "Opentalent\\OtStats\\": "public/typo3conf/ext/ot_stats/Classes",
                 "Opentalent\\OtAdmin\\": "public/typo3conf/ext/ot_admin/Classes",
+                "Opentalent\\OtRouter\\": "public/typo3conf/ext/ot_router/Classes"
                 "Opentalent\\OtOptimizer\\": "public/typo3conf/ext/ot_optimizer/Classes"
     		}
     	}

+ 1 - 0
docker/conf/composer.json

@@ -64,6 +64,7 @@
 			"Opentalent\\OtTemplating\\": "public/typo3conf/ext/ot_templating/Classes",
 			"Opentalent\\OtAdmin\\": "public/typo3conf/ext/ot_admin/Classes",
 			"Opentalent\\OtStats\\": "public/typo3conf/ext/ot_stats/Classes",
+			"Opentalent\\OtRouter\\": "public/typo3conf/ext/ot_router/Classes",
 			"Opentalent\\OtOptimizer\\": "public/typo3conf/ext/ot_optimizer/Classes"
 		}
 	}

+ 58 - 0
ot_router/Classes/Indexer/RoutingIndexer.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Opentalent\OtRouter\Controller;
+
+use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
+use Opentalent\OtCore\Page\OtPageRepository;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+
+/**
+ * Provides methods to index the Typo3 pages and populate the routing db table
+ *
+ * @package Opentalent\OtRouter\Controller
+ */
+class RoutingIndexer
+{
+    const INDEX_TABLENAME = 'tx_opentalent_router';
+
+    /**
+     * @var ConnectionPool
+     */
+    private ConnectionPool $connectionPool;
+
+    public function injectConnectionPool(ConnectionPool $connectionPool)
+    {
+        $this->connectionPool = $connectionPool;
+    }
+
+    /**
+     * @var OtPageRepository
+     */
+    protected OtPageRepository $otPageRepository;
+
+    public function injectOtPageRepository(OtPageRepository $otPageRepository) {
+        $this->otPageRepository = $otPageRepository;
+    }
+
+    protected OrganizationRepository $organizationRepository;
+
+    public function injectOrganizationRepository(OrganizationRepository $organizationRepository) {
+        $this->organizationRepository = $organizationRepository;
+    }
+
+    /**
+     * Clear then repopulate the whole index
+     */
+    public function indexAllRoutes() {
+
+    }
+
+    /**
+     * Clear and recreate the index entry for the target website organization
+     *
+     * @param int $organizationId
+     */
+    public function indexRoutesFor(int $organizationId) {
+
+    }
+}

+ 41 - 0
ot_router/Classes/Middleware/Router.php

@@ -0,0 +1,41 @@
+<?php
+namespace Opentalent\OtRouter\Middleware;
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\MiddlewareInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use TYPO3\CMS\Core\Http\RedirectResponse;
+
+/**
+ * Hooks into the frontend request and use the index table to resolve a page uid
+ *
+ * @internal
+ */
+class Router implements MiddlewareInterface
+{
+    /**
+     *
+     * @param ServerRequestInterface $request
+     * @param RequestHandlerInterface $handler
+     * @return ResponseInterface
+     */
+    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+    {
+        $uri = $request->getUri();
+        if (preg_match("/^(.*&)*logintype=logout(&.*)*$/", $uri->getQuery())) {
+            // this is a logout request, and it has already been handled by the
+            // auth service.
+            $newQuery = preg_replace("/logintype=logout&?/", '', $uri->getQuery());
+
+            return new RedirectResponse(
+                $uri->withQuery($newQuery),
+                303,
+                ['X-Redirect-By' => 'OtConnect logout redirection']
+            );
+        }
+
+        // just pass the plate to the next middleware...
+        return $handler->handle($request);
+    }
+}

+ 18 - 0
ot_router/Configuration/RequestMiddlewares.php

@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * Register middlewares, which will be triggered at each request
+ */
+return [
+    'frontend' => [
+        'logout-rewriter' => [
+            'target' => Opentalent\OtRouter\Middleware\Router::class,
+            'before' => [
+                'typo3/cms-adminpanel/data-persister'
+            ],
+            'after' => [
+                'typo3/cms-adminpanel/renderer'
+            ],
+        ],
+    ],
+];

+ 17 - 0
ot_router/Readme.md

@@ -0,0 +1,17 @@
+# OtRouter
+
+Bypass the builtin Typo3 routing with dedicated router adapted to a large amount of websites
+
+|||
+|---|---|
+| Extension key | ot_router |
+| Vendor | Opentalent |
+| Nom | OtRouter |
+
+> **IMPORTANT**: This extension only aims to improve performances. **If disabled, it shall not 
+> cause anything else than performances losses**. We need to be able to disable it anytime without other consequences.
+
+Cette extension implémente un système de routing basé sur un index des pages sous forme de table additionnelle dans la
+base de données.
+
+Pour plus d'informations: <https://ressources.opentalent.fr/pages/viewpage.action?pageId=11481740>

BIN
ot_router/Resources/Public/Icons/Extension.png


+ 28 - 0
ot_router/composer.json

@@ -0,0 +1,28 @@
+{
+    "name": "opentalent/ot-router",
+    "type": "typo3-cms-extension",
+    "description": "Bypass the builtin Typo3 routing with dedicated router adapted to a large amount of websites",
+    "authors": [
+        {
+            "name": "Olivier Massot",
+            "role": "Developer"
+        }
+    ],
+    "require": {
+        "typo3/cms-core": "^9.5"
+    },
+    "autoload": {
+        "psr-4": {
+            "Opentalent\\OtOptimizer\\": "Classes"
+        }
+    },
+    "autoload-dev": {
+        "psr-4": {
+            "Opentalent\\OtOptimizer\\Tests\\": "Tests"
+        }
+    },
+    "replace": {
+        "ot_optimizer": "self.version",
+        "typo3-ter/ot-optimizer": "self.version"
+    }
+}

+ 29 - 0
ot_router/ext_emconf.php

@@ -0,0 +1,29 @@
+<?php
+
+/***************************************************************
+ * Extension Manager/Repository config file for ext: "ot_optimizer"
+ *
+ * Manual updates:
+ * Only the data in the array - anything else is removed by next write.
+ * "version" and "dependencies" must not be touched!
+ ***************************************************************/
+
+$EM_CONF[$_EXTKEY] = [
+    'title' => 'Router',
+    'description' => 'Bypass the builtin Typo3 routing with dedicated router adapted to a large amount of websites',
+    'category' => 'services',
+    'author' => 'Olivier Massot',
+    'author_email' => 'olivier.massot@2iopenservice.fr',
+    'state' => 'alpha',
+    'uploadfolder' => 0,
+    'createDirs' => '',
+    'clearCacheOnLoad' => 0,
+    'version' => '0.1.0',
+    'constraints' => [
+        'depends' => [
+            'typo3' => '8.7.0-10.4.99',
+        ],
+        'conflicts' => [],
+        'suggests' => [],
+    ],
+];

+ 15 - 0
ot_router/ext_tables.sql

@@ -0,0 +1,15 @@
+# ext_tables.sql contient les directives permettant d ajouter des tables et champs à la DB
+
+#
+# Table structure for table 'tx_opentalent_router'
+#
+CREATE TABLE tx_opentalent_router (
+    uid INT UNSIGNED NOT NULL,
+    domain VARCHAR(2048) NOT NULL,
+    root_uid INT UNSIGNED NOT NULL,
+    structure_id INT UNSIGNED NOT NULL,
+    slug VARCHAR(2048) NOT NULL,
+    page_uid INT UNSIGNED NOT NULL,
+    last_update DATETIME NOT NULL,
+    PRIMARY KEY (uid)
+);