|
1
|
|
|
<?php |
|
2
|
|
|
namespace Elimuswift\DbExporter\Commands; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use Elimuswift\DbExporter\DbExporter; |
|
6
|
|
|
use Elimuswift\DbExporter\DbExportHandler; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Config; |
|
9
|
|
|
use Illuminate\Support\Str; |
|
10
|
|
|
|
|
11
|
|
|
class SeedGeneratorCommand extends GeneratorCommand |
|
12
|
|
|
{ |
|
13
|
|
|
protected $name = 'db-exporter:seeds'; |
|
14
|
|
|
|
|
15
|
|
|
protected $description = 'Export your database table data to a seed class.'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Elimuswift\DbExporter\DbExportHandler |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $handler; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(DbExportHandler $handler) |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct(); |
|
25
|
|
|
|
|
26
|
|
|
$this->handler = $handler; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function fire() |
|
30
|
|
|
{ |
|
31
|
|
|
$database = $this->argument('database'); |
|
32
|
|
|
|
|
33
|
|
|
// Display some helpfull info |
|
34
|
|
|
if (empty($database)) { |
|
35
|
|
|
$this->comment("Preparing the seeder class for database {$this->getDatabaseName()}"); |
|
36
|
|
|
} else { |
|
37
|
|
|
$this->comment("Preparing the seeder class for database {$database}"); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Grab the options |
|
41
|
|
|
$this->fireAction('seed', $database); |
|
42
|
|
|
|
|
43
|
|
|
// Symfony style block messages |
|
44
|
|
|
$formatter = $this->getHelperSet()->get('formatter'); |
|
45
|
|
|
$filename = $this->getFilename(); |
|
46
|
|
|
|
|
47
|
|
|
$errorMessages = array('Success!', "Database seed class generated in: {$filename}"); |
|
48
|
|
|
|
|
49
|
|
|
$formattedBlock = $formatter->formatBlock($errorMessages, 'info', true); |
|
50
|
|
|
$this->line($formattedBlock); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function getFilename() |
|
54
|
|
|
{ |
|
55
|
|
|
$filename = Str::camel($this->getDatabaseName()) . "TableSeeder"; |
|
56
|
|
|
return Config::get('db-exporter.export_path.seeds')."/{$filename}.php"; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
} |