Add Config\Insensitive

The method determines the case insensitivity of the search in the database through the ::config table and WHERE LIKE.
This commit is contained in:
Visman 2022-01-14 16:49:07 +07:00
parent 253a8a54cf
commit 45a9e96cb3
4 changed files with 67 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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,