1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- <?php
- declare(strict_types=1);
- namespace ForkBB\Models\Pages\Admin;
- use ForkBB\Core\Config as CoreConfig;
- use ForkBB\Core\Container;
- use ForkBB\Core\Validator;
- use ForkBB\Models\Page;
- use ForkBB\Models\Pages\Admin;
- use PDO;
- use PDOException;
- use RuntimeException;
- use ForkBB\Core\Exceptions\ForkException;
- use function \ForkBB\__;
- class Update extends Admin
- {
- const PHP_MIN = '7.3.0';
- const LATEST_REV_WITH_DB_CHANGES = 24;
- const LOCK_NAME = 'lock_update';
- const LOCk_TTL = 1800;
- const CONFIG_FILE = 'main.php';
- const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
- public function __construct(Container $container)
- {
- parent::__construct($container);
- $container->Lang->load('validator');
- $container->Lang->load('admin_update');
- $this->aIndex = 'update';
- $this->httpStatus = 503;
- $this->onlinePos = null;
- $this->nameTpl = 'admin/form';
- $this->titleForm = __('Update ForkBB');
- $this->classForm = 'updateforkbb';
- $this->header('Retry-After', '3600');
- }
- /**
- * Подготовка страницы к отображению
- */
- public function prepare(): void
- {
- $this->aNavigation = $this->aNavigation();
- $this->crumbs = $this->crumbs(...$this->aCrumbs);
- }
- /**
- * Возвращает массив ссылок с описанием для построения навигации админки
- */
- protected function aNavigation(): array
- {
- return [
- 'update' => [
- $this->c->Router->link('AdminUpdate'),
- __('Update ForkBB'),
- ],
- ];
- }
- /**
- * Возвращает страницу обслуживания с доп.сообщением
- */
- protected function returnMaintenance(bool $isStage = true): Page
- {
- $maintenance = $this->c->Maintenance;
- $maintenance->fIswev = ['w', __('Update script is running')];
- if ($isStage) {
- $maintenance->fIswev = ['e', __('Script runs error')];
- }
- return $maintenance;
- }
- /**
- * Проверяет наличие блокировки скрипта обновления
- */
- protected function hasLock(string $uid = null): bool
- {
- $lock = $this->c->Cache->get(self::LOCK_NAME);
- if (null === $uid) {
- return ! empty($lock);
- } else {
- return empty($lock) || ! \hash_equals($uid, (string) $lock);
- }
- }
- protected function setLock(string $uid = null): ?string
- {
- if (true === $this->hasLock($uid)) {
- return null;
- }
- if (null === $uid) {
- $uid = $this->c->Secury->randomHash(33);
- }
- $this->c->Cache->set(self::LOCK_NAME, $uid, self::LOCk_TTL);
- if (true === $this->hasLock($uid)) {
- return null;
- }
- return $uid;
- }
- /**
- * Подготавливает данные для страницы обновления форума
- */
- public function view(array $args, string $method): Page
- {
- if (true === $this->hasLock()) {
- return $this->returnMaintenance(false);
- }
- if (
- 'POST' === $method
- && empty($this->fIswev)
- ) {
- $v = $this->c->Validator->reset()
- ->addValidators([
- 'check_pass' => [$this, 'vCheckPass'],
- ])->addRules([
- 'token' => 'token:AdminUpdate',
- 'dbpass' => 'required|string:trim|check_pass',
- 'o_maintenance_message' => 'required|string:trim|max:65000 bytes',
- ])->addAliases([
- 'dbpass' => 'Database password',
- 'o_maintenance_message' => 'Maintenance message',
- ])->addMessages([
- ]);
- if ($v->validation($_POST)) {
- $e = null;
- // версия PHP
- if (
- null === $e
- && \version_compare(\PHP_VERSION, self::PHP_MIN, '<')
- ) {
- $e = __('You are running error', 'PHP', \PHP_VERSION, $this->c->FORK_REVISION, self::PHP_MIN);
- }
- // база не от ForkBB ????
- if (
- null === $e
- && $this->c->config->i_fork_revision < 1
- ) {
- $e = 'Version mismatch error';
- }
- // загрузка и проверка конфига
- if (null === $e) {
- try {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- } catch (ForkException $excp) {
- $e = $excp->getMessage();
- }
- }
- // проверка доступности базы данных на изменения
- if (
- null === $e
- && $this->c->config->i_fork_revision < self::LATEST_REV_WITH_DB_CHANGES
- ) {
- $test_table = 'test_tb_for_update';
- if (
- null === $e
- && true === $this->c->DB->tableExists($test_table)
- ) {
- $e = __('The %s table already exists. Delete it.', $test_table);
- }
- $schema = [
- 'FIELDS' => [
- 'id' => ['SERIAL', false],
- ],
- 'PRIMARY KEY' => ['id'],
- ];
- if (
- null === $e
- && false === $this->c->DB->createTable($test_table, $schema)
- ) {
- $e = __('Unable to create %s table', $test_table);
- }
- if (
- null === $e
- && false === $this->c->DB->addField($test_table, 'test_field', 'VARCHAR(80)', false, '')
- ) {
- $e = __('Unable to add test_field field to %s table', $test_table);
- }
- $sql = "INSERT INTO ::{$test_table} (test_field) VALUES ('TEST_VALUE')";
- if (
- null === $e
- && false === $this->c->DB->exec($sql)
- ) {
- $e = __('Unable to insert line to %s table', $test_table);
- }
- if (
- null === $e
- && false === $this->c->DB->dropField($test_table, 'test_field')
- ) {
- $e = __('Unable to drop test_field field from %s table', $test_table);
- }
- if (
- null === $e
- && false === $this->c->DB->dropTable($test_table)
- ) {
- $e = __('Unable to drop %s table', $test_table);
- }
- }
- if (\is_string($e)) {
- return $this->c->Message->message($e, true, 503);
- }
- $uid = $this->setLock();
- if (null === $uid) {
- $this->fIswev = ['e', __('Unable to write update lock')];
- } else {
- $this->c->config->o_maintenance_message = $v->o_maintenance_message;
- $this->c->config->save();
- return $this->c->Redirect->page('AdminUpdateStage', ['uid' => $uid, 'stage' => 1]);
- }
- } else {
- $this->fIswev = $v->getErrors();
- }
- } else {
- $v = null;
- }
- $this->form = $this->form($v);
- return $this;
- }
- /**
- * Проверяет пароль базы
- */
- public function vCheckPass(Validator $v, $dbpass)
- {
- if (\substr($this->c->DB_DSN, 0, 6) === 'sqlite') {
- if (! \hash_equals($this->c->DB_DSN, "sqlite:{$dbpass}")) { // ????
- $v->addError(__('Invalid file error', self::CONFIG_FILE));
- }
- } else {
- if (! \hash_equals($this->c->DB_PASSWORD, $dbpass)) {
- $v->addError(__('Invalid password error', self::CONFIG_FILE));
- }
- }
- return $dbpass;
- }
- /**
- * Формирует массив для формы
- */
- protected function form(?Validator $v): array
- {
- return [
- 'action' => $this->c->Router->link('AdminUpdate'),
- 'hidden' => [
- 'token' => $this->c->Csrf->create('AdminUpdate'),
- ],
- 'sets' => [
- 'update-info' => [
- 'info' => [
- 'info1' => [
- 'type' => '', //????
- 'value' => __('Update message'),
- # 'html' => true,
- ],
- ],
- ],
- 'update' => [
- 'legend' => __('Update ForkBB'),
- 'fields' => [
- 'dbpass' => [
- 'type' => 'password',
- 'value' => '',
- 'caption' => __('Database password'),
- 'info' => __('Database password note'),
- 'required' => true,
- ],
- 'o_maintenance_message' => [
- 'type' => 'textarea',
- 'value' => $v ? $v->o_maintenance_message : $this->c->config->o_maintenance_message,
- 'caption' => __('Maintenance message'),
- 'info' => __('Maintenance message info'),
- 'required' => true,
- ],
- ],
- ],
- 'member-info' => [
- 'info' => [
- 'info1' => [
- 'type' => '', //????
- 'value' => __('Members message'),
- // 'html' => true,
- ],
- ],
- ],
- ],
- 'btns' => [
- 'start' => [
- 'type' => 'submit',
- 'value' => __('Start update'),
- // 'accesskey' => 's',
- ],
- ],
- ];
- }
- /**
- * Обновляет форум
- */
- public function stage(array $args, string $method): Page
- {
- try {
- $uid = $this->setLock($args['uid']);
- if (null === $uid) {
- return $this->returnMaintenance();
- }
- $stage = \max((int) $args['stage'], (int) $this->c->config->i_fork_revision);
- do {
- if (\method_exists($this, 'stageNumber' . $stage)) {
- $start = $this->{'stageNumber' . $stage}($args);
- if (null === $start) {
- ++$stage;
- }
- return $this->c->Redirect->page(
- 'AdminUpdateStage',
- ['uid' => $uid, 'stage' => $stage, 'start' => $start]
- )->message(__('Stage %1$s (%2$s)', $stage, (int) $start));
- }
- ++$stage;
- } while ($stage < $this->c->FORK_REVISION);
- $this->c->config->i_fork_revision = $this->c->FORK_REVISION;
- $this->c->config->save();
- if (true !== $this->c->Cache->clear()) {
- throw new RuntimeException('Unable to clear cache');
- }
- return $this->c->Redirect->page('Index')->message('Successfully updated');
- } catch (ForkException $excp) {
- return $this->c->Message->message($excp->getMessage(), true, 503);
- }
- }
- # /**
- # * Выполняет определенный шаг обновления
- # *
- # * Возвращает null, если шаг выпонен
- # * Возвращает положительный int, если требуется продолжить выполнение шага
- # */
- # protected function stageNumber1(array $args): ?int
- # {
- # $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- #
- # $coreConfig->add(
- # 'multiple=>AdminUsersRecalculate',
- # '\\ForkBB\\Models\\Pages\\Admin\\Users\\Recalculate::class',
- # 'AdminUsersNew'
- # );
- #
- # $coreConfig->save();
- #
- # return null;
- # }
- /**
- * rev.1 to rev.2
- */
- protected function stageNumber1(array $args): ?int
- {
- $this->c->DB->alterField('users', 'gender', 'TINYINT UNSIGNED', false, 0);
- $this->c->DB->alterField('users', 'disp_topics', 'TINYINT UNSIGNED', false, 0);
- $this->c->DB->alterField('users', 'disp_posts', 'TINYINT UNSIGNED', false, 0);
- $this->c->DB->addField('users', 'ip_check_type', 'TINYINT UNSIGNED', false, 0);
- $this->c->DB->addField('users', 'login_ip_cache', 'VARCHAR(255)', false, '');
- return null;
- }
- /**
- * rev.2 to rev.3
- */
- protected function stageNumber2(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>AdminUsersRecalculate',
- '\\ForkBB\\Models\\Pages\\Admin\\Users\\Recalculate::class',
- 'AdminUsersNew'
- );
- $coreConfig->add(
- 'EOL',
- '\\PHP_EOL'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.3 to rev.4
- */
- protected function stageNumber3(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $result = $coreConfig->delete(
- 'multiple=>AdminUsersRecalculate',
- );
- $coreConfig->add(
- 'multiple=>UserManagerUpdateLoginIpCache',
- '\\ForkBB\\Models\\User\\UpdateLoginIpCache::class',
- 'UserManagerUpdateCountTopics'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.4 to rev.5
- */
- protected function stageNumber4(array $args): ?int
- {
- unset($this->c->config->o_date_format);
- unset($this->c->config->o_time_format);
- $this->c->config->save();
- $query = 'UPDATE ::users
- SET time_format=time_format+1
- WHERE time_format>0';
- $this->c->DB->exec($query);
- $query = 'UPDATE ::users
- SET date_format=date_format+1
- WHERE date_format>0';
- $this->c->DB->exec($query);
- return null;
- }
- /**
- * rev.5 to rev.6
- */
- protected function stageNumber5(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>Email',
- '\\ForkBB\\Models\\Pages\\Email::class',
- 'Report'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.6 to rev.7
- */
- protected function stageNumber6(array $args): ?int
- {
- $this->c->DB->addField('groups', 'g_sig_use', 'TINYINT(1)', false, 1);
- $this->c->DB->addField('groups', 'g_sig_length', 'SMALLINT UNSIGNED', false, 400);
- $this->c->DB->addField('groups', 'g_sig_lines', 'TINYINT UNSIGNED', false, 4);
- $vars = [
- ':sig_use' => '1' == $this->c->config->o_signatures ? 1 : 0,
- ':sig_length' => $this->c->config->p_sig_length > 10000 ? 10000 : (int) $this->c->config->p_sig_length,
- ':sig_lines' => $this->c->config->p_sig_lines> 255 ? 255 : (int) $this->c->config->p_sig_lines,
- ];
- $query = 'UPDATE ::groups
- SET g_sig_use=?i:sig_use, g_sig_length=?i:sig_length, g_sig_lines=?i:sig_lines';
- $this->c->DB->query($query, $vars);
- $vars = [
- ':grp' => $this->c->GROUP_ADMIN,
- ];
- $query = 'UPDATE ::groups
- SET g_sig_use=1, g_sig_length=10000, g_sig_lines=255
- WHERE g_id=?i:grp';
- $this->c->DB->query($query, $vars);
- $vars = [
- ':grp' => $this->c->GROUP_GUEST,
- ];
- $query = 'UPDATE ::groups
- SET g_sig_use=0, g_sig_length=0, g_sig_lines=0
- WHERE g_id=?i:grp';
- $this->c->DB->query($query, $vars);
- unset($this->c->config->o_signatures);
- unset($this->c->config->p_sig_length);
- unset($this->c->config->p_sig_lines);
- $this->c->config->save();
- return null;
- }
- /**
- * rev.7 to rev.8
- */
- protected function stageNumber7(array $args): ?int
- {
- $this->c->DB->dropField('groups', 'g_sig_use');
- return null;
- }
- /**
- * rev.8 to rev.9
- */
- protected function stageNumber8(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>Feed',
- '\\ForkBB\\Models\\Pages\\Feed::class',
- 'Email'
- );
- $coreConfig->add(
- 'multiple=>PostManagerFeed',
- '\\ForkBB\\Models\\Post\\Feed::class',
- 'PostManagerMove'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.9 to rev.10
- */
- protected function stageNumber9(array $args): ?int
- {
- $this->c->config->i_email_max_recipients = 1;
- $this->c->config->save();
- return null;
- }
- /**
- * rev.10 to rev.11
- */
- protected function stageNumber10(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'shared=>subscriptions',
- '\\ForkBB\\Models\\Subscription\\Model::class',
- 'search'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.11 to rev.12
- */
- protected function stageNumber11(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>SearchModelActionF',
- '\\ForkBB\\Models\\Search\\ActionF::class',
- 'SearchModelActionT'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.12 to rev.13
- */
- protected function stageNumber12(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'shared=>SubscriptionModelSend',
- '\\ForkBB\\Models\\Subscription\\Send::class'
- );
- $result = $coreConfig->delete(
- 'multiple=>BanListModelIsBanned',
- );
- $coreConfig->add(
- 'shared=>BanListModelIsBanned',
- '\\ForkBB\\Models\\BanList\\IsBanned::class'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.13 to rev.14
- */
- protected function stageNumber13(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $result = $coreConfig->delete(
- 'multiple=>AdminPermissions',
- );
- $coreConfig->add(
- 'multiple=>AdminParser',
- '\\ForkBB\\Models\\Pages\\Admin\\Parser\\Edit::class',
- 'AdminReports'
- );
- $coreConfig->add(
- 'multiple=>AdminParserSmilies',
- '\\ForkBB\\Models\\Pages\\Admin\\Parser\\Smilies::class',
- 'AdminParser'
- );
- $coreConfig->add(
- 'multiple=>AdminParserBBCode',
- '\\ForkBB\\Models\\Pages\\Admin\\Parser\\BBCode::class',
- 'AdminParserSmilies'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.14 to rev.15
- */
- protected function stageNumber14(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $result = $coreConfig->delete(
- 'multiple=>SmileyListModelLoad',
- );
- $coreConfig->add(
- 'shared=>SmileyListModelLoad',
- '\\ForkBB\\Models\\SmileyList\\Load::class'
- );
- $coreConfig->add(
- 'shared=>SmileyListModelUpdate',
- '\\ForkBB\\Models\\SmileyList\\Update::class'
- );
- $coreConfig->add(
- 'shared=>SmileyListModelInsert',
- '\\ForkBB\\Models\\SmileyList\\Insert::class'
- );
- $coreConfig->add(
- 'shared=>SmileyListModelDelete',
- '\\ForkBB\\Models\\SmileyList\\Delete::class'
- );
- $coreConfig->save();
- $this->c->DB->renameField('smilies', 'image', 'sm_image');
- $this->c->DB->renameField('smilies', 'text', 'sm_code');
- $this->c->DB->renameField('smilies', 'disp_position', 'sm_position');
- $this->c->DB->alterField('smilies', 'sm_position', 'INT(10) UNSIGNED', false, 0);
- return null;
- }
- /**
- * rev.15 to rev.16
- */
- protected function stageNumber15(array $args): ?int
- {
- // bbcode
- $schema = [
- 'FIELDS' => [
- 'id' => ['SERIAL', false],
- 'bb_tag' => ['VARCHAR(11)', false, ''],
- 'bb_edit' => ['TINYINT(1)', false, 1],
- 'bb_delete' => ['TINYINT(1)', false, 1],
- 'bb_structure' => ['MEDIUMTEXT', false],
- ],
- 'PRIMARY KEY' => ['id'],
- 'UNIQUE KEYS' => [
- 'bb_tag_idx' => ['bb_tag'],
- ],
- ];
- $this->c->DB->createTable('bbcode', $schema);
- $query = 'INSERT INTO ::bbcode (bb_tag, bb_edit, bb_delete, bb_structure)
- VALUES(?s:tag, 1, 0, ?s:structure)';
- $bbcodes = include $this->c->DIR_CONFIG . '/defaultBBCode.php';
- foreach ($bbcodes as $bbcode) {
- $vars = [
- ':tag' => $bbcode['tag'],
- ':structure' => \json_encode($bbcode, self::JSON_OPTIONS),
- ];
- $this->c->DB->exec($query, $vars);
- }
- $this->c->config->a_bb_white_mes = [];
- $this->c->config->a_bb_white_sig = ['b', 'i', 'u', 'color', 'colour', 'email', 'url'];
- $this->c->config->a_bb_black_mes = [];
- $this->c->config->a_bb_black_sig = [];
- unset($this->c->config->o_quote_depth);
- unset($this->c->config->p_sig_img_tag);
- unset($this->c->config->p_message_img_tag);
- $this->c->config->save();
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $result = $coreConfig->delete(
- 'BBCODE_INFO=>forSign',
- );
- $coreConfig->add(
- 'shared=>bbcode',
- '\'@BBCodeListModel:init\'',
- 'subscriptions'
- );
- $coreConfig->add(
- 'shared=>BBCodeListModel',
- [
- 'class' => '\\ForkBB\\Models\\BBCodeList\\Model::class',
- 'file' => '\'defaultBBCode.php\'',
- ]
- );
- $coreConfig->add(
- 'shared=>BBCodeListModelGenerate',
- '\\ForkBB\\Models\\BBCodeList\\Generate::class'
- );
- $coreConfig->add(
- 'shared=>BBCodeListModelLoad',
- '\\ForkBB\\Models\\BBCodeList\\Load::class'
- );
- $coreConfig->add(
- 'shared=>BBCodeListModelUpdate',
- '\\ForkBB\\Models\\BBCodeList\\Update::class'
- );
- $coreConfig->add(
- 'shared=>BBCodeListModelInsert',
- '\\ForkBB\\Models\\BBCodeList\\Insert::class'
- );
- $coreConfig->add(
- 'shared=>BBCodeListModelDelete',
- '\\ForkBB\\Models\\BBCodeList\\Delete::class'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.16 to rev.17
- */
- protected function stageNumber16(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'shared=>Router=>csrf',
- '\'@Csrf\''
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.17 to rev.18
- */
- protected function stageNumber17(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>BBStructure',
- '\\ForkBB\\Models\\BBCodeList\\Structure::class'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.18 to rev.19
- */
- protected function stageNumber18(array $args): ?int
- {
- $this->c->DB->addField('users', 'avatar', 'VARCHAR(30)', false, '', 'title');
- $dir = $this->c->DIR_PUBLIC . $this->c->config->o_avatars_dir . '/';
- $avatars = [];
- if (
- \is_dir($dir)
- && false !== ($dh = \opendir($dir))
- ) {
- while (false !== ($entry = \readdir($dh))) {
- if (
- \preg_match('%^([1-9]\d*)\.(jpg|gif|png)$%D', $entry, $matches)
- && \is_file($dir . $entry)
- ) {
- $avatars[$matches[2]][] = (int) $matches[1];
- }
- }
- \closedir($dh);
- }
- $query = 'UPDATE ::users
- SET avatar=CONCAT(id, \'.\', ?s:ext)
- WHERE id IN (?ai:ids)';
- foreach ($avatars as $ext => $ids) {
- $vars = [
- ':ext' => $ext,
- ':ids' => $ids,
- ];
- $this->c->DB->exec($query, $vars);
- }
- return null;
- }
- /**
- * rev.19 to rev.20
- */
- protected function stageNumber19(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $result = $coreConfig->delete(
- 'shared=>FileCache',
- );
- $coreConfig->add(
- 'shared=>Cache',
- $result
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.20 to rev.21
- */
- protected function stageNumber20(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'shared=>Test',
- '\\ForkBB\\Core\\Test::class',
- 'Func'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.21 to rev.22
- */
- protected function stageNumber21(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'USERNAME_PATTERN',
- '\'%^(?=.{2,25}$)\\p{L}[\\p{L}\\p{N}\\x20\\._-]+$%uD\'',
- 'FLOOD_INTERVAL'
- );
- $coreConfig->save();
- return null;
- }
- /**
- * rev.22 to rev.23
- */
- protected function stageNumber22(array $args): ?int
- {
- $this->c->config->i_topic_review = $this->c->config->o_topic_review ?? 15;
- $this->c->config->i_disp_topics_default = $this->c->config->o_disp_topics_default ?? 30;
- $this->c->config->i_disp_posts_default = $this->c->config->o_disp_posts_default ?? 25;
- $this->c->config->i_disp_users = $this->c->config->o_disp_users ?? 50;
- $this->c->config->i_default_email_setting = $this->c->config->o_default_email_setting ?? 2;
- $this->c->config->i_avatars_width = $this->c->config->o_avatars_width ?? 60;
- $this->c->config->i_avatars_height = $this->c->config->o_avatars_height ?? 60;
- $this->c->config->i_avatars_size = $this->c->config->o_avatars_size ?? 10240;
- $this->c->config->i_feed_type = $this->c->config->o_feed_type ?? 2;
- $this->c->config->i_feed_ttl = $this->c->config->o_feed_ttl ?? 0;
- $this->c->config->i_report_method = $this->c->config->o_report_method ?? 0;
- $this->c->config->i_default_user_group = $this->c->config->o_default_user_group ?? $this->c->GROUP_MEMBER;
- $this->c->config->a_max_users = [
- 'number' => (int) $this->c->config->st_max_users ?? 1,
- 'time' => (int) $this->c->config->st_max_users_time ?? \time(),
- ];
- unset($this->c->config->o_enable_acaptcha);
- unset($this->c->config->o_crypto_salt);
- unset($this->c->config->o_crypto_pas);
- unset($this->c->config->o_crypto_enable);
- unset($this->c->config->o_check_ip);
- unset($this->c->config->o_coding_forms);
- unset($this->c->config->o_fbox_files);
- unset($this->c->config->o_fbox_guest);
- unset($this->c->config->o_show_version);
- unset($this->c->config->o_topic_review);
- unset($this->c->config->o_disp_topics_default);
- unset($this->c->config->o_disp_posts_default);
- unset($this->c->config->o_disp_users);
- unset($this->c->config->o_default_email_setting);
- unset($this->c->config->o_avatars_width);
- unset($this->c->config->o_avatars_height);
- unset($this->c->config->o_avatars_size);
- unset($this->c->config->o_feed_type);
- unset($this->c->config->o_feed_ttl);
- unset($this->c->config->o_report_method);
- unset($this->c->config->o_board_redirect);
- unset($this->c->config->o_board_redirectg);
- unset($this->c->config->o_default_user_group);
- unset($this->c->config->st_max_users);
- unset($this->c->config->st_max_users_time);
- $this->c->config->save();
- return null;
- }
- /**
- * rev.23 to rev.24
- */
- protected function stageNumber23(array $args): ?int
- {
- $this->c->DB->addField('forums', 'last_poster_id', 'INT(10) UNSIGNED', false, 0, 'last_poster');
- $query = 'UPDATE ::forums AS f
- SET f.last_poster_id=COALESCE((
- SELECT u.id
- FROM ::users AS u
- WHERE u.username=f.last_poster AND u.id>1
- ), 0)';
- $this->c->DB->exec($query);
- $this->c->DB->renameField('posts', 'edited_by', 'editor');
- $this->c->DB->addField('posts', 'editor_id', 'INT(10) UNSIGNED', false, 0, 'editor');
- $query = 'UPDATE ::posts AS p
- SET p.editor_id=COALESCE((
- SELECT u.id
- FROM ::users AS u
- WHERE u.username=p.editor AND u.id>1
- ), 0)';
- $this->c->DB->exec($query);
- unset($this->c->config->o_merge_timeout);
- $this->c->config->save();
- return null;
- }
- /**
- * rev.24 to rev.25
- */
- protected function stageNumber24(array $args): ?int
- {
- $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
- $coreConfig->add(
- 'multiple=>ForumManagerUpdateUsername',
- '\\ForkBB\\Models\\Forum\\UpdateUsername::class',
- 'ForumManagerMarkread'
- );
- $coreConfig->add(
- 'multiple=>PostManagerUpdateUsername',
- '\\ForkBB\\Models\\Post\\UpdateUsername::class',
- 'PostManagerFeed'
- );
- $coreConfig->save();
- return null;
- }
- }
|