Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.67% covered (warning)
76.67%
23 / 30
77.78% covered (warning)
77.78%
7 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
migration
76.67% covered (warning)
76.67%
23 / 30
77.78% covered (warning)
77.78%
7 / 9
13.83
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 depends_on
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 effectively_installed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update_schema
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 revert_schema
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update_data
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 revert_data
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 sql_query
57.14% covered (warning)
57.14%
8 / 14
0.00% covered (danger)
0.00%
0 / 1
5.26
 get_queries
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
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
14namespace 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*/
23abstract 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        $this->db_tools->set_table_prefix($this->table_prefix);
77    }
78
79    /**
80    * {@inheritdoc}
81    */
82    public static function depends_on()
83    {
84        return array();
85    }
86
87    /**
88    * {@inheritdoc}
89    */
90    public function effectively_installed()
91    {
92        return false;
93    }
94
95    /**
96    * {@inheritdoc}
97    */
98    public function update_schema()
99    {
100        return array();
101    }
102
103    /**
104    * {@inheritdoc}
105    */
106    public function revert_schema()
107    {
108        return array();
109    }
110
111    /**
112    * {@inheritdoc}
113    */
114    public function update_data()
115    {
116        return array();
117    }
118
119    /**
120    * {@inheritdoc}
121    */
122    public function revert_data()
123    {
124        return array();
125    }
126
127    /**
128    * Wrapper for running queries to generate user feedback on updates
129    *
130    * @param string $sql SQL query to run on the database
131    * @return mixed Query result from db->sql_query()
132    */
133    protected function sql_query($sql)
134    {
135        $this->queries[] = $sql;
136
137        $this->db->sql_return_on_error(true);
138
139        if ($sql === 'begin')
140        {
141            $result = $this->db->sql_transaction('begin');
142        }
143        else if ($sql === 'commit')
144        {
145            $result = $this->db->sql_transaction('commit');
146        }
147        else
148        {
149            $result = $this->db->sql_query($sql);
150            if ($this->db->get_sql_error_triggered())
151            {
152                $this->errors[] = array(
153                    'sql'    => $this->db->get_sql_error_sql(),
154                    'code'    => $this->db->get_sql_error_returned(),
155                );
156            }
157        }
158
159        $this->db->sql_return_on_error(false);
160
161        return $result;
162    }
163
164    /**
165    * Get the list of queries run
166    *
167    * @return array
168    */
169    public function get_queries()
170    {
171        return $this->queries;
172    }
173}