diff --git a/app/Models/Config/Insensitive.php b/app/Models/Config/Insensitive.php new file mode 100644 index 00000000..ff771f07 --- /dev/null +++ b/app/Models/Config/Insensitive.php @@ -0,0 +1,39 @@ +. + * + * @copyright (c) Visman + * @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; + } +} diff --git a/app/Models/Pages/Admin/Install.php b/app/Models/Pages/Admin/Install.php index 82e87960..ead6d12b 100644 --- a/app/Models/Pages/Admin/Install.php +++ b/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) { diff --git a/app/Models/Pages/Admin/Update.php b/app/Models/Pages/Admin/Update.php index 5c713c94..c79f3583 100644 --- a/app/Models/Pages/Admin/Update.php +++ b/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; + } } diff --git a/app/config/main.dist.php b/app/config/main.dist.php index d91af120..ab1ac358 100644 --- a/app/config/main.dist.php +++ b/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,