diff --git a/phpBB/phpbb/captcha/plugins/qa.php b/phpBB/phpbb/captcha/plugins/qa.php index b9bfac33f1..106cedb7c2 100644 --- a/phpBB/phpbb/captcha/plugins/qa.php +++ b/phpBB/phpbb/captcha/plugins/qa.php @@ -336,56 +336,6 @@ class qa */ function install() { - global $phpbb_container; - - $db_tool = $phpbb_container->get('dbal.tools'); - $schemas = array( - $this->table_captcha_questions => array ( - 'COLUMNS' => array( - 'question_id' => array('UINT', null, 'auto_increment'), - 'strict' => array('BOOL', 0), - 'lang_id' => array('UINT', 0), - 'lang_iso' => array('VCHAR:30', ''), - 'question_text' => array('TEXT_UNI', ''), - ), - 'PRIMARY_KEY' => 'question_id', - 'KEYS' => array( - 'lang' => array('INDEX', 'lang_iso'), - ), - ), - $this->table_captcha_answers => array ( - 'COLUMNS' => array( - 'question_id' => array('UINT', 0), - 'answer_text' => array('STEXT_UNI', ''), - ), - 'KEYS' => array( - 'qid' => array('INDEX', 'question_id'), - ), - ), - $this->table_qa_confirm => array ( - 'COLUMNS' => array( - 'session_id' => array('CHAR:32', ''), - 'confirm_id' => array('CHAR:32', ''), - 'lang_iso' => array('VCHAR:30', ''), - 'question_id' => array('UINT', 0), - 'attempts' => array('UINT', 0), - 'confirm_type' => array('USINT', 0), - ), - 'KEYS' => array( - 'session_id' => array('INDEX', 'session_id'), - 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso')), - ), - 'PRIMARY_KEY' => 'confirm_id', - ), - ); - - foreach ($schemas as $table => $schema) - { - if (!$db_tool->sql_table_exists($table)) - { - $db_tool->sql_create_table($table, $schema); - } - } } /** diff --git a/phpBB/phpbb/db/migration/data/v400/qa_captcha.php b/phpBB/phpbb/db/migration/data/v400/qa_captcha.php new file mode 100644 index 0000000000..69cca2dc15 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v400/qa_captcha.php @@ -0,0 +1,89 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\db\migration\data\v400; + +use phpbb\db\migration\migration; + +class qa_captcha extends migration +{ + public function effectively_installed(): bool + { + return $this->db_tools->sql_table_exists($this->tables['captcha_qa_questions']) + && $this->db_tools->sql_table_exists($this->tables['captcha_qa_answers']) + && $this->db_tools->sql_table_exists($this->tables['captcha_qa_confirm']); + } + + public static function depends_on(): array + { + return [ + '\phpbb\db\migration\data\v400\dev', + ]; + } + + public function update_schema(): array + { + return [ + 'add_tables' => [ + $this->tables['captcha_qa_questions'] => [ + 'COLUMNS' => [ + 'question_id' => ['UINT', null, 'auto_increment'], + 'strict' => ['BOOL', 0], + 'lang_id' => ['UINT', 0], + 'lang_iso' => ['VCHAR:30', ''], + 'question_text' => ['TEXT_UNI', ''], + ], + 'PRIMARY_KEY' => 'question_id', + 'KEYS' => [ + 'lang' => ['INDEX', 'lang_iso'], + ], + ], + $this->tables['captcha_qa_answers'] => [ + 'COLUMNS' => [ + 'question_id' => ['UINT', 0], + 'answer_text' => ['STEXT_UNI', ''], + ], + 'KEYS' => [ + 'qid' => ['INDEX', 'question_id'], + ], + ], + $this->tables['captcha_qa_confirm'] => [ + 'COLUMNS' => [ + 'session_id' => ['CHAR:32', ''], + 'confirm_id' => ['CHAR:32', ''], + 'lang_iso' => ['VCHAR:30', ''], + 'question_id' => ['UINT', 0], + 'attempts' => ['UINT', 0], + 'confirm_type' => ['USINT', 0], + ], + 'KEYS' => [ + 'session_id' => ['INDEX', 'session_id'], + 'lookup' => ['INDEX', ['confirm_id', 'session_id', 'lang_iso']], + ], + 'PRIMARY_KEY' => 'confirm_id', + ], + ], + ]; + } + + public function revert_schema(): array + { + return [ + 'drop_tables' => [ + $this->tables['captcha_qa_questions'], + $this->tables['captcha_qa_answers'], + $this->tables['captcha_qa_confirm'] + ], + ]; + } +}