aboutsummaryrefslogtreecommitdiff
blob: 79ef8390050ccb302a3b79c1e931f75e89831226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
*
* @package migration
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace phpbb\db\migration\data\v30x;

class release_3_0_9_rc1 extends \phpbb\db\migration\migration
{
	public function effectively_installed()
	{
		return phpbb_version_compare($this->config['version'], '3.0.9-RC1', '>=');
	}

	static public function depends_on()
	{
		return array('\phpbb\db\migration\data\v30x\release_3_0_8');
	}

	public function update_schema()
	{
		return array(
			'add_tables' => array(
				$this->table_prefix . 'login_attempts' => array(
					'COLUMNS' => array(
						// this column was removed from the database updater
						// after 3.0.9-RC3 was released. It might still exist
						// in 3.0.9-RCX installations and has to be dropped as
						// soon as the db_tools class is capable of properly
						// removing a primary key.
						// 'attempt_id'			=> array('UINT', NULL, 'auto_increment'),
						'attempt_ip'			=> array('VCHAR:40', ''),
						'attempt_browser'		=> array('VCHAR:150', ''),
						'attempt_forwarded_for'	=> array('VCHAR:255', ''),
						'attempt_time'			=> array('TIMESTAMP', 0),
						'user_id'				=> array('UINT', 0),
						'username'				=> array('VCHAR_UNI:255', 0),
						'username_clean'		=> array('VCHAR_CI', 0),
					),
					//'PRIMARY_KEY' => 'attempt_id',
					'KEYS' => array(
						'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')),
						'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')),
						'att_time' => array('INDEX', array('attempt_time')),
						'user_id' => array('INDEX', 'user_id'),
					),
				),
			),
			'change_columns' => array(
				$this->table_prefix . 'bbcodes' => array(
					'bbcode_id' => array('USINT', 0),
				),
			),
		);
	}

	public function revert_schema()
	{
		return array(
			'drop_tables' => array(
				$this->table_prefix . 'login_attempts',
			),
		);
	}

	public function update_data()
	{
		return array(
			array('config.add', array('ip_login_limit_max', 50)),
			array('config.add', array('ip_login_limit_time', 21600)),
			array('config.add', array('ip_login_limit_use_forwarded', 0)),
			array('custom', array(array(&$this, 'update_file_extension_group_names'))),
			array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))),

			array('config.update', array('version', '3.0.9-RC1')),
		);
	}

	public function update_file_extension_group_names()
	{
		// Update file extension group names to use language strings, again.
		$sql = 'SELECT group_id, group_name
			FROM ' . EXTENSION_GROUPS_TABLE . '
			WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char);
		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			$sql_ary = array(
				'group_name'	=> substr($row['group_name'], 10), // Strip off 'EXT_GROUP_'
			);

			$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
				SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE group_id = ' . $row['group_id'];
			$this->sql_query($sql);
		}
		$this->db->sql_freeresult($result);
	}

	public function fix_firebird_qa_captcha()
	{
		// Recover from potentially broken Q&A CAPTCHA table on firebird
		// Q&A CAPTCHA was uninstallable, so it's safe to remove these
		// without data loss
		if ($this->db_tools->sql_layer == 'firebird')
		{
			$tables = array(
				$this->table_prefix . 'captcha_questions',
				$this->table_prefix . 'captcha_answers',
				$this->table_prefix . 'qa_confirm',
			);
			foreach ($tables as $table)
			{
				if ($this->db_tools->sql_table_exists($table))
				{
					$this->db_tools->sql_table_drop($table);
				}
			}
		}
	}
}