From 72791b2b0c008bbf9c051c24a9c325e4da021dd6 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tim.dijen@minbzk.nl>
Date: Sun, 21 Jul 2019 20:12:51 +0200
Subject: [PATCH] Update LogoutStore.php (#1120)

---
 modules/saml/lib/SP/LogoutStore.php | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/modules/saml/lib/SP/LogoutStore.php b/modules/saml/lib/SP/LogoutStore.php
index e83138836..c06cec565 100644
--- a/modules/saml/lib/SP/LogoutStore.php
+++ b/modules/saml/lib/SP/LogoutStore.php
@@ -26,7 +26,24 @@ class LogoutStore
     private static function createLogoutTable(Store\SQL $store)
     {
         $tableVer = $store->getTableVersion('saml_LogoutStore');
-        if ($tableVer === 2) {
+        if ($tableVer === 3) {
+            return;
+        } elseif ($tableVer === 2) {
+            // Drop old indexes
+            $query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX '.$store->prefix.'_saml_LogoutStore_nameId';
+            $store->pdo->exec($query);
+            $query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore DROP INDEX _authSource';
+            $store->pdo->exec($query);
+
+            // Create new indexes
+            $query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON ';
+            $query .= $store->prefix.'_saml_LogoutStore (_authSource(191), _nameId)';
+            $store->pdo->exec($query);
+
+            $query = 'ALTER TABLE '.$store->prefix.'_saml_LogoutStore ADD UNIQUE KEY (_authSource(191), _nameID, _sessionIndex)';
+            $store->pdo->exec($query);
+
+            $store->setTableVersion('saml_LogoutStore', 3);
             return;
         } elseif ($tableVer === 1) {
             // TableVersion 2 increased the column size to 255 which is the maximum length of a FQDN
@@ -58,7 +75,7 @@ class LogoutStore
             _sessionIndex VARCHAR(50) NOT NULL,
             _expire TIMESTAMP NOT NULL,
             _sessionId VARCHAR(50) NOT NULL,
-            UNIQUE (_authSource, _nameID, _sessionIndex)
+            UNIQUE (_authSource(191), _nameID, _sessionIndex)
         )';
         $store->pdo->exec($query);
 
@@ -67,7 +84,7 @@ class LogoutStore
         $store->pdo->exec($query);
 
         $query = 'CREATE INDEX '.$store->prefix.'_saml_LogoutStore_nameId ON ';
-        $query .= $store->prefix.'_saml_LogoutStore (_authSource, _nameId)';
+        $query .= $store->prefix.'_saml_LogoutStore (_authSource(191), _nameId)';
         $store->pdo->exec($query);
 
         $store->setTableVersion('saml_LogoutStore', 2);
-- 
GitLab