|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RDV\Bundle\MigrationBundle\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Doctrine\DBAL\DBALException; |
|
7
|
|
|
use RDV\Bundle\MigrationBundle\Migration\Migration; |
|
8
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
9
|
|
|
|
|
10
|
|
|
class MigrationEvent extends Event |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Migration[] |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $migrations = []; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Connection |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $connection; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param Connection $connection |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(Connection $connection) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->connection = $connection; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Adds a migration |
|
32
|
|
|
* |
|
33
|
|
|
* @param Migration $migration |
|
34
|
|
|
* @param bool $prepend If TRUE a migration is added to the beginning of the list |
|
35
|
|
|
*/ |
|
36
|
|
|
public function addMigration(Migration $migration, $prepend = false) |
|
37
|
|
|
{ |
|
38
|
|
|
if ($prepend) { |
|
39
|
|
|
array_unshift($this->migrations, $migration); |
|
40
|
|
|
} else { |
|
41
|
|
|
array_push($this->migrations, $migration); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Gets all migrations |
|
47
|
|
|
* |
|
48
|
|
|
* @return Migration[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getMigrations() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->migrations; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Prepares and executes an SQL query and returns the result as an associative array. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $sql The SQL query. |
|
59
|
|
|
* @param array $params The query parameters. |
|
60
|
|
|
* @param array $types The query parameter types. |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getData($sql, array $params = array(), $types = array()) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->connection->connect(); |
|
66
|
|
|
|
|
67
|
|
|
return $this->connection->fetchAll($sql, $params, $types); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Check if the given table exists in a database |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $tableName |
|
74
|
|
|
* @return bool TRUE if a table exists; otherwise, FALSE |
|
75
|
|
|
*/ |
|
76
|
|
|
public function isTableExist($tableName) |
|
77
|
|
|
{ |
|
78
|
|
|
if (!empty($tableName)) { |
|
79
|
|
|
try { |
|
80
|
|
|
$this->connection->connect(); |
|
81
|
|
|
return $this->connection->getSchemaManager()->tablesExist($tableName); |
|
|
|
|
|
|
82
|
|
|
} catch (\PDOException $e) { |
|
|
|
|
|
|
83
|
|
|
} catch (DBALException $e) { |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: