diff --git a/src/app/Console/Commands/Discount/MergeCommand.php b/src/app/Console/Commands/Discount/MergeCommand.php index a581cc16..272764c0 100644 --- a/src/app/Console/Commands/Discount/MergeCommand.php +++ b/src/app/Console/Commands/Discount/MergeCommand.php @@ -1,95 +1,95 @@ 158f660b-e992-4fb9-ac12-5173b5f33807 \ * > 62af659f-17d8-4527-87c1-c69eaa26653c \ * > --description="Employee discount" * ``` */ class MergeCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'discount:merge {source} {target} {--description*}'; /** * The console command description. * * @var string */ protected $description = 'Merge one discount in to another discount, ' . 'optionally set the description, and delete the source discount'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $source = \App\Discount::find($this->argument('source')); if (!$source) { $this->error("No such source discount: {$source}"); return 1; } $target = \App\Discount::find($this->argument('target')); if (!$target) { $this->error("No such target discount: {$target}"); return 1; } if ($source->discount !== $target->discount) { $this->error("Can't merge two discounts that have different rates"); return 1; } foreach ($source->wallets as $wallet) { - $wallet->discount_id = $target->id; + $wallet->discount = $target; $wallet->timestamps = false; $wallet->save(); } if ($this->option('description')) { - $target->description = $this->option('description'); + $target->{'description'} = $this->option('description'); $target->save(); } $source->delete(); } } diff --git a/src/app/Console/Commands/Scalpel/Discount/MergeCommand.php b/src/app/Console/Commands/Scalpel/Discount/MergeCommand.php deleted file mode 100644 index 912d7665..00000000 --- a/src/app/Console/Commands/Scalpel/Discount/MergeCommand.php +++ /dev/null @@ -1,95 +0,0 @@ - 158f660b-e992-4fb9-ac12-5173b5f33807 \ - * > 62af659f-17d8-4527-87c1-c69eaa26653c \ - * > --description="Employee discount" - * ``` - */ -class MergeCommand extends Command -{ - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'scalpel:discount:merge {source} {target} {--description*}'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Merge one discount in to another discount, ' . - 'optionally set the description, and delete the source discount'; - - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - $source = \App\Discount::find($this->argument('source')); - - if (!$source) { - $this->error("No such source discount: {$source}"); - return 1; - } - - $target = \App\Discount::find($this->argument('target')); - - if (!$target) { - $this->error("No such target discount: {$target}"); - return 1; - } - - if ($source->discount !== $target->discount) { - $this->error("Can't merge two discounts that have different rates"); - return 1; - } - - foreach ($source->wallets as $wallet) { - $wallet->discount = $target; - $wallet->timestamps = false; - $wallet->save(); - } - - if ($this->option('description')) { - $target->{'description'} = $this->option('description'); - $target->save(); - } - - $source->delete(); - } -}