Skip to content

Commit

Permalink
add skip option on command
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeta committed Jan 5, 2021
1 parent 4792c21 commit 346b041
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions src/Console/LaraPnnCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ public function handle()
{
$argument = $this->argument('model');

$skipAsk = $this->option('skip');

$this->model = app($argument);

if (! ($this->model instanceof LaraPnnAbstract)) {
throw new \InvalidArgumentException($argument.' must implement '.LaraPnnAbstract::class);
}

$this->line("\nRetrieval of eligible data in progess. ⌛");

$queryResults = $this->model->all();

$eligibleModels = [];
Expand All @@ -42,7 +46,7 @@ public function handle()

$this->line("\n <options=bold,reverse;fg=green>{$this->description} | Stats for {$this->model->getTable()} table: </> \n");
$this->line("<options=bold>Eligible row:</> {$eligibleModelsLength}");
$this->line("<options=bold>Eligible tel number column:</> {$eligibleModelsColumnsLength}");
$this->line("<options=bold>Eligible tel number column:</> {$eligibleModelsColumnsLength}\n");

if (!$eligibleModels) {

Expand All @@ -51,22 +55,26 @@ public function handle()
return false;
}

$migrate = $this->ask('You do want to continues ? [yes|no]', 'yes');

if ($migrate === 'yes') {
$start = microtime(true);
$start = microtime(true);

if ($skipAsk) {
$this->migrate($eligibleModels, $eligibleModelsColumns);
} else {
$migrate = $this->ask('You do want to continues ? [yes|no]', 'yes');

$time = number_format(microtime(true) - $start, 3);

$this->line("Execution time {$time} seconds\n");
if ($migrate === 'yes') {
$this->migrate($eligibleModels, $eligibleModelsColumns);
}
}

$time = number_format(microtime(true) - $start, 3);

$this->line("Execution time {$time} seconds\n");
}

private function migrate($models, $columns)
{
$this->line("Action in progress, please wait ! \n");
$this->line("Action in progress, please wait ! \n");

foreach ($columns as $column => $modelIds) {
$this->migrateByEligibleColumn($models, $column, $modelIds);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/LaraPnnMigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class LaraPnnMigrateCommand extends LaraPnnCommand
{
protected $signature = 'larapnn:migrate {model}';
protected $signature = 'larapnn:migrate {model} {--skip}';

protected $description = 'Migrate Your tel number for new plan';

Expand Down
4 changes: 2 additions & 2 deletions src/Console/LaraPnnRollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class LaraPnnRollbackCommand extends LaraPnnCommand
{
protected $signature = 'larapnn:rollback {model}';
protected $signature = 'larapnn:rollback {model} {--skip}';

protected $description = 'Rollback Your tel number for last plan';
protected $description = 'Rollback Your tel number for old plan';

protected function getEligibleFields($result)
{
Expand Down

0 comments on commit 346b041

Please sign in to comment.