1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Quickedit |
5
|
|
|
* @copyright (c) 2014 Marc Alexander ( www.m-a-styles.de ) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace marc1706\quickedit\migrations\v10x; |
11
|
|
|
|
12
|
|
|
class beta1 extends \phpbb\db\migration\migration |
13
|
|
|
{ |
14
|
|
|
/** @var int quickedit forums flag */ |
15
|
|
|
const QUICKEDIT_FLAG = 128; |
16
|
|
|
|
17
|
|
|
public function effectively_installed() |
18
|
|
|
{ |
19
|
|
|
return isset($this->config['allow_quick_edit']); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function update_schema() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
return array( |
25
|
|
|
'change_columns' => array( |
26
|
|
|
$this->table_prefix . 'forums' => array( |
27
|
|
|
'forum_flags' => array('UINT', 32), |
28
|
|
|
), |
29
|
|
|
), |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
View Code Duplication |
public function revert_schema() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return array( |
36
|
|
|
'change_columns' => array( |
37
|
|
|
$this->table_prefix . 'forums' => array( |
38
|
|
|
'forum_flags' => array('TINT:4', 32), |
39
|
|
|
), |
40
|
|
|
), |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
static public function depends_on() |
45
|
|
|
{ |
46
|
|
|
return array('\phpbb\db\migration\data\v310\dev'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function update_data() |
50
|
|
|
{ |
51
|
|
|
return array( |
52
|
|
|
array('config.add', array('allow_quick_edit', 0)), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function revert_data() |
57
|
|
|
{ |
58
|
|
|
return array( |
59
|
|
|
array('custom', array(array($this, 'revert_forum_flags'))), |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function revert_forum_flags() |
64
|
|
|
{ |
65
|
|
|
$sql = 'SELECT forum_id, forum_flags FROM ' . FORUMS_TABLE . ' |
66
|
|
|
WHERE forum_flags >= ' . self::QUICKEDIT_FLAG; |
67
|
|
|
$result = $this->db->sql_query($sql); |
68
|
|
|
|
69
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
70
|
|
|
{ |
71
|
|
|
$sql = 'UPDATE ' . FORUMS_TABLE . ' |
72
|
|
|
SET forum_flags = ' . (($row['forum_flags'] & self::QUICKEDIT_FLAG) ? $row['forum_flags'] - self::QUICKEDIT_FLAG : $row['forum_flags']) . ' |
73
|
|
|
WHERE forum_id = ' . $row['forum_id']; |
74
|
|
|
$this->db->sql_query($sql); |
75
|
|
|
} |
76
|
|
|
$this->db->sql_freeresult($result); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.