Просмотр исходного кода

Fix PHP 8.5+ deprecation sqliteCreateFunction (#9421)

Fix https://github.com/FreshRSS/FreshRSS/issues/8525#issuecomment-6065641500
Alexandre Alapetite 2 дней назад
Родитель
Сommit
4a3c6b6b60
1 измененных файлов с 16 добавлено и 7 удалено
  1. 16 7
      app/Models/EntryDAOSQLite.php

+ 16 - 7
app/Models/EntryDAOSQLite.php

@@ -50,14 +50,23 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
 		if (!str_contains($sql, ' REGEXP ')) {
 			return;
 		}
-		// https://www.php.net/pdo.sqlitecreatefunction
+		// https://www.php.net/pdo-sqlite.createfunction
 		// https://www.sqlite.org/lang_expr.html#the_like_glob_regexp_match_and_extract_operators
-		$this->pdo->sqliteCreateFunction('regexp',
-			function (string $pattern, string $text): bool {
-				return preg_match($pattern, $text) === 1;
-			},
-			2
-		);
+		if (class_exists(\Pdo\Sqlite::class) && $this->pdo instanceof \Pdo\Sqlite) {
+			$this->pdo->createFunction('regexp',
+				function (string $pattern, string $text): bool {
+					return preg_match($pattern, $text) === 1;
+				},
+				2
+			);
+		} else {	// PHP < 8.4
+			$this->pdo->sqliteCreateFunction('regexp',
+				function (string $pattern, string $text): bool {
+					return preg_match($pattern, $text) === 1;
+				},
+				2
+			);
+		}
 	}
 
 	/** @param array{0:string,1:int,2:string} $errorInfo */