]> git.agnieray.net Git - galette.git/commitdiff
Fix php8/mysql autocommit issue
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 8 May 2021 06:14:37 +0000 (08:14 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Sat, 8 May 2021 09:28:19 +0000 (11:28 +0200)
str_contains for php<8

.composer-require-checker.config.json
galette/includes/functions.inc.php
galette/lib/Galette/Core/Install.php

index 67e0ea2ed5e880ffdc5f1c4c8705be688916a4bb..83459ec64340342688d65d0b83f83676767f8e7e 100644 (file)
     "// DI functions",
     "DI\\autowire",
     "DI\\Container",
-    "DI\\ContainerBuilder"
+    "DI\\ContainerBuilder",
 
+    "//PHP8 functions",
+    "str_contains"
   ],
   "scan-files": [
     "galette/*.php",
index d58118dc40416c404adc94edd92dfe3e889232d5..c1a5931734c864f59dd8683b06f6e9ea3a539df8 100644 (file)
@@ -143,3 +143,21 @@ function get_numeric_posted_value($name, $defval)
     }
     return $defval;
 }
+
+if (!function_exists('str_contains')) {
+    /**
+     * PHP8 str_contains polyfill
+     *
+     * based on original work from the PHP Laravel framework
+     * see https://www.php.net/manual/fr/function.str-contains.php#125977
+     *
+     * @param string $haystack The string to search in.
+     * @param string $needle   The substring to search for in the haystack
+     *
+     * @return bool
+     */
+    function str_contains($haystack, $needle)
+    {
+        return $needle !== '' && mb_strpos($haystack, $needle) !== false;
+    }
+}
index ed72a524c0b07cb18051f7636d08100a99a34194..0a0bf4f6c5f3b26d859534502050f223c58e33f2 100644 (file)
@@ -774,7 +774,14 @@ class Install
         if ($fatal_error) {
             $zdb->connection->rollBack();
         } else {
-            $zdb->connection->commit();
+            try {
+                $zdb->connection->commit();
+            } catch (\PDOException $e) {
+                //to avoid php8/mysql autocommit issue
+                if ($zdb->isPostgres() || (!$zdb->isPostgres() && !str_contains($e->getMessage(), 'no active transaction'))) {
+                    throw $e;
+                }
+            }
         }
 
         $this->_report = array_merge($this->_report, $queries_results);