From f1a47eff61086893be43bb583c6ba72b989864dd Mon Sep 17 00:00:00 2001
From: Thierry Parmentelat <thierry.parmentelat@inria.fr>
Date: Fri, 29 Apr 2022 17:14:43 +0200
Subject: [PATCH] patch drupal's session handler for php8

---
 drupal-hacks/patch-session-inc.sh | 19 +++++++++++++++++++
 plewww.spec                       |  4 ++++
 2 files changed, 23 insertions(+)
 create mode 100755 drupal-hacks/patch-session-inc.sh

diff --git a/drupal-hacks/patch-session-inc.sh b/drupal-hacks/patch-session-inc.sh
new file mode 100755
index 0000000..1cc8708
--- /dev/null
+++ b/drupal-hacks/patch-session-inc.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# for php8; the handler attached to session_destroy must now return a boolean
+# the patched function is a one-liner
+# so we find its declaration, go down one line (+), and then add a line
+
+readonly filetopatch=/var/www/html/includes/session.inc
+
+# do not patch twice
+if ! grep -q 'patch-session_destroy' $filetopatch >& /dev/null; then
+    ed $filetopatch << EOF
+/function sess_destroy
++
+a
+  return TRUE; // patch-session_destroy for php8
+.
+wq
+EOF
+fi
diff --git a/plewww.spec b/plewww.spec
index aa311e2..5131626 100644
--- a/plewww.spec
+++ b/plewww.spec
@@ -105,6 +105,10 @@ for module in user node; do
     cp -f /var/www/html/drupal-hacks/${module}.module /var/www/html/modules/${module}.module
 done
 popd
+# hack drupal's session handler for php8
+pushd /var/www/html/includes
+bash /var/www/html/drupal-hacks/patch-session-inc.sh
+popd
 # create myslice.log and change its ownership
 mkdir -p /var/log/myslice
 touch /var/log/myslice/myslice.log
-- 
2.47.0