Update.php 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. <?php
  2. declare(strict_types=1);
  3. namespace ForkBB\Models\Pages\Admin;
  4. use ForkBB\Core\Config as CoreConfig;
  5. use ForkBB\Core\Container;
  6. use ForkBB\Core\Validator;
  7. use ForkBB\Models\Page;
  8. use ForkBB\Models\Pages\Admin;
  9. use PDO;
  10. use PDOException;
  11. use RuntimeException;
  12. use ForkBB\Core\Exceptions\ForkException;
  13. use function \ForkBB\__;
  14. class Update extends Admin
  15. {
  16. const PHP_MIN = '7.3.0';
  17. const LATEST_REV_WITH_DB_CHANGES = 24;
  18. const LOCK_NAME = 'lock_update';
  19. const LOCk_TTL = 1800;
  20. const CONFIG_FILE = 'main.php';
  21. const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
  22. public function __construct(Container $container)
  23. {
  24. parent::__construct($container);
  25. $container->Lang->load('validator');
  26. $container->Lang->load('admin_update');
  27. $this->aIndex = 'update';
  28. $this->httpStatus = 503;
  29. $this->onlinePos = null;
  30. $this->nameTpl = 'admin/form';
  31. $this->titleForm = __('Update ForkBB');
  32. $this->classForm = 'updateforkbb';
  33. $this->header('Retry-After', '3600');
  34. }
  35. /**
  36. * Подготовка страницы к отображению
  37. */
  38. public function prepare(): void
  39. {
  40. $this->aNavigation = $this->aNavigation();
  41. $this->crumbs = $this->crumbs(...$this->aCrumbs);
  42. }
  43. /**
  44. * Возвращает массив ссылок с описанием для построения навигации админки
  45. */
  46. protected function aNavigation(): array
  47. {
  48. return [
  49. 'update' => [
  50. $this->c->Router->link('AdminUpdate'),
  51. __('Update ForkBB'),
  52. ],
  53. ];
  54. }
  55. /**
  56. * Возвращает страницу обслуживания с доп.сообщением
  57. */
  58. protected function returnMaintenance(bool $isStage = true): Page
  59. {
  60. $maintenance = $this->c->Maintenance;
  61. $maintenance->fIswev = ['w', __('Update script is running')];
  62. if ($isStage) {
  63. $maintenance->fIswev = ['e', __('Script runs error')];
  64. }
  65. return $maintenance;
  66. }
  67. /**
  68. * Проверяет наличие блокировки скрипта обновления
  69. */
  70. protected function hasLock(string $uid = null): bool
  71. {
  72. $lock = $this->c->Cache->get(self::LOCK_NAME);
  73. if (null === $uid) {
  74. return ! empty($lock);
  75. } else {
  76. return empty($lock) || ! \hash_equals($uid, (string) $lock);
  77. }
  78. }
  79. protected function setLock(string $uid = null): ?string
  80. {
  81. if (true === $this->hasLock($uid)) {
  82. return null;
  83. }
  84. if (null === $uid) {
  85. $uid = $this->c->Secury->randomHash(33);
  86. }
  87. $this->c->Cache->set(self::LOCK_NAME, $uid, self::LOCk_TTL);
  88. if (true === $this->hasLock($uid)) {
  89. return null;
  90. }
  91. return $uid;
  92. }
  93. /**
  94. * Подготавливает данные для страницы обновления форума
  95. */
  96. public function view(array $args, string $method): Page
  97. {
  98. if (true === $this->hasLock()) {
  99. return $this->returnMaintenance(false);
  100. }
  101. if (
  102. 'POST' === $method
  103. && empty($this->fIswev)
  104. ) {
  105. $v = $this->c->Validator->reset()
  106. ->addValidators([
  107. 'check_pass' => [$this, 'vCheckPass'],
  108. ])->addRules([
  109. 'token' => 'token:AdminUpdate',
  110. 'dbpass' => 'required|string:trim|check_pass',
  111. 'o_maintenance_message' => 'required|string:trim|max:65000 bytes',
  112. ])->addAliases([
  113. 'dbpass' => 'Database password',
  114. 'o_maintenance_message' => 'Maintenance message',
  115. ])->addMessages([
  116. ]);
  117. if ($v->validation($_POST)) {
  118. $e = null;
  119. // версия PHP
  120. if (
  121. null === $e
  122. && \version_compare(\PHP_VERSION, self::PHP_MIN, '<')
  123. ) {
  124. $e = __('You are running error', 'PHP', \PHP_VERSION, $this->c->FORK_REVISION, self::PHP_MIN);
  125. }
  126. // база не от ForkBB ????
  127. if (
  128. null === $e
  129. && $this->c->config->i_fork_revision < 1
  130. ) {
  131. $e = 'Version mismatch error';
  132. }
  133. // загрузка и проверка конфига
  134. if (null === $e) {
  135. try {
  136. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  137. } catch (ForkException $excp) {
  138. $e = $excp->getMessage();
  139. }
  140. }
  141. // проверка доступности базы данных на изменения
  142. if (
  143. null === $e
  144. && $this->c->config->i_fork_revision < self::LATEST_REV_WITH_DB_CHANGES
  145. ) {
  146. $test_table = 'test_tb_for_update';
  147. if (
  148. null === $e
  149. && true === $this->c->DB->tableExists($test_table)
  150. ) {
  151. $e = __('The %s table already exists. Delete it.', $test_table);
  152. }
  153. $schema = [
  154. 'FIELDS' => [
  155. 'id' => ['SERIAL', false],
  156. ],
  157. 'PRIMARY KEY' => ['id'],
  158. ];
  159. if (
  160. null === $e
  161. && false === $this->c->DB->createTable($test_table, $schema)
  162. ) {
  163. $e = __('Unable to create %s table', $test_table);
  164. }
  165. if (
  166. null === $e
  167. && false === $this->c->DB->addField($test_table, 'test_field', 'VARCHAR(80)', false, '')
  168. ) {
  169. $e = __('Unable to add test_field field to %s table', $test_table);
  170. }
  171. $sql = "INSERT INTO ::{$test_table} (test_field) VALUES ('TEST_VALUE')";
  172. if (
  173. null === $e
  174. && false === $this->c->DB->exec($sql)
  175. ) {
  176. $e = __('Unable to insert line to %s table', $test_table);
  177. }
  178. if (
  179. null === $e
  180. && false === $this->c->DB->dropField($test_table, 'test_field')
  181. ) {
  182. $e = __('Unable to drop test_field field from %s table', $test_table);
  183. }
  184. if (
  185. null === $e
  186. && false === $this->c->DB->dropTable($test_table)
  187. ) {
  188. $e = __('Unable to drop %s table', $test_table);
  189. }
  190. }
  191. if (\is_string($e)) {
  192. return $this->c->Message->message($e, true, 503);
  193. }
  194. $uid = $this->setLock();
  195. if (null === $uid) {
  196. $this->fIswev = ['e', __('Unable to write update lock')];
  197. } else {
  198. $this->c->config->o_maintenance_message = $v->o_maintenance_message;
  199. $this->c->config->save();
  200. return $this->c->Redirect->page('AdminUpdateStage', ['uid' => $uid, 'stage' => 1]);
  201. }
  202. } else {
  203. $this->fIswev = $v->getErrors();
  204. }
  205. } else {
  206. $v = null;
  207. }
  208. $this->form = $this->form($v);
  209. return $this;
  210. }
  211. /**
  212. * Проверяет пароль базы
  213. */
  214. public function vCheckPass(Validator $v, $dbpass)
  215. {
  216. if (\substr($this->c->DB_DSN, 0, 6) === 'sqlite') {
  217. if (! \hash_equals($this->c->DB_DSN, "sqlite:{$dbpass}")) { // ????
  218. $v->addError(__('Invalid file error', self::CONFIG_FILE));
  219. }
  220. } else {
  221. if (! \hash_equals($this->c->DB_PASSWORD, $dbpass)) {
  222. $v->addError(__('Invalid password error', self::CONFIG_FILE));
  223. }
  224. }
  225. return $dbpass;
  226. }
  227. /**
  228. * Формирует массив для формы
  229. */
  230. protected function form(?Validator $v): array
  231. {
  232. return [
  233. 'action' => $this->c->Router->link('AdminUpdate'),
  234. 'hidden' => [
  235. 'token' => $this->c->Csrf->create('AdminUpdate'),
  236. ],
  237. 'sets' => [
  238. 'update-info' => [
  239. 'info' => [
  240. 'info1' => [
  241. 'type' => '', //????
  242. 'value' => __('Update message'),
  243. # 'html' => true,
  244. ],
  245. ],
  246. ],
  247. 'update' => [
  248. 'legend' => __('Update ForkBB'),
  249. 'fields' => [
  250. 'dbpass' => [
  251. 'type' => 'password',
  252. 'value' => '',
  253. 'caption' => __('Database password'),
  254. 'info' => __('Database password note'),
  255. 'required' => true,
  256. ],
  257. 'o_maintenance_message' => [
  258. 'type' => 'textarea',
  259. 'value' => $v ? $v->o_maintenance_message : $this->c->config->o_maintenance_message,
  260. 'caption' => __('Maintenance message'),
  261. 'info' => __('Maintenance message info'),
  262. 'required' => true,
  263. ],
  264. ],
  265. ],
  266. 'member-info' => [
  267. 'info' => [
  268. 'info1' => [
  269. 'type' => '', //????
  270. 'value' => __('Members message'),
  271. // 'html' => true,
  272. ],
  273. ],
  274. ],
  275. ],
  276. 'btns' => [
  277. 'start' => [
  278. 'type' => 'submit',
  279. 'value' => __('Start update'),
  280. // 'accesskey' => 's',
  281. ],
  282. ],
  283. ];
  284. }
  285. /**
  286. * Обновляет форум
  287. */
  288. public function stage(array $args, string $method): Page
  289. {
  290. try {
  291. $uid = $this->setLock($args['uid']);
  292. if (null === $uid) {
  293. return $this->returnMaintenance();
  294. }
  295. $stage = \max((int) $args['stage'], (int) $this->c->config->i_fork_revision);
  296. do {
  297. if (\method_exists($this, 'stageNumber' . $stage)) {
  298. $start = $this->{'stageNumber' . $stage}($args);
  299. if (null === $start) {
  300. ++$stage;
  301. }
  302. return $this->c->Redirect->page(
  303. 'AdminUpdateStage',
  304. ['uid' => $uid, 'stage' => $stage, 'start' => $start]
  305. )->message(__('Stage %1$s (%2$s)', $stage, (int) $start));
  306. }
  307. ++$stage;
  308. } while ($stage < $this->c->FORK_REVISION);
  309. $this->c->config->i_fork_revision = $this->c->FORK_REVISION;
  310. $this->c->config->save();
  311. if (true !== $this->c->Cache->clear()) {
  312. throw new RuntimeException('Unable to clear cache');
  313. }
  314. return $this->c->Redirect->page('Index')->message('Successfully updated');
  315. } catch (ForkException $excp) {
  316. return $this->c->Message->message($excp->getMessage(), true, 503);
  317. }
  318. }
  319. # /**
  320. # * Выполняет определенный шаг обновления
  321. # *
  322. # * Возвращает null, если шаг выпонен
  323. # * Возвращает положительный int, если требуется продолжить выполнение шага
  324. # */
  325. # protected function stageNumber1(array $args): ?int
  326. # {
  327. # $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  328. #
  329. # $coreConfig->add(
  330. # 'multiple=>AdminUsersRecalculate',
  331. # '\\ForkBB\\Models\\Pages\\Admin\\Users\\Recalculate::class',
  332. # 'AdminUsersNew'
  333. # );
  334. #
  335. # $coreConfig->save();
  336. #
  337. # return null;
  338. # }
  339. /**
  340. * rev.1 to rev.2
  341. */
  342. protected function stageNumber1(array $args): ?int
  343. {
  344. $this->c->DB->alterField('users', 'gender', 'TINYINT UNSIGNED', false, 0);
  345. $this->c->DB->alterField('users', 'disp_topics', 'TINYINT UNSIGNED', false, 0);
  346. $this->c->DB->alterField('users', 'disp_posts', 'TINYINT UNSIGNED', false, 0);
  347. $this->c->DB->addField('users', 'ip_check_type', 'TINYINT UNSIGNED', false, 0);
  348. $this->c->DB->addField('users', 'login_ip_cache', 'VARCHAR(255)', false, '');
  349. return null;
  350. }
  351. /**
  352. * rev.2 to rev.3
  353. */
  354. protected function stageNumber2(array $args): ?int
  355. {
  356. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  357. $coreConfig->add(
  358. 'multiple=>AdminUsersRecalculate',
  359. '\\ForkBB\\Models\\Pages\\Admin\\Users\\Recalculate::class',
  360. 'AdminUsersNew'
  361. );
  362. $coreConfig->add(
  363. 'EOL',
  364. '\\PHP_EOL'
  365. );
  366. $coreConfig->save();
  367. return null;
  368. }
  369. /**
  370. * rev.3 to rev.4
  371. */
  372. protected function stageNumber3(array $args): ?int
  373. {
  374. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  375. $result = $coreConfig->delete(
  376. 'multiple=>AdminUsersRecalculate',
  377. );
  378. $coreConfig->add(
  379. 'multiple=>UserManagerUpdateLoginIpCache',
  380. '\\ForkBB\\Models\\User\\UpdateLoginIpCache::class',
  381. 'UserManagerUpdateCountTopics'
  382. );
  383. $coreConfig->save();
  384. return null;
  385. }
  386. /**
  387. * rev.4 to rev.5
  388. */
  389. protected function stageNumber4(array $args): ?int
  390. {
  391. unset($this->c->config->o_date_format);
  392. unset($this->c->config->o_time_format);
  393. $this->c->config->save();
  394. $query = 'UPDATE ::users
  395. SET time_format=time_format+1
  396. WHERE time_format>0';
  397. $this->c->DB->exec($query);
  398. $query = 'UPDATE ::users
  399. SET date_format=date_format+1
  400. WHERE date_format>0';
  401. $this->c->DB->exec($query);
  402. return null;
  403. }
  404. /**
  405. * rev.5 to rev.6
  406. */
  407. protected function stageNumber5(array $args): ?int
  408. {
  409. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  410. $coreConfig->add(
  411. 'multiple=>Email',
  412. '\\ForkBB\\Models\\Pages\\Email::class',
  413. 'Report'
  414. );
  415. $coreConfig->save();
  416. return null;
  417. }
  418. /**
  419. * rev.6 to rev.7
  420. */
  421. protected function stageNumber6(array $args): ?int
  422. {
  423. $this->c->DB->addField('groups', 'g_sig_use', 'TINYINT(1)', false, 1);
  424. $this->c->DB->addField('groups', 'g_sig_length', 'SMALLINT UNSIGNED', false, 400);
  425. $this->c->DB->addField('groups', 'g_sig_lines', 'TINYINT UNSIGNED', false, 4);
  426. $vars = [
  427. ':sig_use' => '1' == $this->c->config->o_signatures ? 1 : 0,
  428. ':sig_length' => $this->c->config->p_sig_length > 10000 ? 10000 : (int) $this->c->config->p_sig_length,
  429. ':sig_lines' => $this->c->config->p_sig_lines> 255 ? 255 : (int) $this->c->config->p_sig_lines,
  430. ];
  431. $query = 'UPDATE ::groups
  432. SET g_sig_use=?i:sig_use, g_sig_length=?i:sig_length, g_sig_lines=?i:sig_lines';
  433. $this->c->DB->query($query, $vars);
  434. $vars = [
  435. ':grp' => $this->c->GROUP_ADMIN,
  436. ];
  437. $query = 'UPDATE ::groups
  438. SET g_sig_use=1, g_sig_length=10000, g_sig_lines=255
  439. WHERE g_id=?i:grp';
  440. $this->c->DB->query($query, $vars);
  441. $vars = [
  442. ':grp' => $this->c->GROUP_GUEST,
  443. ];
  444. $query = 'UPDATE ::groups
  445. SET g_sig_use=0, g_sig_length=0, g_sig_lines=0
  446. WHERE g_id=?i:grp';
  447. $this->c->DB->query($query, $vars);
  448. unset($this->c->config->o_signatures);
  449. unset($this->c->config->p_sig_length);
  450. unset($this->c->config->p_sig_lines);
  451. $this->c->config->save();
  452. return null;
  453. }
  454. /**
  455. * rev.7 to rev.8
  456. */
  457. protected function stageNumber7(array $args): ?int
  458. {
  459. $this->c->DB->dropField('groups', 'g_sig_use');
  460. return null;
  461. }
  462. /**
  463. * rev.8 to rev.9
  464. */
  465. protected function stageNumber8(array $args): ?int
  466. {
  467. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  468. $coreConfig->add(
  469. 'multiple=>Feed',
  470. '\\ForkBB\\Models\\Pages\\Feed::class',
  471. 'Email'
  472. );
  473. $coreConfig->add(
  474. 'multiple=>PostManagerFeed',
  475. '\\ForkBB\\Models\\Post\\Feed::class',
  476. 'PostManagerMove'
  477. );
  478. $coreConfig->save();
  479. return null;
  480. }
  481. /**
  482. * rev.9 to rev.10
  483. */
  484. protected function stageNumber9(array $args): ?int
  485. {
  486. $this->c->config->i_email_max_recipients = 1;
  487. $this->c->config->save();
  488. return null;
  489. }
  490. /**
  491. * rev.10 to rev.11
  492. */
  493. protected function stageNumber10(array $args): ?int
  494. {
  495. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  496. $coreConfig->add(
  497. 'shared=>subscriptions',
  498. '\\ForkBB\\Models\\Subscription\\Model::class',
  499. 'search'
  500. );
  501. $coreConfig->save();
  502. return null;
  503. }
  504. /**
  505. * rev.11 to rev.12
  506. */
  507. protected function stageNumber11(array $args): ?int
  508. {
  509. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  510. $coreConfig->add(
  511. 'multiple=>SearchModelActionF',
  512. '\\ForkBB\\Models\\Search\\ActionF::class',
  513. 'SearchModelActionT'
  514. );
  515. $coreConfig->save();
  516. return null;
  517. }
  518. /**
  519. * rev.12 to rev.13
  520. */
  521. protected function stageNumber12(array $args): ?int
  522. {
  523. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  524. $coreConfig->add(
  525. 'shared=>SubscriptionModelSend',
  526. '\\ForkBB\\Models\\Subscription\\Send::class'
  527. );
  528. $result = $coreConfig->delete(
  529. 'multiple=>BanListModelIsBanned',
  530. );
  531. $coreConfig->add(
  532. 'shared=>BanListModelIsBanned',
  533. '\\ForkBB\\Models\\BanList\\IsBanned::class'
  534. );
  535. $coreConfig->save();
  536. return null;
  537. }
  538. /**
  539. * rev.13 to rev.14
  540. */
  541. protected function stageNumber13(array $args): ?int
  542. {
  543. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  544. $result = $coreConfig->delete(
  545. 'multiple=>AdminPermissions',
  546. );
  547. $coreConfig->add(
  548. 'multiple=>AdminParser',
  549. '\\ForkBB\\Models\\Pages\\Admin\\Parser\\Edit::class',
  550. 'AdminReports'
  551. );
  552. $coreConfig->add(
  553. 'multiple=>AdminParserSmilies',
  554. '\\ForkBB\\Models\\Pages\\Admin\\Parser\\Smilies::class',
  555. 'AdminParser'
  556. );
  557. $coreConfig->add(
  558. 'multiple=>AdminParserBBCode',
  559. '\\ForkBB\\Models\\Pages\\Admin\\Parser\\BBCode::class',
  560. 'AdminParserSmilies'
  561. );
  562. $coreConfig->save();
  563. return null;
  564. }
  565. /**
  566. * rev.14 to rev.15
  567. */
  568. protected function stageNumber14(array $args): ?int
  569. {
  570. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  571. $result = $coreConfig->delete(
  572. 'multiple=>SmileyListModelLoad',
  573. );
  574. $coreConfig->add(
  575. 'shared=>SmileyListModelLoad',
  576. '\\ForkBB\\Models\\SmileyList\\Load::class'
  577. );
  578. $coreConfig->add(
  579. 'shared=>SmileyListModelUpdate',
  580. '\\ForkBB\\Models\\SmileyList\\Update::class'
  581. );
  582. $coreConfig->add(
  583. 'shared=>SmileyListModelInsert',
  584. '\\ForkBB\\Models\\SmileyList\\Insert::class'
  585. );
  586. $coreConfig->add(
  587. 'shared=>SmileyListModelDelete',
  588. '\\ForkBB\\Models\\SmileyList\\Delete::class'
  589. );
  590. $coreConfig->save();
  591. $this->c->DB->renameField('smilies', 'image', 'sm_image');
  592. $this->c->DB->renameField('smilies', 'text', 'sm_code');
  593. $this->c->DB->renameField('smilies', 'disp_position', 'sm_position');
  594. $this->c->DB->alterField('smilies', 'sm_position', 'INT(10) UNSIGNED', false, 0);
  595. return null;
  596. }
  597. /**
  598. * rev.15 to rev.16
  599. */
  600. protected function stageNumber15(array $args): ?int
  601. {
  602. // bbcode
  603. $schema = [
  604. 'FIELDS' => [
  605. 'id' => ['SERIAL', false],
  606. 'bb_tag' => ['VARCHAR(11)', false, ''],
  607. 'bb_edit' => ['TINYINT(1)', false, 1],
  608. 'bb_delete' => ['TINYINT(1)', false, 1],
  609. 'bb_structure' => ['MEDIUMTEXT', false],
  610. ],
  611. 'PRIMARY KEY' => ['id'],
  612. 'UNIQUE KEYS' => [
  613. 'bb_tag_idx' => ['bb_tag'],
  614. ],
  615. ];
  616. $this->c->DB->createTable('bbcode', $schema);
  617. $query = 'INSERT INTO ::bbcode (bb_tag, bb_edit, bb_delete, bb_structure)
  618. VALUES(?s:tag, 1, 0, ?s:structure)';
  619. $bbcodes = include $this->c->DIR_CONFIG . '/defaultBBCode.php';
  620. foreach ($bbcodes as $bbcode) {
  621. $vars = [
  622. ':tag' => $bbcode['tag'],
  623. ':structure' => \json_encode($bbcode, self::JSON_OPTIONS),
  624. ];
  625. $this->c->DB->exec($query, $vars);
  626. }
  627. $this->c->config->a_bb_white_mes = [];
  628. $this->c->config->a_bb_white_sig = ['b', 'i', 'u', 'color', 'colour', 'email', 'url'];
  629. $this->c->config->a_bb_black_mes = [];
  630. $this->c->config->a_bb_black_sig = [];
  631. unset($this->c->config->o_quote_depth);
  632. unset($this->c->config->p_sig_img_tag);
  633. unset($this->c->config->p_message_img_tag);
  634. $this->c->config->save();
  635. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  636. $result = $coreConfig->delete(
  637. 'BBCODE_INFO=>forSign',
  638. );
  639. $coreConfig->add(
  640. 'shared=>bbcode',
  641. '\'@BBCodeListModel:init\'',
  642. 'subscriptions'
  643. );
  644. $coreConfig->add(
  645. 'shared=>BBCodeListModel',
  646. [
  647. 'class' => '\\ForkBB\\Models\\BBCodeList\\Model::class',
  648. 'file' => '\'defaultBBCode.php\'',
  649. ]
  650. );
  651. $coreConfig->add(
  652. 'shared=>BBCodeListModelGenerate',
  653. '\\ForkBB\\Models\\BBCodeList\\Generate::class'
  654. );
  655. $coreConfig->add(
  656. 'shared=>BBCodeListModelLoad',
  657. '\\ForkBB\\Models\\BBCodeList\\Load::class'
  658. );
  659. $coreConfig->add(
  660. 'shared=>BBCodeListModelUpdate',
  661. '\\ForkBB\\Models\\BBCodeList\\Update::class'
  662. );
  663. $coreConfig->add(
  664. 'shared=>BBCodeListModelInsert',
  665. '\\ForkBB\\Models\\BBCodeList\\Insert::class'
  666. );
  667. $coreConfig->add(
  668. 'shared=>BBCodeListModelDelete',
  669. '\\ForkBB\\Models\\BBCodeList\\Delete::class'
  670. );
  671. $coreConfig->save();
  672. return null;
  673. }
  674. /**
  675. * rev.16 to rev.17
  676. */
  677. protected function stageNumber16(array $args): ?int
  678. {
  679. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  680. $coreConfig->add(
  681. 'shared=>Router=>csrf',
  682. '\'@Csrf\''
  683. );
  684. $coreConfig->save();
  685. return null;
  686. }
  687. /**
  688. * rev.17 to rev.18
  689. */
  690. protected function stageNumber17(array $args): ?int
  691. {
  692. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  693. $coreConfig->add(
  694. 'multiple=>BBStructure',
  695. '\\ForkBB\\Models\\BBCodeList\\Structure::class'
  696. );
  697. $coreConfig->save();
  698. return null;
  699. }
  700. /**
  701. * rev.18 to rev.19
  702. */
  703. protected function stageNumber18(array $args): ?int
  704. {
  705. $this->c->DB->addField('users', 'avatar', 'VARCHAR(30)', false, '', 'title');
  706. $dir = $this->c->DIR_PUBLIC . $this->c->config->o_avatars_dir . '/';
  707. $avatars = [];
  708. if (
  709. \is_dir($dir)
  710. && false !== ($dh = \opendir($dir))
  711. ) {
  712. while (false !== ($entry = \readdir($dh))) {
  713. if (
  714. \preg_match('%^([1-9]\d*)\.(jpg|gif|png)$%D', $entry, $matches)
  715. && \is_file($dir . $entry)
  716. ) {
  717. $avatars[$matches[2]][] = (int) $matches[1];
  718. }
  719. }
  720. \closedir($dh);
  721. }
  722. $query = 'UPDATE ::users
  723. SET avatar=CONCAT(id, \'.\', ?s:ext)
  724. WHERE id IN (?ai:ids)';
  725. foreach ($avatars as $ext => $ids) {
  726. $vars = [
  727. ':ext' => $ext,
  728. ':ids' => $ids,
  729. ];
  730. $this->c->DB->exec($query, $vars);
  731. }
  732. return null;
  733. }
  734. /**
  735. * rev.19 to rev.20
  736. */
  737. protected function stageNumber19(array $args): ?int
  738. {
  739. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  740. $result = $coreConfig->delete(
  741. 'shared=>FileCache',
  742. );
  743. $coreConfig->add(
  744. 'shared=>Cache',
  745. $result
  746. );
  747. $coreConfig->save();
  748. return null;
  749. }
  750. /**
  751. * rev.20 to rev.21
  752. */
  753. protected function stageNumber20(array $args): ?int
  754. {
  755. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  756. $coreConfig->add(
  757. 'shared=>Test',
  758. '\\ForkBB\\Core\\Test::class',
  759. 'Func'
  760. );
  761. $coreConfig->save();
  762. return null;
  763. }
  764. /**
  765. * rev.21 to rev.22
  766. */
  767. protected function stageNumber21(array $args): ?int
  768. {
  769. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  770. $coreConfig->add(
  771. 'USERNAME_PATTERN',
  772. '\'%^(?=.{2,25}$)\\p{L}[\\p{L}\\p{N}\\x20\\._-]+$%uD\'',
  773. 'FLOOD_INTERVAL'
  774. );
  775. $coreConfig->save();
  776. return null;
  777. }
  778. /**
  779. * rev.22 to rev.23
  780. */
  781. protected function stageNumber22(array $args): ?int
  782. {
  783. $this->c->config->i_topic_review = $this->c->config->o_topic_review ?? 15;
  784. $this->c->config->i_disp_topics_default = $this->c->config->o_disp_topics_default ?? 30;
  785. $this->c->config->i_disp_posts_default = $this->c->config->o_disp_posts_default ?? 25;
  786. $this->c->config->i_disp_users = $this->c->config->o_disp_users ?? 50;
  787. $this->c->config->i_default_email_setting = $this->c->config->o_default_email_setting ?? 2;
  788. $this->c->config->i_avatars_width = $this->c->config->o_avatars_width ?? 60;
  789. $this->c->config->i_avatars_height = $this->c->config->o_avatars_height ?? 60;
  790. $this->c->config->i_avatars_size = $this->c->config->o_avatars_size ?? 10240;
  791. $this->c->config->i_feed_type = $this->c->config->o_feed_type ?? 2;
  792. $this->c->config->i_feed_ttl = $this->c->config->o_feed_ttl ?? 0;
  793. $this->c->config->i_report_method = $this->c->config->o_report_method ?? 0;
  794. $this->c->config->i_default_user_group = $this->c->config->o_default_user_group ?? $this->c->GROUP_MEMBER;
  795. $this->c->config->a_max_users = [
  796. 'number' => (int) $this->c->config->st_max_users ?? 1,
  797. 'time' => (int) $this->c->config->st_max_users_time ?? \time(),
  798. ];
  799. unset($this->c->config->o_enable_acaptcha);
  800. unset($this->c->config->o_crypto_salt);
  801. unset($this->c->config->o_crypto_pas);
  802. unset($this->c->config->o_crypto_enable);
  803. unset($this->c->config->o_check_ip);
  804. unset($this->c->config->o_coding_forms);
  805. unset($this->c->config->o_fbox_files);
  806. unset($this->c->config->o_fbox_guest);
  807. unset($this->c->config->o_show_version);
  808. unset($this->c->config->o_topic_review);
  809. unset($this->c->config->o_disp_topics_default);
  810. unset($this->c->config->o_disp_posts_default);
  811. unset($this->c->config->o_disp_users);
  812. unset($this->c->config->o_default_email_setting);
  813. unset($this->c->config->o_avatars_width);
  814. unset($this->c->config->o_avatars_height);
  815. unset($this->c->config->o_avatars_size);
  816. unset($this->c->config->o_feed_type);
  817. unset($this->c->config->o_feed_ttl);
  818. unset($this->c->config->o_report_method);
  819. unset($this->c->config->o_board_redirect);
  820. unset($this->c->config->o_board_redirectg);
  821. unset($this->c->config->o_default_user_group);
  822. unset($this->c->config->st_max_users);
  823. unset($this->c->config->st_max_users_time);
  824. $this->c->config->save();
  825. return null;
  826. }
  827. /**
  828. * rev.23 to rev.24
  829. */
  830. protected function stageNumber23(array $args): ?int
  831. {
  832. $this->c->DB->addField('forums', 'last_poster_id', 'INT(10) UNSIGNED', false, 0, 'last_poster');
  833. $query = 'UPDATE ::forums AS f
  834. SET f.last_poster_id=COALESCE((
  835. SELECT u.id
  836. FROM ::users AS u
  837. WHERE u.username=f.last_poster AND u.id>1
  838. ), 0)';
  839. $this->c->DB->exec($query);
  840. $this->c->DB->renameField('posts', 'edited_by', 'editor');
  841. $this->c->DB->addField('posts', 'editor_id', 'INT(10) UNSIGNED', false, 0, 'editor');
  842. $query = 'UPDATE ::posts AS p
  843. SET p.editor_id=COALESCE((
  844. SELECT u.id
  845. FROM ::users AS u
  846. WHERE u.username=p.editor AND u.id>1
  847. ), 0)';
  848. $this->c->DB->exec($query);
  849. unset($this->c->config->o_merge_timeout);
  850. $this->c->config->save();
  851. return null;
  852. }
  853. /**
  854. * rev.24 to rev.25
  855. */
  856. protected function stageNumber24(array $args): ?int
  857. {
  858. $coreConfig = new CoreConfig($this->c->DIR_CONFIG . '/' . self::CONFIG_FILE);
  859. $coreConfig->add(
  860. 'multiple=>ForumManagerUpdateUsername',
  861. '\\ForkBB\\Models\\Forum\\UpdateUsername::class',
  862. 'ForumManagerMarkread'
  863. );
  864. $coreConfig->add(
  865. 'multiple=>PostManagerUpdateUsername',
  866. '\\ForkBB\\Models\\Post\\UpdateUsername::class',
  867. 'PostManagerFeed'
  868. );
  869. $coreConfig->save();
  870. return null;
  871. }
  872. }