m4_update_statuses::update_data()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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