|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Console\Commands; |
| 4 | + |
| 5 | +use Illuminate\Console\Command; |
| 6 | +use Illuminate\Support\Facades\File; |
| 7 | + |
| 8 | +class EcommerceInstall extends Command |
| 9 | +{ |
| 10 | + /** |
| 11 | + * The name and signature of the console command. |
| 12 | + * |
| 13 | + * @var string |
| 14 | + */ |
| 15 | + protected $signature = 'ecommerce:install {--force : Do not ask for user confirmation}'; |
| 16 | + |
| 17 | + /** |
| 18 | + * The console command description. |
| 19 | + * |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + protected $description = 'Install dummy data for the Ecommerce Application'; |
| 23 | + |
| 24 | + /** |
| 25 | + * Create a new command instance. |
| 26 | + * |
| 27 | + * @return void |
| 28 | + */ |
| 29 | + public function __construct() |
| 30 | + { |
| 31 | + parent::__construct(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Execute the console command. |
| 36 | + * |
| 37 | + * @return mixed |
| 38 | + */ |
| 39 | + public function handle() |
| 40 | + { |
| 41 | + if ($this->option('force')) { |
| 42 | + $this->proceed(); |
| 43 | + } else { |
| 44 | + if ($this->confirm('This will delete ALL your current data and install the default dummy data. Are you sure?')) { |
| 45 | + $this->proceed(); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + protected function proceed() |
| 51 | + { |
| 52 | + File::deleteDirectory(public_path('storage/products/dummy')); |
| 53 | + $this->callSilent('storage:link'); |
| 54 | + $copySuccess = File::copyDirectory(public_path('img/products'), public_path('storage/products/dummy')); |
| 55 | + if ($copySuccess) { |
| 56 | + $this->info('Images successfully copied to storage folder.'); |
| 57 | + } |
| 58 | + |
| 59 | + $this->call('migrate:fresh', [ |
| 60 | + '--seed' => true, |
| 61 | + ]); |
| 62 | + |
| 63 | + $this->call('db:seed', [ |
| 64 | + '--class' => 'VoyagerDatabaseSeeder', |
| 65 | + ]); |
| 66 | + |
| 67 | + $this->call('db:seed', [ |
| 68 | + '--class' => 'VoyagerDummyDatabaseSeeder', |
| 69 | + ]); |
| 70 | + |
| 71 | + $this->call('db:seed', [ |
| 72 | + '--class' => 'DataTypesTableSeederCustom', |
| 73 | + ]); |
| 74 | + |
| 75 | + $this->call('db:seed', [ |
| 76 | + '--class' => 'DataRowsTableSeederCustom', |
| 77 | + ]); |
| 78 | + |
| 79 | + $this->call('db:seed', [ |
| 80 | + '--class' => 'MenusTableSeederCustom', |
| 81 | + ]); |
| 82 | + |
| 83 | + $this->call('db:seed', [ |
| 84 | + '--class' => 'MenuItemsTableSeederCustom', |
| 85 | + ]); |
| 86 | + |
| 87 | + $this->call('db:seed', [ |
| 88 | + '--class' => 'RolesTableSeederCustom', |
| 89 | + ]); |
| 90 | + |
| 91 | + $this->call('db:seed', [ |
| 92 | + '--class' => 'PermissionsTableSeederCustom', |
| 93 | + ]); |
| 94 | + |
| 95 | + $this->call('db:seed', [ |
| 96 | + '--class' => 'PermissionRoleTableSeeder', |
| 97 | + ]); |
| 98 | + |
| 99 | + $this->call('db:seed', [ |
| 100 | + '--class' => 'PermissionRoleTableSeederCustom', |
| 101 | + ]); |
| 102 | + |
| 103 | + $this->call('db:seed', [ |
| 104 | + '--class' => 'UsersTableSeederCustom', |
| 105 | + ]); |
| 106 | + |
| 107 | + $this->info('Dummy data installed'); |
| 108 | + } |
| 109 | +} |
0 commit comments