Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 63
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
release_3_0_9_rc1
0.00% covered (danger)
0.00%
0 / 63
0.00% covered (danger)
0.00%
0 / 7
132
0.00% covered (danger)
0.00%
0 / 1
 effectively_installed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 depends_on
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_schema
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
2
 revert_schema
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 update_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 update_file_extension_group_names
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
6
 fix_firebird_qa_captcha
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\db\migration\data\v30x;
15
16class release_3_0_9_rc1 extends \phpbb\db\migration\migration
17{
18    public function effectively_installed()
19    {
20        return phpbb_version_compare($this->config['version'], '3.0.9-RC1', '>=');
21    }
22
23    public static function depends_on()
24    {
25        return array('\phpbb\db\migration\data\v30x\release_3_0_8');
26    }
27
28    public function update_schema()
29    {
30        return array(
31            'add_tables' => array(
32                $this->table_prefix . 'login_attempts' => array(
33                    'COLUMNS' => array(
34                        // this column was removed from the database updater
35                        // after 3.0.9-RC3 was released. It might still exist
36                        // in 3.0.9-RCX installations and has to be dropped as
37                        // soon as the \phpbb\db\tools\tools class is capable of properly
38                        // removing a primary key.
39                        // 'attempt_id'            => array('UINT', NULL, 'auto_increment'),
40                        'attempt_ip'            => array('VCHAR:40', ''),
41                        'attempt_browser'        => array('VCHAR:150', ''),
42                        'attempt_forwarded_for'    => array('VCHAR:255', ''),
43                        'attempt_time'            => array('TIMESTAMP', 0),
44                        'user_id'                => array('UINT', 0),
45                        'username'                => array('VCHAR_UNI:255', 0),
46                        'username_clean'        => array('VCHAR_CI', 0),
47                    ),
48                    //'PRIMARY_KEY' => 'attempt_id',
49                    'KEYS' => array(
50                        'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
51                        'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
52                        'att_time' => array('INDEX', array('attempt_time')),
53                        'user_id' => array('INDEX', 'user_id'),
54                    ),
55                ),
56            ),
57            'change_columns' => array(
58                $this->table_prefix . 'bbcodes' => array(
59                    'bbcode_id' => array('USINT', 0),
60                ),
61            ),
62        );
63    }
64
65    public function revert_schema()
66    {
67        return array(
68            'drop_tables' => array(
69                $this->table_prefix . 'login_attempts',
70            ),
71        );
72    }
73
74    public function update_data()
75    {
76        return array(
77            array('config.add', array('ip_login_limit_max', 50)),
78            array('config.add', array('ip_login_limit_time', 21600)),
79            array('config.add', array('ip_login_limit_use_forwarded', 0)),
80            array('custom', array(array(&$this, 'update_file_extension_group_names'))),
81            array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))),
82
83            array('config.update', array('version', '3.0.9-RC1')),
84        );
85    }
86
87    public function update_file_extension_group_names()
88    {
89        // Update file extension group names to use language strings, again.
90        $sql = 'SELECT group_id, group_name
91            FROM ' . EXTENSION_GROUPS_TABLE . '
92            WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->get_any_char());
93        $result = $this->db->sql_query($sql);
94
95        while ($row = $this->db->sql_fetchrow($result))
96        {
97            $sql_ary = array(
98                'group_name'    => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
99            );
100
101            $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
102                SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
103                WHERE group_id = ' . $row['group_id'];
104            $this->sql_query($sql);
105        }
106        $this->db->sql_freeresult($result);
107    }
108
109    public function fix_firebird_qa_captcha()
110    {
111        // Recover from potentially broken Q&A CAPTCHA table on firebird
112        // Q&A CAPTCHA was uninstallable, so it's safe to remove these
113        // without data loss
114        if ($this->db_tools->sql_layer == 'firebird')
115        {
116            $tables = array(
117                $this->table_prefix . 'captcha_questions',
118                $this->table_prefix . 'captcha_answers',
119                $this->table_prefix . 'qa_confirm',
120            );
121            foreach ($tables as $table)
122            {
123                if ($this->db_tools->sql_table_exists($table))
124                {
125                    $this->db_tools->sql_table_drop($table);
126                }
127            }
128        }
129    }
130}