m4_update_statuses   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 25
c 0
b 0
f 0
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A update_statuses() 0 21 2
A update_data() 0 4 1
A depends_on() 0 5 1
A effectively_installed() 0 10 1
1
<?php
2
/**
3
 *
4
 * Ideas extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ideas\migrations;
12
13
class m4_update_statuses extends \phpbb\db\migration\migration
14
{
15
	public function effectively_installed()
16
	{
17
		$sql = 'SELECT status_id
18
			FROM ' . $this->table_prefix . "ideas_statuses
19
			WHERE status_name='New'";
20
		$result = $this->db->sql_query($sql);
21
		$row = $this->db->sql_fetchrow($result);
22
		$this->db->sql_freeresult($result);
23
24
		return $row === false;
25
	}
26
27
	public static function depends_on()
28
	{
29
		return array(
30
			'\phpbb\ideas\migrations\m1_initial_schema',
31
			'\phpbb\ideas\migrations\m2_initial_data',
32
		);
33
	}
34
35
	public function update_data()
36
	{
37
		return array(
38
			array('custom', array(array($this, 'update_statuses'))),
39
		);
40
	}
41
42
	public function update_statuses()
43
	{
44
		$status_updates = array(
45
			'New'			=> 'NEW',
46
			'In Progress'	=> 'IN_PROGRESS',
47
			'Implemented'	=> 'IMPLEMENTED',
48
			'Duplicate'		=> 'DUPLICATE',
49
			'Invalid'		=> 'INVALID',
50
		);
51
52
		$this->db->sql_transaction('begin');
53
54
		foreach ($status_updates as $old => $new)
55
		{
56
			$sql = 'UPDATE ' . $this->table_prefix . "ideas_statuses
57
				SET status_name='" . $this->db->sql_escape($new) . "'
58
				WHERE status_name='" .  $this->db->sql_escape($old) . "'";
59
			$this->db->sql_query($sql);
60
		}
61
62
		$this->db->sql_transaction('commit');
63
	}
64
}
65