Install.php 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Pages\Admin;
  10. use ForkBB\Core\Validator;
  11. use ForkBB\Models\Page;
  12. use ForkBB\Models\Pages\Admin;
  13. use PDO;
  14. use PDOException;
  15. use RuntimeException;
  16. use function \ForkBB\__;
  17. class Install extends Admin
  18. {
  19. const PHP_MIN = '7.3.0';
  20. const MYSQL_MIN = '5.5.3';
  21. const SQLITE_MIN = '3.25.0';
  22. const PGSQL_MIN = '10.0';
  23. const JSON_OPTIONS = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR;
  24. /**
  25. * Для MySQL
  26. * @var string
  27. */
  28. protected $DBEngine = '';
  29. /**
  30. * Подготовка страницы к отображению
  31. */
  32. public function prepare(): void
  33. {
  34. }
  35. /**
  36. * Возращает доступные типы БД
  37. */
  38. protected function DBTypes(): array
  39. {
  40. $dbTypes = [];
  41. $pdoDrivers = PDO::getAvailableDrivers();
  42. foreach ($pdoDrivers as $type) {
  43. if (\is_file($this->c->DIR_APP . '/Core/DB/' . \ucfirst($type) . '.php')) {
  44. switch ($type) {
  45. case 'mysql':
  46. $dbTypes['mysql_innodb'] = 'MySQL InnoDB (PDO)';
  47. $dbTypes[$type] = 'MySQL (PDO) (no transactions!)';
  48. break;
  49. case 'sqlite':
  50. $dbTypes[$type] = 'SQLite (PDO)';
  51. break;
  52. case 'pgsql':
  53. $dbTypes[$type] = 'PostgreSQL (PDO)';
  54. break;
  55. default:
  56. $dbTypes[$type] = \ucfirst($type) . ' (PDO)';
  57. break;
  58. }
  59. }
  60. }
  61. return $dbTypes;
  62. }
  63. /**
  64. * Подготовка данных для страницы установки форума
  65. */
  66. public function install(array $args, string $method): Page
  67. {
  68. $changeLang = false;
  69. if ('POST' === $method) {
  70. $v = $this->c->Validator->reset()
  71. ->addRules([
  72. 'token' => 'token:Install',
  73. 'installlang' => 'required|string:trim',
  74. 'changelang' => 'string', // не нужно required
  75. ]);
  76. if ($v->validation($_POST)) {
  77. $this->user->language = $v->installlang;
  78. $changeLang = (bool) $v->changelang;
  79. }
  80. }
  81. $v = null;
  82. $this->c->Lang->load('validator');
  83. $this->c->Lang->load('admin_install');
  84. // версия PHP
  85. if (\version_compare(\PHP_VERSION, self::PHP_MIN, '<')) {
  86. $this->fIswev = ['e', ['You are running error', 'PHP', \PHP_VERSION, $this->c->FORK_REVISION, self::PHP_MIN]];
  87. }
  88. // типы БД
  89. $this->dbTypes = $this->DBTypes();
  90. if (empty($this->dbTypes)) {
  91. $this->fIswev = ['e', 'No DB extensions'];
  92. }
  93. // доступность папок на запись
  94. $folders = [
  95. $this->c->DIR_CONFIG,
  96. $this->c->DIR_CONFIG . '/db',
  97. $this->c->DIR_CACHE,
  98. $this->c->DIR_PUBLIC . '/img/avatars',
  99. ];
  100. foreach ($folders as $folder) {
  101. if (! \is_writable($folder)) {
  102. $folder = \str_replace(\dirname($this->c->DIR_APP), '', $folder);
  103. $this->fIswev = ['e', ['Alert folder %s', $folder]];
  104. }
  105. }
  106. // доступность шаблона конфигурации
  107. $config = \file_get_contents($this->c->DIR_CONFIG . '/main.dist.php');
  108. if (false === $config) {
  109. $this->fIswev = ['e', 'No access to main.dist.php'];
  110. }
  111. unset($config);
  112. // языки
  113. $langs = $this->c->Func->getNameLangs();
  114. if (empty($langs)) {
  115. $this->fIswev = ['e', 'No language packs'];
  116. }
  117. // стили
  118. $styles = $this->c->Func->getStyles();
  119. if (empty($styles)) {
  120. $this->fIswev = ['e', 'No styles'];
  121. }
  122. if (
  123. 'POST' === $method
  124. && ! $changeLang
  125. && empty($this->fIswev['e'])
  126. ) { //????
  127. $v = $this->c->Validator->reset()
  128. ->addValidators([
  129. 'check_prefix' => [$this, 'vCheckPrefix'],
  130. 'check_host' => [$this, 'vCheckHost'],
  131. 'rtrim_url' => [$this, 'vRtrimURL']
  132. ])->addRules([
  133. 'token' => 'token:Install',
  134. 'dbtype' => 'required|string:trim|in:' . \implode(',', \array_keys($this->dbTypes)),
  135. 'dbhost' => 'required|string:trim|check_host',
  136. 'dbname' => 'required|string:trim',
  137. 'dbuser' => 'exist|string:trim',
  138. 'dbpass' => 'exist|string:trim',
  139. 'dbprefix' => 'required|string:trim|min:1|max:40|check_prefix',
  140. 'username' => 'required|string:trim|min:2|max:25',
  141. 'password' => 'required|string|min:16|max:100000|password',
  142. 'email' => 'required|string:trim|email',
  143. 'title' => 'required|string:trim|max:255',
  144. 'descr' => 'exist|string:trim,empty|max:65000 bytes|html',
  145. 'baseurl' => 'required|string:trim|rtrim_url|max:128',
  146. 'defaultlang' => 'required|string:trim|in:' . \implode(',', $this->c->Func->getLangs()),
  147. 'defaultstyle' => 'required|string:trim|in:' . \implode(',', $this->c->Func->getStyles()),
  148. 'cookie_domain' => 'exist|string:trim|max:128',
  149. 'cookie_path' => 'required|string:trim|max:1024',
  150. 'cookie_secure' => 'required|integer|in:0,1',
  151. ])->addAliases([
  152. 'dbtype' => 'Database type',
  153. 'dbhost' => 'Database server hostname',
  154. 'dbname' => 'Database name',
  155. 'dbuser' => 'Database username',
  156. 'dbpass' => 'Database password',
  157. 'dbprefix' => 'Table prefix',
  158. 'username' => 'Administrator username',
  159. 'password' => 'Administrator passphrase',
  160. 'title' => 'Board title',
  161. 'descr' => 'Board description',
  162. 'baseurl' => 'Base URL',
  163. 'defaultlang' => 'Default language',
  164. 'defaultstyle' => 'Default style',
  165. 'cookie_domain' => 'Cookie Domain',
  166. 'cookie_path' => 'Cookie Path',
  167. 'cookie_secure' => 'Cookie Secure',
  168. ])->addMessages([
  169. 'email' => 'Wrong email',
  170. ]);
  171. if ($v->validation($_POST)) {
  172. return $this->installEnd($v);
  173. } else {
  174. $this->fIswev = $v->getErrors();
  175. }
  176. }
  177. if (\count($langs) > 1) {
  178. $this->form1 = [
  179. 'action' => $this->c->Router->link('Install'),
  180. 'hidden' => [
  181. 'token' => $this->c->Csrf->create('Install'),
  182. ],
  183. 'sets' => [
  184. 'dlang' => [
  185. 'fields' => [
  186. 'installlang' => [
  187. 'type' => 'select',
  188. 'options' => $langs,
  189. 'value' => $this->user->language,
  190. 'caption' => 'Install language',
  191. 'help' => 'Choose install language info',
  192. ],
  193. ],
  194. ],
  195. ],
  196. 'btns' => [
  197. 'changelang' => [
  198. 'type' => 'submit',
  199. 'value' => __('Change language'),
  200. ],
  201. ],
  202. ];
  203. }
  204. $this->form2 = [
  205. 'action' => $this->c->Router->link('Install'),
  206. 'hidden' => [
  207. 'token' => $this->c->Csrf->create('Install'),
  208. 'installlang' => $this->user->language,
  209. ],
  210. 'sets' => [
  211. 'db-info' => [
  212. 'info' => [
  213. [
  214. 'value' => __('Database setup'),
  215. 'html' => true,
  216. ],
  217. [
  218. 'value' => __('Info 1'),
  219. ],
  220. ],
  221. ],
  222. 'db' => [
  223. 'fields' => [
  224. 'dbtype' => [
  225. 'type' => 'select',
  226. 'options' => $this->dbTypes,
  227. 'value' => $v->dbtype ?? 'mysql_innodb',
  228. 'caption' => 'Database type',
  229. 'help' => 'Info 2',
  230. ],
  231. 'dbhost' => [
  232. 'type' => 'text',
  233. 'value' => $v->dbhost ?? 'localhost',
  234. 'caption' => 'Database server hostname',
  235. 'help' => 'Info 3',
  236. 'required' => true,
  237. ],
  238. 'dbname' => [
  239. 'type' => 'text',
  240. 'value' => $v->dbname ?? '',
  241. 'caption' => 'Database name',
  242. 'help' => 'Info 4',
  243. 'required' => true,
  244. ],
  245. 'dbuser' => [
  246. 'type' => 'text',
  247. 'value' => $v->dbuser ?? '',
  248. 'caption' => 'Database username',
  249. ],
  250. 'dbpass' => [
  251. 'type' => 'password',
  252. 'value' => '',
  253. 'caption' => 'Database password',
  254. 'help' => 'Info 5',
  255. ],
  256. 'dbprefix' => [
  257. 'type' => 'text',
  258. 'maxlength' => '40',
  259. 'value' => $v->dbprefix ?? '',
  260. 'caption' => 'Table prefix',
  261. 'help' => 'Info 6',
  262. 'required' => true,
  263. ],
  264. ],
  265. ],
  266. 'adm-info' => [
  267. 'info' => [
  268. [
  269. 'value' => __('Administration setup'),
  270. 'html' => true,
  271. ],
  272. [
  273. 'value' => __('Info 7'),
  274. ],
  275. ],
  276. ],
  277. 'adm' => [
  278. 'fields' => [
  279. 'username' => [
  280. 'type' => 'text',
  281. 'maxlength' => '25',
  282. 'pattern' => '^.{2,25}$',
  283. 'value' => $v->username ?? '',
  284. 'caption' => 'Administrator username',
  285. 'help' => 'Info 8',
  286. 'required' => true,
  287. ],
  288. 'password' => [
  289. 'type' => 'password',
  290. 'pattern' => '^.{16,}$',
  291. 'value' => '',
  292. 'caption' => 'Administrator passphrase',
  293. 'help' => 'Info 9',
  294. 'required' => true,
  295. ],
  296. 'email' => [
  297. 'type' => 'text',
  298. 'maxlength' => '80',
  299. 'pattern' => '.+@.+',
  300. 'value' => $v->email ?? '',
  301. 'caption' => 'Administrator email',
  302. 'help' => 'Info 10',
  303. 'required' => true,
  304. ],
  305. ],
  306. ],
  307. 'board-info' => [
  308. 'info' => [
  309. [
  310. 'value' => __('Board setup'),
  311. 'html' => true,
  312. ],
  313. [
  314. 'value' => __('Info 11'),
  315. ],
  316. ],
  317. ],
  318. 'board' => [
  319. 'fields' => [
  320. 'title' => [
  321. 'type' => 'text',
  322. 'maxlength' => '255',
  323. 'value' => $v->title ?? __('My ForkBB Forum'),
  324. 'caption' => 'Board title',
  325. 'required' => true,
  326. ],
  327. 'descr' => [
  328. 'type' => 'text',
  329. 'maxlength' => '16000',
  330. 'value' => $v->descr ?? __('Description'),
  331. 'caption' => 'Board description',
  332. ],
  333. 'baseurl' => [
  334. 'type' => 'text',
  335. 'maxlength' => '128',
  336. 'value' => $v->baseurl ?? $this->c->BASE_URL,
  337. 'caption' => 'Base URL',
  338. 'required' => true,
  339. ],
  340. 'defaultlang' => [
  341. 'type' => 'select',
  342. 'options' => $langs,
  343. 'value' => $v->defaultlang ?? $this->user->language,
  344. 'caption' => 'Default language',
  345. ],
  346. 'defaultstyle' => [
  347. 'type' => 'select',
  348. 'options' => $styles,
  349. 'value' => $v->defaultstyle ?? $this->user->style,
  350. 'caption' => 'Default style',
  351. ],
  352. ],
  353. ],
  354. 'cookie-info' => [
  355. 'info' => [
  356. [
  357. 'value' => __('Cookie setup'),
  358. 'html' => true,
  359. ],
  360. [
  361. 'value' => __('Info 12'),
  362. ],
  363. ],
  364. ],
  365. 'cookie' => [
  366. 'fields' => [
  367. 'cookie_domain' => [
  368. 'type' => 'text',
  369. 'maxlength' => '128',
  370. 'value' => $v->cookie_domain ?? '',
  371. 'caption' => 'Cookie Domain',
  372. 'help' => 'Cookie Domain info',
  373. ],
  374. 'cookie_path' => [
  375. 'type' => 'text',
  376. 'maxlength' => '1024',
  377. 'value' => $v
  378. ? $v->cookie_path
  379. : \rtrim((string) \parse_url($this->c->BASE_URL, \PHP_URL_PATH), '/') . '/',
  380. 'caption' => 'Cookie Path',
  381. 'help' => 'Cookie Path info',
  382. 'required' => true,
  383. ],
  384. 'cookie_secure' => [
  385. 'type' => 'radio',
  386. 'value' => $v
  387. ? $v->cookie_secure
  388. : (
  389. \preg_match('%^https%i', $this->c->BASE_URL)
  390. ? 1
  391. : 0
  392. ),
  393. 'values' => [1 => __('Yes '), 0 => __('No ')],
  394. 'caption' => 'Cookie Secure',
  395. 'help' => 'Cookie Secure info',
  396. ],
  397. ],
  398. ],
  399. ],
  400. 'btns' => [
  401. 'submit' => [
  402. 'type' => 'submit',
  403. 'value' => __('Start install'),
  404. ],
  405. ],
  406. ];
  407. $this->nameTpl = 'layouts/install';
  408. $this->onlinePos = null;
  409. $this->rev = $this->c->FORK_REVISION;
  410. return $this;
  411. }
  412. /**
  413. * Обработка base URL
  414. */
  415. public function vRtrimURL(Validator $v, string $url): string
  416. {
  417. return \rtrim($url, '/');
  418. }
  419. /**
  420. * Дополнительная проверка префикса
  421. */
  422. public function vCheckPrefix(Validator $v, string $prefix): string
  423. {
  424. if (! \preg_match('%^[a-z][a-z\d_]*$%i', $prefix)) {
  425. $v->addError('Table prefix error');
  426. } elseif (
  427. 'sqlite_' === \strtolower($prefix)
  428. || 'pg_' === \strtolower($prefix)
  429. ) {
  430. $v->addError('Prefix reserved');
  431. }
  432. return $prefix;
  433. }
  434. /**
  435. * Полная проверка подключения к БД
  436. */
  437. public function vCheckHost(Validator $v, string $dbhost): string
  438. {
  439. $this->c->DB_USERNAME = $v->dbuser;
  440. $this->c->DB_PASSWORD = $v->dbpass;
  441. $this->c->DB_OPTIONS = [];
  442. $this->c->DB_OPTS_AS_STR = '';
  443. $this->c->DB_PREFIX = $v->dbprefix;
  444. $dbtype = $v->dbtype;
  445. $dbname = $v->dbname;
  446. // есть ошибки, ни чего не проверяем
  447. if (! empty($v->getErrors())) {
  448. return $dbhost;
  449. }
  450. // настройки подключения БД
  451. $DBEngine = 'MyISAM';
  452. switch ($dbtype) {
  453. case 'mysql_innodb':
  454. $DBEngine = 'InnoDB';
  455. case 'mysql':
  456. $this->DBEngine = $DBEngine;
  457. if (\preg_match('%^([^:]+):(\d+)$%', $dbhost, $matches)) {
  458. $this->c->DB_DSN = "mysql:host={$matches[1]};port={$matches[2]};dbname={$dbname};charset=utf8mb4";
  459. } else {
  460. $this->c->DB_DSN = "mysql:host={$dbhost};dbname={$dbname};charset=utf8mb4";
  461. }
  462. break;
  463. case 'sqlite':
  464. $this->c->DB_DSN = "sqlite:!PATH!{$dbname}";
  465. $this->c->DB_OPTS_AS_STR = "\n"
  466. . ' \\PDO::ATTR_TIMEOUT => 5,' . "\n"
  467. . ' /* \'initSQLCommands\' => [\'PRAGMA journal_mode=WAL\',], */' . "\n"
  468. . ' \'initFunction\' => function ($db) {return $db->sqliteCreateFunction(\'CONCAT\', function (...$args) {return \\implode(\'\', $args);});},' . "\n"
  469. . ' ';
  470. $this->c->DB_OPTIONS = [
  471. PDO::ATTR_TIMEOUT => 5,
  472. 'initSQLCommands' => [
  473. 'PRAGMA journal_mode=WAL',
  474. ],
  475. 'initFunction' => function ($db) {return $db->sqliteCreateFunction('CONCAT', function (...$args) {return \implode('', $args);});},
  476. ];
  477. break;
  478. case 'pgsql':
  479. if (\preg_match('%^([^:]+):(\d+)$%', $dbhost, $matches)) {
  480. $host = $matches[1];
  481. $port = $matches[2];
  482. } else {
  483. $host = $dbhost;
  484. $port = '5432';
  485. }
  486. $this->c->DB_DSN = "pgsql:host={$host} port={$port} dbname={$dbname} options='--client_encoding=UTF8'";
  487. break;
  488. default:
  489. //????
  490. break;
  491. }
  492. // подключение к БД
  493. try {
  494. $stat = $this->c->DB->statistics();
  495. } catch (PDOException $e) {
  496. $v->addError($e->getMessage());
  497. return $dbhost;
  498. }
  499. $version = $versionNeed = $this->c->DB->getAttribute(PDO::ATTR_SERVER_VERSION);
  500. switch ($dbtype) {
  501. case 'mysql_innodb':
  502. case 'mysql':
  503. $versionNeed = self::MYSQL_MIN;
  504. $progName = 'MySQL';
  505. break;
  506. case 'sqlite':
  507. $versionNeed = self::SQLITE_MIN;
  508. $progName = 'SQLite';
  509. break;
  510. case 'pgsql':
  511. $versionNeed = self::PGSQL_MIN;
  512. $progName = 'PostgreSQL';
  513. break;
  514. }
  515. if (\version_compare($version, $versionNeed, '<')) {
  516. $v->addError(['You are running error', $progName, $version, $this->c->FORK_REVISION, $versionNeed]);
  517. return $dbhost;
  518. }
  519. // проверка наличия таблиц в БД
  520. if (
  521. '' != $stat['tables']
  522. && '0' != $stat['tables']
  523. ) {
  524. $v->addError(['Existing table error', $v->dbprefix, $v->dbname, $stat['tables']]);
  525. return $dbhost;
  526. }
  527. // база MySQL, кодировка базы отличается от UTF-8 (4 байта)
  528. if (
  529. isset($stat['character_set_database'])
  530. && 'utf8mb4' !== $stat['character_set_database']
  531. ) {
  532. $v->addError('Bad database charset');
  533. }
  534. // база PostgreSQL, кодировка базы
  535. if (
  536. isset($stat['server_encoding'])
  537. && 'UTF8' !== $stat['server_encoding']
  538. ) {
  539. $v->addError(['Bad database encoding', 'UTF8']);
  540. }
  541. // база PostgreSQL, порядок сопоставления/сортировки
  542. if (
  543. isset($stat['lc_collate'])
  544. && 'C' !== $stat['lc_collate']
  545. ) {
  546. $v->addError('Bad database collate');
  547. }
  548. // база PostgreSQL, тип символов
  549. if (
  550. isset($stat['lc_ctype'])
  551. && 'C' !== $stat['lc_ctype']
  552. ) {
  553. $v->addError('Bad database ctype');
  554. }
  555. // база SQLite, кодировка базы
  556. if (
  557. isset($stat['encoding'])
  558. && 'UTF-8' !== $stat['encoding']
  559. ) {
  560. $v->addError(['Bad database encoding', 'UTF-8']);
  561. }
  562. // тест типа возвращаемого результата
  563. $table = '::tmp_test';
  564. $schema = [
  565. 'FIELDS' => [
  566. 'test_field' => ['INT(10) UNSIGNED', false, 0],
  567. ],
  568. 'ENGINE' => $this->DBEngine,
  569. ];
  570. if (! $this->c->DB->createTable($table, $schema)) {
  571. $v->addError('Failed to create table');
  572. } else {
  573. if (! $this->c->DB->truncateTable($table)) {
  574. $v->addError('Failed to truncate table');
  575. }
  576. $this->c->DB->exec("INSERT INTO {$table} (test_field) VALUES (?i)", [123]);
  577. $value = $this->c->DB->query("SELECT test_field FROM {$table} WHERE test_field=123")->fetchColumn();
  578. if (123 !== $value) {
  579. $v->addError('Wrong data type for numeric fields');
  580. }
  581. if (! $this->c->DB->dropTable($table)) {
  582. $v->addError('Failed to drop table');
  583. }
  584. }
  585. return $dbhost;
  586. }
  587. /**
  588. * Завершение установки форума
  589. */
  590. protected function installEnd(Validator $v): Page
  591. {
  592. if (\function_exists('\\set_time_limit')) {
  593. \set_time_limit(0);
  594. }
  595. if (true !== $this->c->Cache->clear()) {
  596. throw new RuntimeException('Unable to clear cache');
  597. }
  598. if ('pgsql' === $this->c->DB->getType()) {
  599. $query = 'CREATE COLLATION IF NOT EXISTS fork_icu (
  600. provider = icu,
  601. locale = \'und-u-ks-level2\'
  602. )';
  603. $this->c->DB->exec($query);
  604. }
  605. // bans
  606. $schema = [
  607. 'FIELDS' => [
  608. 'id' => ['SERIAL', false],
  609. 'username' => ['VARCHAR(190)', false, ''],
  610. 'ip' => ['VARCHAR(255)', false, ''],
  611. 'email' => ['VARCHAR(190)', false, ''],
  612. 'message' => ['VARCHAR(255)', false, ''],
  613. 'expire' => ['INT(10) UNSIGNED', false, 0],
  614. 'ban_creator' => ['INT(10) UNSIGNED', false, 0],
  615. ],
  616. 'PRIMARY KEY' => ['id'],
  617. 'INDEXES' => [
  618. 'username_idx' => ['username(25)'],
  619. ],
  620. 'ENGINE' => $this->DBEngine,
  621. ];
  622. $this->c->DB->createTable('::bans', $schema);
  623. // bbcode
  624. $schema = [
  625. 'FIELDS' => [
  626. 'id' => ['SERIAL', false],
  627. 'bb_tag' => ['VARCHAR(11)', false, ''],
  628. 'bb_edit' => ['TINYINT(1)', false, 1],
  629. 'bb_delete' => ['TINYINT(1)', false, 1],
  630. 'bb_structure' => ['MEDIUMTEXT', false],
  631. ],
  632. 'PRIMARY KEY' => ['id'],
  633. 'UNIQUE KEYS' => [
  634. 'bb_tag_idx' => ['bb_tag'],
  635. ],
  636. 'ENGINE' => $this->DBEngine,
  637. ];
  638. $this->c->DB->createTable('::bbcode', $schema);
  639. // categories
  640. $schema = [
  641. 'FIELDS' => [
  642. 'id' => ['SERIAL', false],
  643. 'cat_name' => ['VARCHAR(80)', false, 'New Category'],
  644. 'disp_position' => ['INT(10)', false, 0],
  645. ],
  646. 'PRIMARY KEY' => ['id'],
  647. 'ENGINE' => $this->DBEngine,
  648. ];
  649. $this->c->DB->createTable('::categories', $schema);
  650. // censoring
  651. $schema = [
  652. 'FIELDS' => [
  653. 'id' => ['SERIAL', false],
  654. 'search_for' => ['VARCHAR(60)', false, ''],
  655. 'replace_with' => ['VARCHAR(60)', false, ''],
  656. ],
  657. 'PRIMARY KEY' => ['id'],
  658. 'ENGINE' => $this->DBEngine,
  659. ];
  660. $this->c->DB->createTable('::censoring', $schema);
  661. // config
  662. $schema = [
  663. 'FIELDS' => [
  664. 'conf_name' => ['VARCHAR(190)', false, ''],
  665. 'conf_value' => ['TEXT', true],
  666. ],
  667. 'PRIMARY KEY' => ['conf_name'],
  668. 'ENGINE' => $this->DBEngine,
  669. ];
  670. $this->c->DB->createTable('::config', $schema);
  671. // forum_perms
  672. $schema = [
  673. 'FIELDS' => [
  674. 'group_id' => ['INT(10)', false, 0],
  675. 'forum_id' => ['INT(10)', false, 0],
  676. 'read_forum' => ['TINYINT(1)', false, 1],
  677. 'post_replies' => ['TINYINT(1)', false, 1],
  678. 'post_topics' => ['TINYINT(1)', false, 1],
  679. ],
  680. 'PRIMARY KEY' => ['group_id', 'forum_id'],
  681. 'ENGINE' => $this->DBEngine,
  682. ];
  683. $this->c->DB->createTable('::forum_perms', $schema);
  684. // forums
  685. $schema = [
  686. 'FIELDS' => [
  687. 'id' => ['SERIAL', false],
  688. 'forum_name' => ['VARCHAR(80)', false, 'New forum'],
  689. 'forum_desc' => ['TEXT', false],
  690. 'redirect_url' => ['VARCHAR(255)', false, ''],
  691. 'moderators' => ['TEXT', false],
  692. 'num_topics' => ['MEDIUMINT(8) UNSIGNED', false, 0],
  693. 'num_posts' => ['MEDIUMINT(8) UNSIGNED', false, 0],
  694. 'last_post' => ['INT(10) UNSIGNED', false, 0],
  695. 'last_post_id' => ['INT(10) UNSIGNED', false, 0],
  696. 'last_poster' => ['VARCHAR(190)', false, ''],
  697. 'last_poster_id' => ['INT(10) UNSIGNED', false, 0],
  698. 'last_topic' => ['VARCHAR(255)', false, ''],
  699. 'sort_by' => ['TINYINT(1)', false, 0],
  700. 'disp_position' => ['INT(10)', false, 0],
  701. 'cat_id' => ['INT(10) UNSIGNED', false, 0],
  702. 'no_sum_mess' => ['TINYINT(1)', false, 0],
  703. 'parent_forum_id' => ['INT(10) UNSIGNED', false, 0],
  704. ],
  705. 'PRIMARY KEY' => ['id'],
  706. 'ENGINE' => $this->DBEngine,
  707. ];
  708. $this->c->DB->createTable('::forums', $schema);
  709. // groups
  710. $schema = [
  711. 'FIELDS' => [
  712. 'g_id' => ['SERIAL', false],
  713. 'g_title' => ['VARCHAR(50)', false, ''],
  714. 'g_user_title' => ['VARCHAR(50)', false, ''],
  715. 'g_promote_min_posts' => ['INT(10) UNSIGNED', false, 0],
  716. 'g_promote_next_group' => ['INT(10) UNSIGNED', false, 0],
  717. 'g_moderator' => ['TINYINT(1)', false, 0],
  718. 'g_mod_edit_users' => ['TINYINT(1)', false, 0],
  719. 'g_mod_rename_users' => ['TINYINT(1)', false, 0],
  720. 'g_mod_change_passwords' => ['TINYINT(1)', false, 0],
  721. 'g_mod_ban_users' => ['TINYINT(1)', false, 0],
  722. 'g_mod_promote_users' => ['TINYINT(1)', false, 0],
  723. 'g_read_board' => ['TINYINT(1)', false, 1],
  724. 'g_view_users' => ['TINYINT(1)', false, 1],
  725. 'g_post_replies' => ['TINYINT(1)', false, 1],
  726. 'g_post_topics' => ['TINYINT(1)', false, 1],
  727. 'g_edit_posts' => ['TINYINT(1)', false, 1],
  728. 'g_delete_posts' => ['TINYINT(1)', false, 1],
  729. 'g_delete_topics' => ['TINYINT(1)', false, 1],
  730. 'g_post_links' => ['TINYINT(1)', false, 1],
  731. 'g_set_title' => ['TINYINT(1)', false, 1],
  732. 'g_search' => ['TINYINT(1)', false, 1],
  733. 'g_search_users' => ['TINYINT(1)', false, 1],
  734. 'g_send_email' => ['TINYINT(1)', false, 1],
  735. 'g_post_flood' => ['SMALLINT(6)', false, 30],
  736. 'g_search_flood' => ['SMALLINT(6)', false, 30],
  737. 'g_email_flood' => ['SMALLINT(6)', false, 60],
  738. 'g_report_flood' => ['SMALLINT(6)', false, 60],
  739. 'g_deledit_interval' => ['INT(10)', false, 0],
  740. 'g_pm' => ['TINYINT(1)', false, 1],
  741. 'g_pm_limit' => ['INT(10) UNSIGNED', false, 100],
  742. 'g_sig_length' => ['SMALLINT UNSIGNED', false, 400],
  743. 'g_sig_lines' => ['TINYINT UNSIGNED', false, 4],
  744. ],
  745. 'PRIMARY KEY' => ['g_id'],
  746. 'ENGINE' => $this->DBEngine,
  747. ];
  748. $this->c->DB->createTable('::groups', $schema);
  749. // online
  750. $schema = [
  751. 'FIELDS' => [
  752. 'user_id' => ['INT(10) UNSIGNED', false, 1],
  753. 'ident' => ['VARCHAR(190)', false, ''],
  754. 'logged' => ['INT(10) UNSIGNED', false, 0],
  755. 'last_post' => ['INT(10) UNSIGNED', false, 0],
  756. 'last_search' => ['INT(10) UNSIGNED', false, 0],
  757. 'o_position' => ['VARCHAR(100)', false, ''],
  758. 'o_name' => ['VARCHAR(190)', false, ''],
  759. ],
  760. 'UNIQUE KEYS' => [
  761. 'user_id_ident_idx' => ['user_id', 'ident(45)'],
  762. ],
  763. 'INDEXES' => [
  764. 'ident_idx' => ['ident'],
  765. 'logged_idx' => ['logged'],
  766. ],
  767. 'ENGINE' => $this->DBEngine,
  768. ];
  769. $this->c->DB->createTable('::online', $schema);
  770. // posts
  771. $schema = [
  772. 'FIELDS' => [
  773. 'id' => ['SERIAL', false],
  774. 'poster' => ['VARCHAR(190)', false, ''],
  775. 'poster_id' => ['INT(10) UNSIGNED', false, 1],
  776. 'poster_ip' => ['VARCHAR(45)', false, ''],
  777. 'poster_email' => ['VARCHAR(190)', false, ''],
  778. 'message' => ['MEDIUMTEXT', false],
  779. 'hide_smilies' => ['TINYINT(1)', false, 0],
  780. 'edit_post' => ['TINYINT(1)', false, 0],
  781. 'posted' => ['INT(10) UNSIGNED', false, 0],
  782. 'edited' => ['INT(10) UNSIGNED', false, 0],
  783. 'editor' => ['VARCHAR(190)', false, ''],
  784. 'editor_id' => ['INT(10) UNSIGNED', false, 0],
  785. 'user_agent' => ['VARCHAR(255)', false, ''],
  786. 'topic_id' => ['INT(10) UNSIGNED', false, 0],
  787. ],
  788. 'PRIMARY KEY' => ['id'],
  789. 'INDEXES' => [
  790. 'topic_id_idx' => ['topic_id'],
  791. 'multi_idx' => ['poster_id', 'topic_id'],
  792. ],
  793. 'ENGINE' => $this->DBEngine,
  794. ];
  795. $this->c->DB->createTable('::posts', $schema);
  796. // reports
  797. $schema = [
  798. 'FIELDS' => [
  799. 'id' => ['SERIAL', false],
  800. 'post_id' => ['INT(10) UNSIGNED', false, 0],
  801. 'topic_id' => ['INT(10) UNSIGNED', false, 0],
  802. 'forum_id' => ['INT(10) UNSIGNED', false, 0],
  803. 'reported_by' => ['INT(10) UNSIGNED', false, 0],
  804. 'created' => ['INT(10) UNSIGNED', false, 0],
  805. 'message' => ['TEXT', false],
  806. 'zapped' => ['INT(10) UNSIGNED', false, 0],
  807. 'zapped_by' => ['INT(10) UNSIGNED', false, 0],
  808. ],
  809. 'PRIMARY KEY' => ['id'],
  810. 'INDEXES' => [
  811. 'zapped_idx' => ['zapped'],
  812. ],
  813. 'ENGINE' => $this->DBEngine,
  814. ];
  815. $this->c->DB->createTable('::reports', $schema);
  816. // search_cache
  817. $schema = [
  818. 'FIELDS' => [
  819. 'search_data' => ['MEDIUMTEXT', false],
  820. 'search_time' => ['INT(10) UNSIGNED', false, 0],
  821. 'search_key' => ['VARCHAR(190)', false, '', 'bin'],
  822. ],
  823. 'INDEXES' => [
  824. 'search_time_idx' => ['search_time'],
  825. 'search_key_idx' => ['search_key'],
  826. ],
  827. 'ENGINE' => $this->DBEngine,
  828. ];
  829. $this->c->DB->createTable('::search_cache', $schema);
  830. // search_matches
  831. $schema = [
  832. 'FIELDS' => [
  833. 'post_id' => ['INT(10) UNSIGNED', false, 0],
  834. 'word_id' => ['INT(10) UNSIGNED', false, 0],
  835. 'subject_match' => ['TINYINT(1)', false, 0],
  836. ],
  837. 'INDEXES' => [
  838. 'word_id_idx' => ['word_id'],
  839. 'post_id_idx' => ['post_id'],
  840. ],
  841. 'ENGINE' => $this->DBEngine,
  842. ];
  843. $this->c->DB->createTable('::search_matches', $schema);
  844. // search_words
  845. $schema = [
  846. 'FIELDS' => [
  847. 'id' => ['SERIAL', false],
  848. 'word' => ['VARCHAR(20)', false, '' , 'bin'],
  849. ],
  850. 'PRIMARY KEY' => ['id'],
  851. 'UNIQUE KEYS' => [
  852. 'word_idx' => ['word']
  853. ],
  854. 'ENGINE' => $this->DBEngine,
  855. ];
  856. $this->c->DB->createTable('::search_words', $schema);
  857. // topic_subscriptions
  858. $schema = [
  859. 'FIELDS' => [
  860. 'user_id' => ['INT(10) UNSIGNED', false, 0],
  861. 'topic_id' => ['INT(10) UNSIGNED', false, 0],
  862. ],
  863. 'PRIMARY KEY' => ['user_id', 'topic_id'],
  864. 'ENGINE' => $this->DBEngine,
  865. ];
  866. $this->c->DB->createTable('::topic_subscriptions', $schema);
  867. // forum_subscriptions
  868. $schema = [
  869. 'FIELDS' => [
  870. 'user_id' => ['INT(10) UNSIGNED', false, 0],
  871. 'forum_id' => ['INT(10) UNSIGNED', false, 0],
  872. ],
  873. 'PRIMARY KEY' => ['user_id', 'forum_id'],
  874. 'ENGINE' => $this->DBEngine,
  875. ];
  876. $this->c->DB->createTable('::forum_subscriptions', $schema);
  877. // topics
  878. $schema = [
  879. 'FIELDS' => [
  880. 'id' => ['SERIAL', false],
  881. 'poster' => ['VARCHAR(190)', false, ''],
  882. 'poster_id' => ['INT(10) UNSIGNED', false, 0],
  883. 'subject' => ['VARCHAR(255)', false, ''],
  884. 'posted' => ['INT(10) UNSIGNED', false, 0],
  885. 'first_post_id' => ['INT(10) UNSIGNED', false, 0],
  886. 'last_post' => ['INT(10) UNSIGNED', false, 0],
  887. 'last_post_id' => ['INT(10) UNSIGNED', false, 0],
  888. 'last_poster' => ['VARCHAR(190)', false, ''],
  889. 'last_poster_id' => ['INT(10) UNSIGNED', false, 0],
  890. 'num_views' => ['MEDIUMINT(8) UNSIGNED', false, 0],
  891. 'num_replies' => ['MEDIUMINT(8) UNSIGNED', false, 0],
  892. 'closed' => ['TINYINT(1)', false, 0],
  893. 'sticky' => ['TINYINT(1)', false, 0],
  894. 'stick_fp' => ['TINYINT(1)', false, 0],
  895. 'moved_to' => ['INT(10) UNSIGNED', false, 0],
  896. 'forum_id' => ['INT(10) UNSIGNED', false, 0],
  897. 'poll_type' => ['SMALLINT UNSIGNED', false, 0],
  898. 'poll_time' => ['INT(10) UNSIGNED', false, 0],
  899. 'poll_term' => ['TINYINT', false, 0],
  900. ],
  901. 'PRIMARY KEY' => ['id'],
  902. 'INDEXES' => [
  903. 'forum_id_idx' => ['forum_id'],
  904. 'moved_to_idx' => ['moved_to'],
  905. 'last_post_idx' => ['last_post'],
  906. 'first_post_id_idx' => ['first_post_id'],
  907. ],
  908. 'ENGINE' => $this->DBEngine,
  909. ];
  910. $this->c->DB->createTable('::topics', $schema);
  911. // pm_block
  912. $schema = [
  913. 'FIELDS' => [
  914. 'bl_first_id' => ['INT(10) UNSIGNED', false, 0],
  915. 'bl_second_id' => ['INT(10) UNSIGNED', false, 0],
  916. ],
  917. 'INDEXES' => [
  918. 'bl_first_id_idx' => ['bl_first_id'],
  919. 'bl_second_id_idx' => ['bl_second_id'],
  920. ],
  921. 'ENGINE' => $this->DBEngine,
  922. ];
  923. $this->c->DB->createTable('::pm_block', $schema);
  924. // pm_posts
  925. $schema = [
  926. 'FIELDS' => [
  927. 'id' => ['SERIAL', false],
  928. 'poster' => ['VARCHAR(190)', false, ''],
  929. 'poster_id' => ['INT(10) UNSIGNED', false, 0],
  930. 'poster_ip' => ['VARCHAR(45)', false, ''],
  931. 'message' => ['TEXT', false],
  932. 'hide_smilies' => ['TINYINT(1)', false, 0],
  933. 'posted' => ['INT(10) UNSIGNED', false, 0],
  934. 'edited' => ['INT(10) UNSIGNED', false, 0],
  935. 'topic_id' => ['INT(10) UNSIGNED', false, 0],
  936. ],
  937. 'PRIMARY KEY' => ['id'],
  938. 'INDEXES' => [
  939. 'topic_id_idx' => ['topic_id'],
  940. ],
  941. 'ENGINE' => $this->DBEngine,
  942. ];
  943. $this->c->DB->createTable('::pm_posts', $schema);
  944. // pm_topics
  945. $schema = [
  946. 'FIELDS' => [
  947. 'id' => ['SERIAL', false],
  948. 'subject' => ['VARCHAR(255)', false, ''],
  949. 'poster' => ['VARCHAR(190)', false, ''],
  950. 'poster_id' => ['INT(10) UNSIGNED', false, 0],
  951. 'poster_status' => ['TINYINT UNSIGNED', false, 0],
  952. 'poster_visit' => ['INT(10) UNSIGNED', false, 0],
  953. 'target' => ['VARCHAR(190)', false, ''],
  954. 'target_id' => ['INT(10) UNSIGNED', false, 0],
  955. 'target_status' => ['TINYINT UNSIGNED', false, 0],
  956. 'target_visit' => ['INT(10) UNSIGNED', false, 0],
  957. 'num_replies' => ['INT(10) UNSIGNED', false, 0],
  958. 'first_post_id' => ['INT(10) UNSIGNED', false, 0],
  959. 'last_post' => ['INT(10) UNSIGNED', false, 0],
  960. 'last_post_id' => ['INT(10) UNSIGNED', false, 0],
  961. 'last_number' => ['TINYINT UNSIGNED', false, 0],
  962. ],
  963. 'PRIMARY KEY' => ['id'],
  964. 'INDEXES' => [
  965. 'last_post_idx' => ['last_post'],
  966. 'poster_id_status_idx' => ['poster_id', 'poster_status'],
  967. 'target_id_status_idx' => ['target_id', 'target_status'],
  968. ],
  969. 'ENGINE' => $this->DBEngine,
  970. ];
  971. $this->c->DB->createTable('::pm_topics', $schema);
  972. // users
  973. $schema = [
  974. 'FIELDS' => [
  975. 'id' => ['SERIAL', false],
  976. 'group_id' => ['INT(10) UNSIGNED', false, 0],
  977. 'username' => ['VARCHAR(190)', false, ''],
  978. 'username_normal' => ['VARCHAR(190)', false, ''],
  979. 'password' => ['VARCHAR(255)', false, ''],
  980. 'email' => ['VARCHAR(190)', false, ''],
  981. 'email_normal' => ['VARCHAR(190)', false, ''],
  982. 'email_confirmed' => ['TINYINT(1)', false, 0],
  983. 'title' => ['VARCHAR(50)', false, ''],
  984. 'avatar' => ['VARCHAR(30)', false, ''],
  985. 'realname' => ['VARCHAR(40)', false, ''],
  986. 'url' => ['VARCHAR(100)', false, ''],
  987. 'jabber' => ['VARCHAR(80)', false, ''],
  988. 'icq' => ['VARCHAR(12)', false, ''],
  989. 'msn' => ['VARCHAR(80)', false, ''],
  990. 'aim' => ['VARCHAR(30)', false, ''],
  991. 'yahoo' => ['VARCHAR(30)', false, ''],
  992. 'location' => ['VARCHAR(30)', false, ''],
  993. 'signature' => ['TEXT', false],
  994. 'disp_topics' => ['TINYINT UNSIGNED', false, 0],
  995. 'disp_posts' => ['TINYINT UNSIGNED', false, 0],
  996. 'email_setting' => ['TINYINT(1)', false, 1],
  997. 'notify_with_post' => ['TINYINT(1)', false, 0],
  998. 'auto_notify' => ['TINYINT(1)', false, 0],
  999. 'show_smilies' => ['TINYINT(1)', false, 1],
  1000. 'show_img' => ['TINYINT(1)', false, 1],
  1001. 'show_img_sig' => ['TINYINT(1)', false, 1],
  1002. 'show_avatars' => ['TINYINT(1)', false, 1],
  1003. 'show_sig' => ['TINYINT(1)', false, 1],
  1004. 'timezone' => ['FLOAT', false, 0],
  1005. 'dst' => ['TINYINT(1)', false, 0],
  1006. 'time_format' => ['TINYINT(1)', false, 0],
  1007. 'date_format' => ['TINYINT(1)', false, 0],
  1008. 'language' => ['VARCHAR(25)', false, ''],
  1009. 'style' => ['VARCHAR(25)', false, ''],
  1010. 'num_posts' => ['INT(10) UNSIGNED', false, 0],
  1011. 'num_topics' => ['INT(10) UNSIGNED', false, 0],
  1012. 'last_post' => ['INT(10) UNSIGNED', false, 0],
  1013. 'last_search' => ['INT(10) UNSIGNED', false, 0],
  1014. 'last_email_sent' => ['INT(10) UNSIGNED', false, 0],
  1015. 'last_report_sent' => ['INT(10) UNSIGNED', false, 0],
  1016. 'registered' => ['INT(10) UNSIGNED', false, 0],
  1017. 'registration_ip' => ['VARCHAR(45)', false, ''],
  1018. 'last_visit' => ['INT(10) UNSIGNED', false, 0],
  1019. 'admin_note' => ['VARCHAR(30)', false, ''],
  1020. 'activate_string' => ['VARCHAR(80)', false, ''],
  1021. 'u_pm' => ['TINYINT(1)', false, 1],
  1022. 'u_pm_notify' => ['TINYINT(1)', false, 0],
  1023. 'u_pm_flash' => ['TINYINT(1)', false, 0],
  1024. 'u_pm_num_new' => ['INT(10) UNSIGNED', false, 0],
  1025. 'u_pm_num_all' => ['INT(10) UNSIGNED', false, 0],
  1026. 'u_pm_last_post' => ['INT(10) UNSIGNED', false, 0],
  1027. 'warning_flag' => ['TINYINT(1)', false, 0],
  1028. 'warning_all' => ['INT(10) UNSIGNED', false, 0],
  1029. 'gender' => ['TINYINT UNSIGNED', false, 0],
  1030. 'u_mark_all_read' => ['INT(10) UNSIGNED', false, 0],
  1031. 'last_report_id' => ['INT(10) UNSIGNED', false, 0],
  1032. 'ip_check_type' => ['TINYINT UNSIGNED', false, 0],
  1033. 'login_ip_cache' => ['VARCHAR(255)', false, ''],
  1034. ],
  1035. 'PRIMARY KEY' => ['id'],
  1036. 'UNIQUE KEYS' => [
  1037. 'username_idx' => ['username(25)'],
  1038. 'email_normal_idx' => ['email_normal'],
  1039. ],
  1040. 'INDEXES' => [
  1041. 'registered_idx' => ['registered'],
  1042. ],
  1043. 'ENGINE' => $this->DBEngine,
  1044. ];
  1045. $this->c->DB->createTable('::users', $schema);
  1046. // smilies
  1047. $schema = [
  1048. 'FIELDS' => [
  1049. 'id' => ['SERIAL', false],
  1050. 'sm_image' => ['VARCHAR(40)', false, ''],
  1051. 'sm_code' => ['VARCHAR(20)', false, ''],
  1052. 'sm_position' => ['INT(10) UNSIGNED', false, 0],
  1053. ],
  1054. 'PRIMARY KEY' => ['id'],
  1055. 'ENGINE' => $this->DBEngine,
  1056. ];
  1057. $this->c->DB->createTable('::smilies', $schema);
  1058. // warnings
  1059. $schema = [
  1060. 'FIELDS' => [
  1061. 'id' => ['SERIAL', false],
  1062. 'poster' => ['VARCHAR(190)', false, ''],
  1063. 'poster_id' => ['INT(10) UNSIGNED', false, 0],
  1064. 'posted' => ['INT(10) UNSIGNED', false, 0],
  1065. 'message' => ['TEXT', false],
  1066. ],
  1067. 'PRIMARY KEY' => ['id'],
  1068. 'ENGINE' => $this->DBEngine,
  1069. ];
  1070. $this->c->DB->createTable('::warnings', $schema);
  1071. // poll
  1072. $schema = [
  1073. 'FIELDS' => [
  1074. 'tid' => ['INT(10) UNSIGNED', false, 0],
  1075. 'question_id' => ['TINYINT', false, 0],
  1076. 'field_id' => ['TINYINT', false, 0],
  1077. 'qna_text' => ['VARCHAR(255)', false, ''],
  1078. 'votes' => ['INT(10) UNSIGNED', false, 0],
  1079. ],
  1080. 'PRIMARY KEY' => ['tid', 'question_id', 'field_id'],
  1081. 'ENGINE' => $this->DBEngine,
  1082. ];
  1083. $this->c->DB->createTable('::poll', $schema);
  1084. // poll_voted
  1085. $schema = [
  1086. 'FIELDS' => [
  1087. 'tid' => ['INT(10) UNSIGNED', false],
  1088. 'uid' => ['INT(10) UNSIGNED', false],
  1089. 'rez' => ['TEXT', false],
  1090. ],
  1091. 'PRIMARY KEY' => ['tid', 'uid'],
  1092. 'ENGINE' => $this->DBEngine,
  1093. ];
  1094. $this->c->DB->createTable('::poll_voted', $schema) ;
  1095. // mark_of_forum
  1096. $schema = [
  1097. 'FIELDS' => [
  1098. 'uid' => ['INT(10) UNSIGNED', false, 0],
  1099. 'fid' => ['INT(10) UNSIGNED', false, 0],
  1100. 'mf_mark_all_read' => ['INT(10) UNSIGNED', false, 0],
  1101. ],
  1102. 'UNIQUE KEYS' => [
  1103. 'uid_fid_idx' => ['uid', 'fid'],
  1104. ],
  1105. 'INDEXES' => [
  1106. 'mf_mark_all_read_idx' => ['mf_mark_all_read'],
  1107. ],
  1108. 'ENGINE' => $this->DBEngine,
  1109. ];
  1110. $this->c->DB->createTable('::mark_of_forum', $schema);
  1111. // mark_of_topic
  1112. $schema = [
  1113. 'FIELDS' => [
  1114. 'uid' => ['INT(10) UNSIGNED', false, 0],
  1115. 'tid' => ['INT(10) UNSIGNED', false, 0],
  1116. 'mt_last_visit' => ['INT(10) UNSIGNED', false, 0],
  1117. 'mt_last_read' => ['INT(10) UNSIGNED', false, 0],
  1118. ],
  1119. 'UNIQUE KEYS' => [
  1120. 'uid_tid_idx' => ['uid', 'tid'],
  1121. ],
  1122. 'INDEXES' => [
  1123. 'mt_last_visit_idx' => ['mt_last_visit'],
  1124. 'mt_last_read_idx' => ['mt_last_read'],
  1125. ],
  1126. 'ENGINE' => $this->DBEngine,
  1127. ];
  1128. $this->c->DB->createTable('::mark_of_topic', $schema);
  1129. $now = \time();
  1130. $groups = [
  1131. [
  1132. 'g_id' => FORK_GROUP_ADMIN,
  1133. 'g_title' => __('Administrators'),
  1134. 'g_user_title' => __('Administrator '),
  1135. 'g_mod_promote_users' => 1,
  1136. 'g_read_board' => 1,
  1137. 'g_view_users' => 1,
  1138. 'g_post_replies' => 1,
  1139. 'g_post_topics' => 1,
  1140. 'g_edit_posts' => 1,
  1141. 'g_delete_posts' => 1,
  1142. 'g_delete_topics' => 1,
  1143. 'g_post_links' => 1,
  1144. 'g_set_title' => 1,
  1145. 'g_search' => 1,
  1146. 'g_search_users' => 1,
  1147. 'g_send_email' => 1,
  1148. 'g_post_flood' => 0,
  1149. 'g_search_flood' => 0,
  1150. 'g_email_flood' => 0,
  1151. 'g_report_flood' => 0,
  1152. 'g_pm_limit' => 0,
  1153. 'g_sig_length' => 10000,
  1154. 'g_sig_lines' => 255,
  1155. ],
  1156. [
  1157. 'g_id' => FORK_GROUP_MOD,
  1158. 'g_title' => __('Moderators'),
  1159. 'g_user_title' => __('Moderator '),
  1160. 'g_moderator' => 1,
  1161. 'g_mod_edit_users' => 1,
  1162. 'g_mod_rename_users' => 1,
  1163. 'g_mod_change_passwords' => 1,
  1164. 'g_mod_ban_users' => 1,
  1165. 'g_mod_promote_users' => 1,
  1166. 'g_read_board' => 1,
  1167. 'g_view_users' => 1,
  1168. 'g_post_replies' => 1,
  1169. 'g_post_topics' => 1,
  1170. 'g_edit_posts' => 1,
  1171. 'g_delete_posts' => 1,
  1172. 'g_delete_topics' => 1,
  1173. 'g_post_links' => 1,
  1174. 'g_set_title' => 1,
  1175. 'g_search' => 1,
  1176. 'g_search_users' => 1,
  1177. 'g_send_email' => 1,
  1178. 'g_post_flood' => 0,
  1179. 'g_search_flood' => 0,
  1180. 'g_email_flood' => 0,
  1181. 'g_report_flood' => 0,
  1182. ],
  1183. [
  1184. 'g_id' => FORK_GROUP_GUEST,
  1185. 'g_title' => __('Guests'),
  1186. 'g_user_title' => '',
  1187. 'g_read_board' => 1,
  1188. 'g_view_users' => 1,
  1189. 'g_post_replies' => 0,
  1190. 'g_post_topics' => 0,
  1191. 'g_edit_posts' => 0,
  1192. 'g_delete_posts' => 0,
  1193. 'g_delete_topics' => 0,
  1194. 'g_post_links' => 0,
  1195. 'g_set_title' => 0,
  1196. 'g_search' => 1,
  1197. 'g_search_users' => 1,
  1198. 'g_send_email' => 0,
  1199. 'g_post_flood' => 120,
  1200. 'g_search_flood' => 60,
  1201. 'g_email_flood' => 0,
  1202. 'g_report_flood' => 0,
  1203. 'g_pm' => 0,
  1204. 'g_sig_length' => 0,
  1205. 'g_sig_lines' => 0,
  1206. ],
  1207. [
  1208. 'g_id' => FORK_GROUP_MEMBER,
  1209. 'g_title' => __('Members'),
  1210. 'g_user_title' => '',
  1211. 'g_read_board' => 1,
  1212. 'g_view_users' => 1,
  1213. 'g_post_replies' => 1,
  1214. 'g_post_topics' => 1,
  1215. 'g_edit_posts' => 1,
  1216. 'g_delete_posts' => 1,
  1217. 'g_delete_topics' => 1,
  1218. 'g_post_links' => 1,
  1219. 'g_set_title' => 0,
  1220. 'g_search' => 1,
  1221. 'g_search_users' => 1,
  1222. 'g_send_email' => 1,
  1223. 'g_post_flood' => 30,
  1224. 'g_search_flood' => 30,
  1225. 'g_email_flood' => 60,
  1226. 'g_report_flood' => 60,
  1227. ],
  1228. [
  1229. 'g_id' => FORK_GROUP_NEW_MEMBER,
  1230. 'g_title' => __('New members'),
  1231. 'g_user_title' => __('New member'),
  1232. 'g_read_board' => 1,
  1233. 'g_view_users' => 1,
  1234. 'g_post_replies' => 1,
  1235. 'g_post_topics' => 1,
  1236. 'g_edit_posts' => 1,
  1237. 'g_delete_posts' => 1,
  1238. 'g_delete_topics' => 1,
  1239. 'g_post_links' => 0,
  1240. 'g_set_title' => 0,
  1241. 'g_search' => 1,
  1242. 'g_search_users' => 1,
  1243. 'g_send_email' => 1,
  1244. 'g_post_flood' => 60,
  1245. 'g_search_flood' => 30,
  1246. 'g_email_flood' => 120,
  1247. 'g_report_flood' => 60,
  1248. 'g_deledit_interval' => 600,
  1249. 'g_pm' => 0,
  1250. 'g_promote_min_posts' => 5,
  1251. 'g_promote_next_group' => FORK_GROUP_MEMBER,
  1252. ],
  1253. ];
  1254. foreach ($groups as $group) {
  1255. $fields = [];
  1256. $values = [];
  1257. foreach ($group as $key => $value) {
  1258. $fields[] = $key;
  1259. $values[] = (\is_int($value) ? '?i:' : '?s:') . $key;
  1260. }
  1261. $fields = \implode(', ', $fields);
  1262. $values = \implode(', ', $values);
  1263. $query = "INSERT INTO ::groups ({$fields}) VALUES ({$values})";
  1264. $this->c->DB->exec($query, $group);
  1265. }
  1266. if ('pgsql' === $v->dbtype) {
  1267. $this->c->DB->exec('ALTER SEQUENCE ::groups_g_id_seq RESTART WITH ' . (FORK_GROUP_NEW_MEMBER + 1));
  1268. }
  1269. $forkConfig = [
  1270. 'i_fork_revision' => $this->c->FORK_REVISION,
  1271. 'o_board_title' => $v->title,
  1272. 'o_board_desc' => $v->descr,
  1273. 'o_default_timezone' => 0,
  1274. 'i_timeout_visit' => 3600,
  1275. 'i_timeout_online' => 900,
  1276. 'i_redirect_delay' => 1,
  1277. 'b_show_user_info' => 1,
  1278. 'b_show_post_count' => 1,
  1279. 'b_smilies' => 1,
  1280. 'b_smilies_sig' => 1,
  1281. 'b_make_links' => 1,
  1282. 'o_default_lang' => $v->defaultlang,
  1283. 'o_default_style' => $v->defaultstyle,
  1284. 'i_default_user_group' => FORK_GROUP_NEW_MEMBER,
  1285. 'i_topic_review' => 15,
  1286. 'i_disp_topics_default' => 30,
  1287. 'i_disp_posts_default' => 25,
  1288. 'i_disp_users' => 50,
  1289. 'b_quickpost' => 1,
  1290. 'b_users_online' => 1,
  1291. 'b_censoring' => 0,
  1292. 'b_show_dot' => 0,
  1293. 'b_topic_views' => 1,
  1294. 'o_additional_navlinks' => '',
  1295. 'i_report_method' => 0,
  1296. 'b_regs_report' => 0,
  1297. 'i_default_email_setting' => 2,
  1298. 'o_mailing_list' => $v->email,
  1299. 'b_avatars' => \filter_var(@\ini_get('file_uploads'), \FILTER_VALIDATE_BOOLEAN) ? 1 : 0,
  1300. 'o_avatars_dir' => '/img/avatars',
  1301. 'i_avatars_width' => 60,
  1302. 'i_avatars_height' => 60,
  1303. 'i_avatars_size' => 10240,
  1304. 'o_admin_email' => $v->email,
  1305. 'o_webmaster_email' => $v->email,
  1306. 'b_forum_subscriptions' => 1,
  1307. 'b_topic_subscriptions' => 1,
  1308. 'i_email_max_recipients' => 1,
  1309. 'o_smtp_host' => '',
  1310. 'o_smtp_user' => '',
  1311. 'o_smtp_pass' => '',
  1312. 'b_smtp_ssl' => 0,
  1313. 'b_regs_allow' => 1,
  1314. 'b_regs_verify' => 1,
  1315. 'b_announcement' => 0,
  1316. 'o_announcement_message' => __('Announcement '),
  1317. 'b_rules' => 0,
  1318. 'o_rules_message' => __('Rules '),
  1319. 'b_maintenance' => 0,
  1320. 'o_maintenance_message' => __('Maintenance message '),
  1321. 'b_default_dst' => 0,
  1322. 'i_feed_type' => 2,
  1323. 'i_feed_ttl' => 0,
  1324. 'b_message_bbcode' => 1,
  1325. 'b_message_all_caps' => 0,
  1326. 'b_subject_all_caps' => 0,
  1327. 'b_sig_all_caps' => 0,
  1328. 'b_sig_bbcode' => 1,
  1329. 'b_force_guest_email' => 1,
  1330. 'b_pm' => 0,
  1331. 'b_poll_enabled' => 0,
  1332. 'i_poll_max_questions' => 3,
  1333. 'i_poll_max_fields' => 20,
  1334. 'i_poll_time' => 60,
  1335. 'i_poll_term' => 3,
  1336. 'b_poll_guest' => 0,
  1337. 'a_max_users' => \json_encode(['number' => 1, 'time' => \time()], self::JSON_OPTIONS),
  1338. 'a_bb_white_mes' => \json_encode([], self::JSON_OPTIONS),
  1339. 'a_bb_white_sig' => \json_encode(['b', 'i', 'u', 'color', 'colour', 'email', 'url'], self::JSON_OPTIONS),
  1340. 'a_bb_black_mes' => \json_encode([], self::JSON_OPTIONS),
  1341. 'a_bb_black_sig' => \json_encode([], self::JSON_OPTIONS),
  1342. 'a_guest_set' => \json_encode(
  1343. [
  1344. 'show_smilies' => 1,
  1345. 'show_sig' => 1,
  1346. 'show_avatars' => 1,
  1347. 'show_img' => 1,
  1348. 'show_img_sig' => 1,
  1349. ], self::JSON_OPTIONS
  1350. ),
  1351. 's_РЕГИСТР' => 'Ok',
  1352. ];
  1353. foreach ($forkConfig as $name => $value) {
  1354. $this->c->DB->exec('INSERT INTO ::config (conf_name, conf_value) VALUES (?s, ?s)', [$name, $value]);
  1355. }
  1356. $ip = \filter_var($_SERVER['REMOTE_ADDR'], \FILTER_VALIDATE_IP) ?: '0.0.0.0';
  1357. $topicId = 1;
  1358. $this->c->DB->exec('INSERT INTO ::users (group_id, username, username_normal, password, email, email_normal, language, style, num_posts, last_post, registered, registration_ip, last_visit, signature, num_topics) VALUES (?i, ?s, ?s, ?s, ?s, ?s, ?s, ?s, 1, ?i, ?i, ?s, ?i, \'\', 1)', [FORK_GROUP_ADMIN, $v->username, $this->c->users->normUsername($v->username), \password_hash($v->password, \PASSWORD_DEFAULT), $v->email, $this->c->NormEmail->normalize($v->email), $v->defaultlang, $v->defaultstyle, $now, $now, $ip, $now]);
  1359. $adminId = (int) $this->c->DB->lastInsertId();
  1360. $this->c->DB->exec('INSERT INTO ::categories (cat_name, disp_position) VALUES (?s, ?i)', [__('Test category'), 1]);
  1361. $catId = (int) $this->c->DB->lastInsertId();
  1362. $this->c->DB->exec('INSERT INTO ::posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(?s, ?i, ?s, ?s, ?i, ?i)', [$v->username, $adminId, $ip, __('Test message'), $now, $topicId]);
  1363. $postId = (int) $this->c->DB->lastInsertId();
  1364. $this->c->DB->exec('INSERT INTO ::forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, last_poster_id, last_topic, disp_position, cat_id, moderators) VALUES (?s, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?s, ?i, ?i, \'\')', [__('Test forum'), __('This is just a test forum'), 1, 1, $now, $postId, $v->username, $adminId, __('Test post'), 1, $catId]);
  1365. $forumId = (int) $this->c->DB->lastInsertId();
  1366. $this->c->DB->exec('INSERT INTO ::topics (poster, poster_id, subject, posted, first_post_id, last_post, last_post_id, last_poster, last_poster_id, forum_id) VALUES(?s, ?i, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?i)', [$v->username, $adminId, __('Test post'), $now, $postId, $now, $postId, $v->username, $adminId, $forumId]);
  1367. $topicId = (int) $this->c->DB->lastInsertId();
  1368. $this->c->DB->exec('UPDATE ::posts SET topic_id=?i WHERE id=?i', [$topicId, $postId]);
  1369. $smilies = [
  1370. ':)' => 'smile.png',
  1371. '=)' => 'smile.png',
  1372. ':|' => 'neutral.png',
  1373. '=|' => 'neutral.png',
  1374. ':(' => 'sad.png',
  1375. '=(' => 'sad.png',
  1376. ':D' => 'big_smile.png',
  1377. '=D' => 'big_smile.png',
  1378. ':o' => 'yikes.png',
  1379. ':O' => 'yikes.png',
  1380. ';)' => 'wink.png',
  1381. ':/' => 'hmm.png',
  1382. ':P' => 'tongue.png',
  1383. ':p' => 'tongue.png',
  1384. ':lol:' => 'lol.png',
  1385. ':mad:' => 'mad.png',
  1386. ':rolleyes:' => 'roll.png',
  1387. ':cool:' => 'cool.png',
  1388. ];
  1389. $i = 0;
  1390. foreach ($smilies as $text => $img) {
  1391. $this->c->DB->exec('INSERT INTO ::smilies (sm_image, sm_code, sm_position) VALUES(?s, ?s, ?i)', [$img, $text, $i++]); //????
  1392. }
  1393. $query = 'INSERT INTO ::bbcode (bb_tag, bb_edit, bb_delete, bb_structure)
  1394. VALUES(?s:tag, 1, 0, ?s:structure)';
  1395. $bbcodes = include $this->c->DIR_CONFIG . '/defaultBBCode.php';
  1396. foreach ($bbcodes as $bbcode) {
  1397. $vars = [
  1398. ':tag' => $bbcode['tag'],
  1399. ':structure' => \json_encode($bbcode, self::JSON_OPTIONS),
  1400. ];
  1401. $this->c->DB->exec($query, $vars);
  1402. }
  1403. $config = \file_get_contents($this->c->DIR_CONFIG . '/main.dist.php');
  1404. if (false === $config) {
  1405. throw new RuntimeException('No access to main.dist.php.');
  1406. }
  1407. $repl = [ //????
  1408. '_BASE_URL_' => $v->baseurl,
  1409. '_DB_DSN_' => $this->c->DB_DSN,
  1410. '_DB_USERNAME_' => $this->c->DB_USERNAME,
  1411. '_DB_PASSWORD_' => $this->c->DB_PASSWORD,
  1412. '_DB_PREFIX_' => $this->c->DB_PREFIX,
  1413. '_SALT_FOR_HMAC_' => $this->c->Secury->randomPass(\mt_rand(20,30)),
  1414. '_COOKIE_PREFIX_' => 'fork' . $this->c->Secury->randomHash(7) . '_',
  1415. '_COOKIE_DOMAIN_' => $v->cookie_domain,
  1416. '_COOKIE_PATH_' => $v->cookie_path,
  1417. '_COOKIE_SECURE_' => 1 === $v->cookie_secure ? 'true' : 'false',
  1418. '_COOKIE_KEY1_' => $this->c->Secury->randomPass(\mt_rand(20,30)),
  1419. '_COOKIE_KEY2_' => $this->c->Secury->randomPass(\mt_rand(20,30)),
  1420. ];
  1421. foreach ($repl as $key => $val) {
  1422. $config = \str_replace($key, \addslashes($val), $config);
  1423. }
  1424. $config = \str_replace('_DB_OPTIONS_', $this->c->DB_OPTS_AS_STR, $config);
  1425. $result = \file_put_contents($this->c->DIR_CONFIG . '/main.php', $config);
  1426. if (false === $result) {
  1427. throw new RuntimeException('No write to main.php');
  1428. }
  1429. return $this->c->Redirect->toIndex();
  1430. }
  1431. }