You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.2 KiB
118 lines
3.2 KiB
<?php
|
|
|
|
namespace Glmdev\Meta\Commands;
|
|
|
|
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as VanillaCommand;
|
|
use Glmdev\Meta\MetaMigrationCreator;
|
|
use \Illuminate\Support\Composer as Compsr;
|
|
|
|
class MetaMigrationCommand extends VanillaCommand {
|
|
|
|
/**
|
|
* The console command signature.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'meta:migration {name : The name of the migration.}
|
|
{--create= : The table to be created.}
|
|
{--table= : The table to migrate.}
|
|
{--path= : The location where the migration file should be created.}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Create a new meta-enabled migration file';
|
|
|
|
/**
|
|
* The migration creator instance.
|
|
*
|
|
* @var \Glmdev\Meta\MetaMigrationCreator
|
|
*/
|
|
protected $creator;
|
|
|
|
/**
|
|
* The Composer instance.
|
|
*
|
|
* @var \Illuminate\Support\Composer
|
|
*/
|
|
protected $composer;
|
|
|
|
/**
|
|
* Create a new migration install command instance.
|
|
*
|
|
* @param \Glmdev\Meta\MigrationCreator $creator
|
|
* @param \Illuminate\Support\Composer $composer
|
|
* @return void
|
|
*/
|
|
public function __construct(MetaMigrationCreator $creator, Compsr $composer)
|
|
{
|
|
parent::__construct($creator, $composer);
|
|
|
|
$this->creator = $creator;
|
|
$this->composer = $composer;
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function fire()
|
|
{
|
|
// It's possible for the developer to specify the tables to modify in this
|
|
// schema operation. The developer may also specify if this table needs
|
|
// to be freshly created so we can create the appropriate migrations.
|
|
$name = trim($this->input->getArgument('name'));
|
|
|
|
$table = $this->input->getOption('table');
|
|
|
|
$create = $this->input->getOption('create') ?: false;
|
|
|
|
if (! $table && is_string($create)) {
|
|
$table = $create;
|
|
|
|
$create = true;
|
|
}
|
|
|
|
// Now we are ready to write the migration out to disk. Once we've written
|
|
// the migration out, we will dump-autoload for the entire framework to
|
|
// make sure that the migrations are registered by the class loaders.
|
|
$this->writeMigration($name, $table, $create);
|
|
|
|
$this->composer->dumpAutoloads();
|
|
}
|
|
|
|
/**
|
|
* Write the migration file to disk.
|
|
*
|
|
* @param string $name
|
|
* @param string $table
|
|
* @param bool $create
|
|
* @return string
|
|
*/
|
|
protected function writeMigration($name, $table, $create)
|
|
{
|
|
$path = $this->getMigrationPath();
|
|
|
|
$file = pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);
|
|
|
|
$this->line("<info>Created Migration:</info> {$file}");
|
|
}
|
|
|
|
/**
|
|
* Get migration path (either specified by '--path' option or default location).
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function getMigrationPath()
|
|
{
|
|
if (! is_null($targetPath = $this->input->getOption('path'))) {
|
|
return $this->laravel->basePath().'/'.$targetPath;
|
|
}
|
|
|
|
return parent::getMigrationPath();
|
|
}
|
|
|
|
} |