Completed
Pull Request — master (#43)
by Jakub
08:12
created

m9_views_clicks::update_schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\migrations\v10x;
12
13
class m9_views_clicks extends \phpbb\db\migration\migration
14
{
15
	/**
16
	* {@inheritDoc}
17
	*/
18
	public function effectively_installed()
19
	{
20
		return $this->db_tools->sql_column_exists($this->table_prefix . 'ads', 'ad_views');
21
	}
22
23
	/**
24
	* {@inheritDoc}
25
	*/
26
	static public function depends_on()
27
	{
28
		return array('\phpbb\ads\migrations\v10x\m1_initial_schema');
29
	}
30
31
	/**
32
	* Add the views and clicks to ads table
33
	*
34
	* @return array Array of table schema
35
	* @access public
36
	*/
37
	public function update_schema()
38
	{
39
		return array(
40
			'add_columns' => array(
41
				$this->table_prefix . 'ads' => array(
42
					'ad_views'			=> array('UINT', 0),
43
					'ad_clicks'			=> array('UINT', 0),
44
					'ad_views_limit'	=> array('UINT', 0),
45
					'ad_clicks_limit'	=> array('UINT', 0),
46
				),
47
			),
48
			'add_index'	=> array(
49
				$this->table_prefix . 'ads'	=> array(
50
					'ad_views'			=> array('ad_views'), // index used in ad\manager::get_ads
51
					'ad_clicks'			=> array('ad_clicks'), // index used in ad\manager::get_ads
52
					'ad_views_limit'	=> array('ad_views_limit'), // index used in ad\manager::get_ads
53
					'ad_clicks_limit'	=> array('ad_clicks_limit'), // index used in ad\manager::get_ads
54
				),
55
			),
56
		);
57
	}
58
59
	/**
60
	* Drop the views and clicks from ads table
61
	*
62
	* @return array Array of table schema
63
	* @access public
64
	*/
65
	public function revert_schema()
66
	{
67
		return array(
68
			'drop_keys'	=> array(
69
				$this->table_prefix . 'ads' => array(
70
					'ad_clicks_limit',
71
					'ad_views_limit',
72
					'ad_clicks',
73
					'ad_views',
74
				),
75
			),
76
			'drop_columns' => array(
77
				$this->table_prefix . 'ads' => array(
78
					'ad_views',
79
					'ad_clicks',
80
					'ad_views_limit',
81
					'ad_clicks_limit',
82
				),
83
			),
84
		);
85
	}
86
87
	/**
88
	 * Add phpbb_ads_enable_views and phpbb_ads_enable_clicks config
89
	 *
90
	 * @return array Array of data update instructions
91
	 */
92
	public function update_data()
93
	{
94
		return array(
95
			array('config.add', array('phpbb_ads_enable_views', 0)),
96
			array('config.add', array('phpbb_ads_enable_clicks', 0)),
97
		);
98
	}
99
}
100