1
|
|
|
<?php namespace Codengine\CustomMigrations; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class Migrator |
5
|
|
|
* The custom Migrator filters migrations of a specific type |
6
|
|
|
* |
7
|
|
|
* @package Codengine\CustomMigrations |
8
|
|
|
*/ |
9
|
|
|
class Migrator extends \Illuminate\Database\Migrations\Migrator { |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $migrationType = 'default'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Sets the migration type filter |
17
|
|
|
* |
18
|
|
|
* @param string $type |
19
|
|
|
*/ |
20
|
|
|
public function setMigrationType($type) |
21
|
|
|
{ |
22
|
|
|
$this->migrationType = $type; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the migration type filter |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function getMigrationType() |
31
|
|
|
{ |
32
|
|
|
return $this->migrationType; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Resolves the migration and filters those that don't match the migration type |
37
|
|
|
* |
38
|
|
|
* @param string $migration |
39
|
|
|
* @return bool Returns TRUE on a match, else FALSE |
40
|
|
|
*/ |
41
|
|
|
protected function filterMigrations($migration) |
42
|
|
|
{ |
43
|
|
|
$instance = $this->resolve($migration); |
44
|
|
|
if(empty($instance->type)) |
45
|
|
|
{ |
46
|
|
|
$instance->type = 'default'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if($this->migrationType != $instance->type) |
50
|
|
|
{ |
51
|
|
|
return false; |
52
|
|
|
} else { |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Gets a filtered list of migrations and runs them |
59
|
|
|
* |
60
|
|
|
* @param array $migrations |
61
|
|
|
* @param bool $pretend |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
public function runMigrationList($migrations, array $options=[]) |
64
|
|
|
{ |
65
|
|
|
$this->note("Running " . ($this->migrationType == "default" ? "default" : "custom") . " migrations for DB " . $this->connection); |
66
|
|
|
$migrations = array_filter($migrations, array($this, "filterMigrations")); |
67
|
|
|
parent::runMigrationList($migrations, $options); |
68
|
|
|
} |
69
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.