|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RDV\Bundle\MigrationBundle\Migration; |
|
4
|
|
|
|
|
5
|
|
|
class QueryBag |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var array |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $preQueries = []; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var array |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $postQueries = []; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Gets a list of SQL queries should be executed before UP migrations defined in this class |
|
19
|
|
|
* |
|
20
|
|
|
* @return array An SQL query can be a string or an instance of MigrationQuery |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getPreQueries() |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->preQueries; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Gets a list of SQL queries should be executed after UP migrations defined in this class |
|
29
|
|
|
* |
|
30
|
|
|
* @return array An SQL query can be a string or an instance of MigrationQuery |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getPostQueries() |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->postQueries; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register a SQL query should be executed before UP migrations defined in this class |
|
39
|
|
|
* |
|
40
|
|
|
* @param string|MigrationQuery $query |
|
41
|
|
|
*/ |
|
42
|
|
|
public function addPreQuery($query) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->preQueries[] = $query; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register a SQL query should be executed after UP migrations defined in this class |
|
49
|
|
|
* |
|
50
|
|
|
* @param string|MigrationQuery $query |
|
51
|
|
|
*/ |
|
52
|
|
|
public function addPostQuery($query) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->postQueries[] = $query; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Register a SQL query should be executed after UP migrations defined in this class |
|
59
|
|
|
* This method is just an alias for addPostQuery |
|
60
|
|
|
* |
|
61
|
|
|
* @param string|MigrationQuery $query |
|
62
|
|
|
*/ |
|
63
|
|
|
public function addQuery($query) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->postQueries[] = $query; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Clears all data in this bag |
|
70
|
|
|
*/ |
|
71
|
|
|
public function clear() |
|
72
|
|
|
{ |
|
73
|
|
|
if (!empty($this->preQueries)) { |
|
74
|
|
|
$this->preQueries = []; |
|
75
|
|
|
} |
|
76
|
|
|
if (!empty($this->postQueries)) { |
|
77
|
|
|
$this->postQueries = []; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|