1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Console/Commands/MakeModule.php

98 lines
3.6 KiB
PHP
Raw Normal View History

2016-12-08 14:41:35 +01:00
<?php
namespace App\Console\Commands;
use Artisan;
use Illuminate\Console\Command;
class MakeModule extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
2016-12-09 10:51:18 +01:00
protected $signature = 'ninja:make-module {name} {fields?} {--migrate=}';
2016-12-08 14:41:35 +01:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate Module CRUD';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$name = $this->argument('name');
$fields = $this->argument('fields');
2016-12-09 10:51:18 +01:00
$migrate = $this->option('migrate');
2016-12-08 19:00:13 +01:00
$lower = strtolower($name);
2016-12-13 11:51:13 +01:00
2016-12-08 22:13:40 +01:00
// convert 'name:string,description:text' to 'name,description'
$fillable = explode(',', $fields);
2017-01-30 17:05:31 +01:00
$fillable = array_map(function ($item) {
2016-12-08 22:13:40 +01:00
return explode(':', $item)[0];
}, $fillable);
2017-01-30 20:40:43 +01:00
$fillable = implode(',', $fillable);
2016-12-08 22:13:40 +01:00
2016-12-09 12:38:11 +01:00
$this->info("Creating module: {$name}...");
2016-12-08 14:41:35 +01:00
Artisan::call('module:make', ['name' => [$name]]);
2016-12-08 19:00:13 +01:00
Artisan::call('module:make-migration', ['name' => "create_{$lower}_table", '--fields' => $fields, 'module' => $name]);
2016-12-08 22:13:40 +01:00
Artisan::call('module:make-model', ['model' => $name, 'module' => $name, '--fillable' => $fillable]);
2016-12-08 14:41:35 +01:00
2016-12-08 23:06:31 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'views', '--fields' => $fields, '--filename' => 'edit.blade']);
2016-12-08 22:13:40 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'datatable', '--fields' => $fields]);
2016-12-08 23:18:10 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository', '--fields' => $fields]);
2016-12-08 19:00:13 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
2016-12-08 21:39:15 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request']);
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'create']);
2016-12-08 21:51:53 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'update']);
2016-12-09 09:43:20 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'api-controller']);
2016-12-09 10:26:21 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'transformer', '--fields' => $fields]);
2016-12-09 11:35:49 +01:00
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'lang', '--filename' => 'texts']);
2016-12-08 19:00:13 +01:00
2016-12-13 11:51:13 +01:00
if ($migrate == 'false') {
2016-12-09 10:51:18 +01:00
$this->info("Use the following command to run the migrations:\nphp artisan module:migrate $name");
2016-12-13 11:51:13 +01:00
} else {
Artisan::call('module:migrate', ['module' => $name]);
2016-12-09 10:51:18 +01:00
}
2016-12-08 19:00:13 +01:00
Artisan::call('module:dump');
2016-12-09 12:38:11 +01:00
2017-01-30 20:40:43 +01:00
$this->info('Done');
2016-12-08 14:41:35 +01:00
}
protected function getArguments()
{
return [
['name', InputArgument::REQUIRED, 'The name of the module.'],
2017-01-30 20:40:43 +01:00
['fields', InputArgument::OPTIONAL, 'The fields of the module.'],
2016-12-08 14:41:35 +01:00
];
}
2016-12-08 22:13:40 +01:00
2016-12-09 10:51:18 +01:00
protected function getOptions()
{
2017-01-30 20:40:43 +01:00
return [
['migrate', null, InputOption::VALUE_OPTIONAL, 'The model attributes.', null],
];
2016-12-09 10:51:18 +01:00
}
2016-12-08 14:41:35 +01:00
}