Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
75.86% |
22 / 29 |
|
77.78% |
7 / 9 |
CRAP | |
0.00% |
0 / 1 |
migration | |
75.86% |
22 / 29 |
|
77.78% |
7 / 9 |
14.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
depends_on | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
effectively_installed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
update_schema | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
revert_schema | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
update_data | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
revert_data | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
sql_query | |
57.14% |
8 / 14 |
|
0.00% |
0 / 1 |
5.26 | |||
get_queries | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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; |
15 | |
16 | /** |
17 | * Abstract base class for database migrations |
18 | * |
19 | * Each migration consists of a set of schema and data changes to be implemented |
20 | * in a subclass. This class provides various utility methods to simplify editing |
21 | * a phpBB. |
22 | */ |
23 | abstract class migration implements migration_interface |
24 | { |
25 | /** @var \phpbb\config\config */ |
26 | protected $config; |
27 | |
28 | /** @var \phpbb\db\driver\driver_interface */ |
29 | protected $db; |
30 | |
31 | /** @var \phpbb\db\tools\tools_interface */ |
32 | protected $db_tools; |
33 | |
34 | /** @var string */ |
35 | protected $table_prefix; |
36 | |
37 | /** @var array Tables array */ |
38 | protected $tables; |
39 | |
40 | /** @var string */ |
41 | protected $phpbb_root_path; |
42 | |
43 | /** @var string */ |
44 | protected $php_ext; |
45 | |
46 | /** @var array Errors, if any occurred */ |
47 | protected $errors; |
48 | |
49 | /** @var array List of queries executed through $this->sql_query() */ |
50 | protected $queries = array(); |
51 | |
52 | /** |
53 | * Constructor |
54 | * |
55 | * @param \phpbb\config\config $config |
56 | * @param \phpbb\db\driver\driver_interface $db |
57 | * @param \phpbb\db\tools\tools_interface $db_tools |
58 | * @param string $phpbb_root_path |
59 | * @param string $php_ext |
60 | * @param string $table_prefix |
61 | * @param array $tables |
62 | */ |
63 | public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\db\tools\tools_interface $db_tools, $phpbb_root_path, $php_ext, $table_prefix, $tables) |
64 | { |
65 | $this->config = $config; |
66 | $this->db = $db; |
67 | $this->db_tools = $db_tools; |
68 | $this->table_prefix = $table_prefix; |
69 | $this->tables = $tables; |
70 | |
71 | $this->phpbb_root_path = $phpbb_root_path; |
72 | $this->php_ext = $php_ext; |
73 | |
74 | $this->errors = array(); |
75 | } |
76 | |
77 | /** |
78 | * {@inheritdoc} |
79 | */ |
80 | public static function depends_on() |
81 | { |
82 | return array(); |
83 | } |
84 | |
85 | /** |
86 | * {@inheritdoc} |
87 | */ |
88 | public function effectively_installed() |
89 | { |
90 | return false; |
91 | } |
92 | |
93 | /** |
94 | * {@inheritdoc} |
95 | */ |
96 | public function update_schema() |
97 | { |
98 | return array(); |
99 | } |
100 | |
101 | /** |
102 | * {@inheritdoc} |
103 | */ |
104 | public function revert_schema() |
105 | { |
106 | return array(); |
107 | } |
108 | |
109 | /** |
110 | * {@inheritdoc} |
111 | */ |
112 | public function update_data() |
113 | { |
114 | return array(); |
115 | } |
116 | |
117 | /** |
118 | * {@inheritdoc} |
119 | */ |
120 | public function revert_data() |
121 | { |
122 | return array(); |
123 | } |
124 | |
125 | /** |
126 | * Wrapper for running queries to generate user feedback on updates |
127 | * |
128 | * @param string $sql SQL query to run on the database |
129 | * @return mixed Query result from db->sql_query() |
130 | */ |
131 | protected function sql_query($sql) |
132 | { |
133 | $this->queries[] = $sql; |
134 | |
135 | $this->db->sql_return_on_error(true); |
136 | |
137 | if ($sql === 'begin') |
138 | { |
139 | $result = $this->db->sql_transaction('begin'); |
140 | } |
141 | else if ($sql === 'commit') |
142 | { |
143 | $result = $this->db->sql_transaction('commit'); |
144 | } |
145 | else |
146 | { |
147 | $result = $this->db->sql_query($sql); |
148 | if ($this->db->get_sql_error_triggered()) |
149 | { |
150 | $this->errors[] = array( |
151 | 'sql' => $this->db->get_sql_error_sql(), |
152 | 'code' => $this->db->get_sql_error_returned(), |
153 | ); |
154 | } |
155 | } |
156 | |
157 | $this->db->sql_return_on_error(false); |
158 | |
159 | return $result; |
160 | } |
161 | |
162 | /** |
163 | * Get the list of queries run |
164 | * |
165 | * @return array |
166 | */ |
167 | public function get_queries() |
168 | { |
169 | return $this->queries; |
170 | } |
171 | } |