1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class BuildCommand. |
5
|
|
|
*/ |
6
|
|
|
class BuildCommand extends SilverstripeCommand |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var string |
10
|
|
|
*/ |
11
|
|
|
protected $name = 'dev:build'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $description = 'Rebuild the database'; |
17
|
|
|
|
18
|
|
|
CONST CHANGE = '+'; |
19
|
|
|
CONST DELETE = '-'; |
20
|
|
|
CONST NOTICE = '*'; |
21
|
|
|
CONST ERROR = '!'; |
22
|
|
|
|
23
|
|
|
public function fire() |
24
|
|
|
{ |
25
|
|
|
// make sure we have a fresh manifest |
26
|
|
|
$this->call('clear:cache'); |
27
|
|
|
|
28
|
|
|
/** @var DatabaseAdmin $da */ |
29
|
|
|
$da = DatabaseAdmin::create(); |
30
|
|
|
|
31
|
|
|
// hack untill we have something better... |
32
|
|
|
ob_start(); |
33
|
|
|
$da->doBuild(); |
34
|
|
|
$content = ob_get_contents(); |
35
|
|
|
ob_get_clean(); |
36
|
|
|
foreach(explode("\n", $content) as $line) { |
37
|
|
|
$this->displayBuildMessage($line); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function displayBuildMessage($buildMessage) |
42
|
|
|
{ |
43
|
|
|
$message = trim($buildMessage); |
44
|
|
|
|
45
|
|
|
$change = BuildCommand::CHANGE; |
46
|
|
|
$delete = BuildCommand::DELETE; |
47
|
|
|
$notice = BuildCommand::NOTICE; |
48
|
|
|
$error = BuildCommand::ERROR; |
49
|
|
|
|
50
|
|
|
if(Str::startsWith($message, $change)) { |
51
|
|
|
$this->info($this->parseMessage($message, $change)); |
52
|
|
|
}elseif(Str::startsWith($message, $delete)) { |
53
|
|
|
$this->warn($this->parseMessage($message, $delete)); |
54
|
|
|
}elseif(Str::startsWith($message, $notice)) { |
55
|
|
|
$this->comment($this->parseMessage($message, $notice)); |
56
|
|
|
}elseif(Str::startsWith($message, $error)) { |
57
|
|
|
$this->error($this->parseMessage($message, $error)); |
58
|
|
|
}elseif($message){ |
59
|
|
|
$this->line($this->parseMessage($message)); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $message |
65
|
|
|
* @param string$replace |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
protected function parseMessage($message, $replace = '') |
69
|
|
|
{ |
70
|
|
|
if($replace) { |
71
|
|
|
$message = Str::replaceFirst($replace, '', $message); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return trim($message); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.