Completed
Push — develop-3.2.x ( b3fe85...938ab2 )
by Matt
08:07
created

v310_m1_remove_data::abbc3_bbcodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 67
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 67
rs 9.2815
cc 1
eloc 57
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
*
4
* Advanced BBCode Box
5
*
6
* @copyright (c) 2013 Matt Friedman
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace vse\abbc3\migrations;
12
13
/**
14
* This migration removes old data from 3.0
15
* installations of Advanced BBCode Box 3 MOD.
16
*/
17
class v310_m1_remove_data extends \phpbb\db\migration\migration
18
{
19
	/**
20
	 * Run migration if ABBC3_VERSION config exists
21
	 *
22
	 * @return bool
23
	 */
24
	public function effectively_installed()
25
	{
26
		return !isset($this->config['ABBC3_VERSION']);
27
	}
28
29
	/**
30
	 * This dependency is needed mostly for testing, to ensure
31
	 * phpBB migrations are installed before ABBC3.
32
	 *
33
	 * @return array An array of migration class names
34
	 */
35
	static public function depends_on()
36
	{
37
		return array('\phpbb\db\migration\data\v310\beta4');
38
	}
39
40
	/**
41
	 * {@inheritdoc}
42
	 */
43
	public function update_data()
44
	{
45
		return array(
46
			array('if', array(
47
				array('module.exists', array('acp', false, 'ACP_ABBC3_BBCODES')),
48
				array('module.remove', array('acp', false, 'ACP_ABBC3_BBCODES')),
49
			)),
50
			array('if', array(
51
				array('module.exists', array('acp', false, 'ACP_ABBC3_SETTINGS')),
52
				array('module.remove', array('acp', false, 'ACP_ABBC3_SETTINGS')),
53
			)),
54
			array('if', array(
55
				array('module.exists', array('acp', false, 'ACP_ABBCODES')),
56
				array('module.remove', array('acp', false, 'ACP_ABBCODES')),
57
			)),
58
59
			// Custom functions
60
			array('custom', array(array($this, 'remove_abbc3_configs'))),
61
			array('custom', array(array($this, 'remove_abbc3_bbcodes'))),
62
		);
63
	}
64
65
	/**
66
	 * Remove config data from ABBC3 MOD
67
	 */
68
	public function remove_abbc3_configs()
69
	{
70
		$sql = 'DELETE FROM ' . $this->table_prefix . 'config
71
			WHERE ' . $this->db->sql_like_expression('ABBC3_' . $this->db->get_any_char());
72
		$this->db->sql_query($sql);
73
	}
74
75
	/**
76
	 * Remove BBCodes from ABBC3 MOD
77
	 */
78
	public function remove_abbc3_bbcodes()
79
	{
80
		$abbc3_bbcode_deprecated = $this->abbc3_bbcodes();
81
82
		// Add all breaks and divisions to the array
83
		$sql = 'SELECT bbcode_tag
84
			FROM ' . $this->table_prefix . 'bbcodes
85
			WHERE bbcode_tag ' . $this->db->sql_like_expression('break' . $this->db->get_any_char()) . '
86
			OR bbcode_tag ' . $this->db->sql_like_expression('division' . $this->db->get_any_char());
87
88
		$result = $this->db->sql_query($sql);
89
		while ($row = $this->db->sql_fetchrow($result))
90
		{
91
			$abbc3_bbcode_deprecated[] = $row['bbcode_tag'];
92
		}
93
		$this->db->sql_freeresult($result);
94
95
		// Delete all the unwanted BBCodes
96
		$sql = 'DELETE FROM ' . $this->table_prefix . 'bbcodes
97
			WHERE ' . $this->db->sql_in_set('bbcode_tag', $abbc3_bbcode_deprecated) . '
98
			OR bbcode_id < 0';
99
		$this->db->sql_query($sql);
100
	}
101
102
	/**
103
	 * Array of ABBC3 MOD BBCodes to remove
104
	 *
105
	 * @return array
106
	 */
107
	public function abbc3_bbcodes()
108
	{
109
		return array(
110
			// These exists in core
111
			'b',
112
			'code',
113
			'color',
114
			'email',
115
			'flash',
116
			'i',
117
			'img=',
118
			'listb',
119
			'listitem',
120
			'listo',
121
			'quote',
122
			'size',
123
			'u',
124
			'url',
125
			'url=',
126
127
			// These were not really BBCodes
128
			'copy',
129
			'cut',
130
			'grad',
131
			'paste',
132
			'plain',
133
			'imgshack',
134
135
			// These are deprecated
136
			'click',
137
			'ed2k',
138
			'flv',
139
			'quicktime',
140
			'ram',
141
			'rapidshare',
142
			'stream',
143
			'testlink',
144
			'video',
145
			'wave=',
146
			'web',
147
			'scrippet',
148
			'search',
149
			'thumbnail',
150
			'hr',			// no closing
151
			'tab=',			// no closing
152
			'tabs',
153
			'table=',
154
			'anchor=',
155
			'upload',
156
			'html',
157
			'collegehumor',
158
			'dm',
159
			'gamespot',
160
			'ignvideo',
161
			'liveleak',
162
			'veoh',
163
164
			// These are being replaced by new BBCodes
165
			'align=justify',	// replaced by align=
166
			'align=left',		// replaced by align=
167
			'align=right',		// replaced by align=
168
			'dir=rtl',			// replaced by dir=
169
			'marq=down',		// replaced by marq=
170
			'marq=left',		// replaced by marq=
171
			'marq=right',		// replaced by marq=
172
		);
173
	}
174
}
175