Completed
Push — master ( 888ef4...61b434 )
by Marc
117:35 queued 52:30
created

beta1::effectively_installed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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