Quellcode durchsuchen

Add Config\Insensitive

The method determines the case insensitivity of the search in the database through the ::config table and WHERE LIKE.
Visman vor 3 Jahren
Ursprung
Commit
45a9e96cb3

+ 39 - 0
app/Models/Config/Insensitive.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ * This file is part of the ForkBB <https://github.com/forkbb>.
+ *
+ * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
+ * @license   The MIT License (MIT)
+ */
+
+declare(strict_types=1);
+
+namespace ForkBB\Models\Config;
+
+use ForkBB\Models\Method;
+
+class Insensitive extends Method
+{
+    /**
+     * Проверяет регистронезависимое сравнение в БД через таблицу config
+     */
+    public function insensitive(): bool
+    {
+        $result = $this->c->Cache->get('case_insensitive', null);
+
+        if (! \is_bool($result)) {
+            $like  = 'pgsql' === $this->c->DB->getType() ? 'ILIKE' : 'LIKE';
+            $query = "SELECT conf_value
+                FROM ::config
+                WHERE conf_name {$like} 's#_регистр' ESCAPE '#'";
+
+            $result = 'Ok' === $this->c->DB->query($query)->fetchColumn();
+
+            if (true !== $this->c->Cache->set('case_insensitive', $result)) {
+                throw new RuntimeException('Unable to write value to cache - case_insensitive');
+            }
+        }
+
+        return $result;
+    }
+}

+ 1 - 0
app/Models/Pages/Admin/Install.php

@@ -1286,6 +1286,7 @@ class Install extends Admin
                     'show_img_sig' => 1,
                 ], self::JSON_OPTIONS
             ),
+            's_РЕГИСТР'               => 'Ok',
         ];
 
         foreach ($pun_config as $conf_name => $conf_value) {

+ 24 - 0
app/Models/Pages/Admin/Update.php

@@ -647,4 +647,28 @@ class Update extends Admin
 
         return null;
     }
+
+    /**
+     * rev.47 to rev.48
+     */
+    protected function stageNumber47(array $args): ?int
+    {
+        $config = $this->c->config;
+
+        $config->s_РЕГИСТР = 'Ok';
+
+        $config->save();
+
+        $coreConfig = new CoreConfig($this->configFile);
+
+        $coreConfig->add(
+            'shared=>Config/insensitive',
+            '\\ForkBB\\Models\\Config\\Insensitive::class',
+            'Config/save'
+        );
+
+        $coreConfig->save();
+
+        return null;
+    }
 }

+ 3 - 2
app/config/main.dist.php

@@ -212,8 +212,9 @@ return [
         'Censorship/refresh' => \ForkBB\Models\Censorship\Refresh::class,
         'Censorship/save'    => \ForkBB\Models\Censorship\Save::class,
 
-        'Config/load' => \ForkBB\Models\Config\Load::class,
-        'Config/save' => \ForkBB\Models\Config\Save::class,
+        'Config/insensitive' => \ForkBB\Models\Config\Insensitive::class,
+        'Config/load'        => \ForkBB\Models\Config\Load::class,
+        'Config/save'        => \ForkBB\Models\Config\Save::class,
 
         'Forum/calcStat' => \ForkBB\Models\Forum\CalcStat::class,