Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
84.62% |
33 / 39 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
config | |
84.62% |
33 / 39 |
|
57.14% |
4 / 7 |
18.05 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get_name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
add | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
update | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
update_if_equals | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
remove | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
reverse | |
84.00% |
21 / 25 |
|
0.00% |
0 / 1 |
7.20 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of 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 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\db\migration\tool; |
15 | |
16 | /** |
17 | * Migration config tool |
18 | */ |
19 | class config implements \phpbb\db\migration\tool\tool_interface |
20 | { |
21 | /** @var \phpbb\config\config */ |
22 | protected $config; |
23 | |
24 | /** |
25 | * Constructor |
26 | * |
27 | * @param \phpbb\config\config $config |
28 | */ |
29 | public function __construct(\phpbb\config\config $config) |
30 | { |
31 | $this->config = $config; |
32 | } |
33 | |
34 | /** |
35 | * {@inheritdoc} |
36 | */ |
37 | public function get_name() |
38 | { |
39 | return 'config'; |
40 | } |
41 | |
42 | /** |
43 | * Add a config setting. |
44 | * |
45 | * @param string $config_name The name of the config setting |
46 | * you would like to add |
47 | * @param mixed $config_value The value of the config setting |
48 | * @param bool $is_dynamic True if it is dynamic (changes very often) |
49 | * and should not be stored in the cache, false if not. |
50 | * @return void |
51 | */ |
52 | public function add($config_name, $config_value, $is_dynamic = false) |
53 | { |
54 | if (isset($this->config[$config_name])) |
55 | { |
56 | return; |
57 | } |
58 | |
59 | $this->config->set($config_name, $config_value, !$is_dynamic); |
60 | } |
61 | |
62 | /** |
63 | * Update an existing config setting. |
64 | * |
65 | * @param string $config_name The name of the config setting you would |
66 | * like to update |
67 | * @param mixed $config_value The value of the config setting |
68 | * @return void |
69 | * @throws \phpbb\db\migration\exception |
70 | */ |
71 | public function update($config_name, $config_value) |
72 | { |
73 | if (!isset($this->config[$config_name])) |
74 | { |
75 | throw new \phpbb\db\migration\exception('CONFIG_NOT_EXIST', $config_name); |
76 | } |
77 | |
78 | $this->config->set($config_name, $config_value); |
79 | } |
80 | |
81 | /** |
82 | * Update a config setting if the first argument equal to the |
83 | * current config value |
84 | * |
85 | * @param string $compare If equal to the current config value, will be |
86 | * updated to the new config value, otherwise not |
87 | * @param string $config_name The name of the config setting you would |
88 | * like to update |
89 | * @param mixed $config_value The value of the config setting |
90 | * @return void |
91 | * @throws \phpbb\db\migration\exception |
92 | */ |
93 | public function update_if_equals($compare, $config_name, $config_value) |
94 | { |
95 | if (!isset($this->config[$config_name])) |
96 | { |
97 | throw new \phpbb\db\migration\exception('CONFIG_NOT_EXIST', $config_name); |
98 | } |
99 | |
100 | $this->config->set_atomic($config_name, $compare, $config_value); |
101 | } |
102 | |
103 | /** |
104 | * Remove an existing config setting. |
105 | * |
106 | * @param string $config_name The name of the config setting you would |
107 | * like to remove |
108 | * @return void |
109 | */ |
110 | public function remove($config_name) |
111 | { |
112 | if (!isset($this->config[$config_name])) |
113 | { |
114 | return; |
115 | } |
116 | |
117 | $this->config->delete($config_name); |
118 | } |
119 | |
120 | /** |
121 | * {@inheritdoc} |
122 | */ |
123 | public function reverse() |
124 | { |
125 | $arguments = func_get_args(); |
126 | $original_call = array_shift($arguments); |
127 | |
128 | $call = false; |
129 | switch ($original_call) |
130 | { |
131 | case 'add': |
132 | $call = 'remove'; |
133 | break; |
134 | |
135 | case 'remove': |
136 | $call = 'add'; |
137 | if (count($arguments) == 1) |
138 | { |
139 | $arguments[] = ''; |
140 | } |
141 | break; |
142 | |
143 | case 'update_if_equals': |
144 | $call = 'update_if_equals'; |
145 | |
146 | // Set to the original value if the current value is what we compared to originally |
147 | $arguments = array( |
148 | $arguments[2], |
149 | $arguments[1], |
150 | $arguments[0], |
151 | ); |
152 | break; |
153 | |
154 | case 'reverse': |
155 | // Reversing a reverse is just the call itself |
156 | $call = array_shift($arguments); |
157 | break; |
158 | } |
159 | |
160 | if ($call) |
161 | { |
162 | return call_user_func_array(array(&$this, $call), $arguments); |
163 | } |
164 | |
165 | return null; |
166 | } |
167 | } |