beta1   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 67
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A effectively_installed() 0 4 1
A depends_on() 0 4 1
A update_data() 0 6 1
A revert_data() 0 6 1
A revert_forum_flags() 0 15 3
A update_schema() 0 10 1
A revert_schema() 0 10 1
1
<?php
2
/**
3
*
4
* @package Quickedit
5
* @copyright (c) 2015 - 2021 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
	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
	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 = ' . (int) $row['forum_id'];
74
			$this->db->sql_query($sql);
75
		}
76
		$this->db->sql_freeresult($result);
77
	}
78
}
79