Skip to content

Commit f24fa12

Browse files
committed
Added dbm:seed command
1 parent 4e8d2af commit f24fa12

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/Commands/DatabaseSeed.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace CodexShaper\DBM\Commands;
4+
5+
use CodexShaper\DBM\ManagerServiceProvider;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Filesystem\Filesystem;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Process\Process;
10+
11+
class DatabaseSeed extends Command
12+
{
13+
/**
14+
* The console command name.
15+
*
16+
* @var string
17+
*/
18+
protected $name = 'dbm:seed';
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Seed the Laravel Database Manager';
25+
/**
26+
* The database Seeder Path.
27+
*
28+
* @var string
29+
*/
30+
protected $seedersPath = __DIR__.'/../../database/seeds/';
31+
32+
/**
33+
* Get Option.
34+
*
35+
* @return array
36+
*/
37+
protected function getOptions()
38+
{
39+
return [
40+
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null],
41+
];
42+
}
43+
44+
/**
45+
* Get the composer command for the environment.
46+
*
47+
* @return string
48+
*/
49+
protected function findComposer()
50+
{
51+
if (file_exists(getcwd().'/composer.phar')) {
52+
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
53+
}
54+
55+
return 'composer';
56+
}
57+
58+
/**
59+
* Execute the console command.
60+
*
61+
* @param \Illuminate\Filesystem\Filesystem $filesystem
62+
*
63+
* @return void
64+
*/
65+
public function handle(Filesystem $filesystem)
66+
{
67+
$this->info('Database Manager Seeding...');
68+
// Seeding Dummy Data
69+
$class = 'DatabaseManagerSeeder';
70+
$file = $this->seedersPath.$class.'.php';
71+
if (file_exists($file) && ! class_exists($class)) {
72+
require_once $file;
73+
}
74+
with(new $class())->run();
75+
76+
$this->info('Seeding Completed');
77+
}
78+
}

src/ManagerServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CodexShaper\DBM\Commands\DatabaseAdmin;
66
use CodexShaper\DBM\Commands\DatabaseBackup;
77
use CodexShaper\DBM\Commands\DatabaseRestore;
8+
use CodexShaper\DBM\Commands\DatabaseSeed;
89
use CodexShaper\DBM\Commands\InstallDatabaseManager;
910
use CodexShaper\DBM\MongoDB\Passport\AuthCode;
1011
use CodexShaper\DBM\MongoDB\Passport\Bridge\RefreshToken;
@@ -146,5 +147,6 @@ private function registerCommands()
146147
$this->commands(DatabaseAdmin::class);
147148
$this->commands(DatabaseBackup::class);
148149
$this->commands(DatabaseRestore::class);
150+
$this->commands(DatabaseSeed::class);
149151
}
150152
}

0 commit comments

Comments
 (0)