1
|
|
|
<?php |
2
|
|
|
namespace Elimuswift\DbExporter\Commands; |
3
|
|
|
|
4
|
|
|
use Config; |
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class GeneratorCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Get the database name from the app/config/database.php file |
13
|
|
|
* @return String |
14
|
|
|
*/ |
15
|
|
|
protected function getDatabaseName() |
16
|
|
|
{ |
17
|
|
|
$connType = Config::get('database.default'); |
18
|
|
|
$database = Config::get('database.connections.' .$connType ); |
19
|
|
|
|
20
|
|
|
return $database['database']; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function blockMessage($title, $message, $style = 'info') |
24
|
|
|
{ |
25
|
|
|
// Symfony style block messages |
26
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
27
|
|
|
$errorMessages = array($title, $message); |
28
|
|
|
$formattedBlock = $formatter->formatBlock($errorMessages, $style, true); |
29
|
|
|
$this->line($formattedBlock); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function sectionMessage($title, $message) |
33
|
|
|
{ |
34
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
35
|
|
|
$formattedLine = $formatter->formatSection( |
36
|
|
|
$title, |
37
|
|
|
$message |
38
|
|
|
); |
39
|
|
|
$this->line($formattedLine); |
40
|
|
|
} |
41
|
|
|
protected function getArguments() |
42
|
|
|
{ |
43
|
|
|
return array( |
44
|
|
|
array('database', InputArgument::OPTIONAL, 'Override the application database') |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function getOptions() |
49
|
|
|
{ |
50
|
|
|
return array( |
51
|
|
|
array('ignore', 'i', InputOption::VALUE_REQUIRED, 'Ignore tables to export, seperated by a comma', null) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function fireAction($action,$database) |
56
|
|
|
{ |
57
|
|
|
// Grab the options |
58
|
|
|
$ignore = $this->option('ignore'); |
59
|
|
|
|
60
|
|
|
if (empty($ignore)) { |
61
|
|
|
$this->handler->$action($database); |
62
|
|
|
} else { |
63
|
|
|
$tables = explode(',', str_replace(' ', '', $ignore)); |
64
|
|
|
|
65
|
|
|
$this->handler->ignore($tables)->$action($database); |
66
|
|
|
foreach (DbExporter::$ignore as $table) { |
67
|
|
|
$this->comment("Ignoring the {$table} table"); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |