aboutsummaryrefslogtreecommitdiff
path: root/app/Models/DatabaseDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-09-06 09:35:58 +0200
committerGravatar GitHub <noreply@github.com> 2024-09-06 09:35:58 +0200
commit1a552bd60eab4a4b940d3896376b599e155d7da0 (patch)
treee3872dfc1bc51ed52a88bc22fc7582e858314a71 /app/Models/DatabaseDAO.php
parent35a7634e68d87ad4da46c96ee8066e8c681f8d18 (diff)
Regex search (#6706)
* Regex search fix https://github.com/FreshRSS/FreshRSS/issues/3549 * Fix PHPStan * Fix escape * Fix ungreedy * Initial support for regex search in PostgreSQL and MySQL * Improvements, support MySQL * Fix multiline * Add support for SQLite * A few tests * Added author: and inurl: support, documentation * author example * Remove \b for now * Disable regex sanitization for now * Fix getInurlRegex * getNotInurlRegex * Quotes for inurl: * Fix test * Fix quoted tags + regex for tags https://github.com/FreshRSS/FreshRSS/issues/6761 * Fix wrong regex detection * Add MariaDB * Fix logic * Increase requirements for MySQL and MariaDB Check support for multiline mode in MySQL * Remove sanitizeRegexes() * Allow searching HTML code Allow searching for instance `/<pre>/` Fix https://github.com/FreshRSS/FreshRSS/issues/6775#issuecomment-2331769883 * Doc regex search HTML * Fix Doctype
Diffstat (limited to 'app/Models/DatabaseDAO.php')
-rw-r--r--app/Models/DatabaseDAO.php27
1 files changed, 25 insertions, 2 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php
index 363225cdb..ba0ee3e79 100644
--- a/app/Models/DatabaseDAO.php
+++ b/app/Models/DatabaseDAO.php
@@ -185,6 +185,30 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
return $list;
}
+ private static ?string $staticVersion = null;
+ /**
+ * To override the database version. Useful for testing.
+ */
+ public static function setStaticVersion(?string $version): void {
+ self::$staticVersion = $version;
+ }
+
+ public function version(): string {
+ if (self::$staticVersion !== null) {
+ return self::$staticVersion;
+ }
+ static $version = null;
+ if ($version === null) {
+ $version = $this->fetchValue('SELECT version()') ?? '';
+ }
+ return $version;
+ }
+
+ final public function isMariaDB(): bool {
+ // MariaDB includes its name in version, but not MySQL
+ return str_contains($this->version(), 'MariaDB');
+ }
+
public function size(bool $all = false): int {
$db = FreshRSS_Context::systemConf()->db;
@@ -237,8 +261,7 @@ SQL;
$isMariaDB = false;
if ($this->pdo->dbType() === 'mysql') {
- $dbVersion = $this->fetchValue('SELECT version()') ?? '';
- $isMariaDB = stripos($dbVersion, 'MariaDB') !== false; // MariaDB includes its name in version, but not MySQL
+ $isMariaDB = $this->isMariaDB();
if (!$isMariaDB) {
// MySQL does not support `DROP INDEX IF EXISTS` yet https://dev.mysql.com/doc/refman/8.3/en/drop-index.html
// but MariaDB does https://mariadb.com/kb/en/drop-index/