Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Discount/MergeCommand.php
<?php | <?php | ||||
namespace App\Console\Commands\Discount; | namespace App\Console\Commands\Discount; | ||||
use Illuminate\Console\Command; | use App\Console\Command; | ||||
/** | /** | ||||
* Merge one discount (source) with another discount (target), and delete the source discount. | * Merge one discount (source) with another discount (target), and delete the source discount. | ||||
* | * | ||||
* This command re-associates the wallets that are discounted with the source discount to become discounted with the | * This command re-associates the wallets that are discounted with the source discount to become discounted with the | ||||
* target discount. | * target discount. | ||||
* | * | ||||
* Optionally, update the description of the target discount. | * Optionally, update the description of the target discount. | ||||
Show All 25 Lines | class MergeCommand extends Command | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Merge one discount in to another discount, ' . | protected $description = 'Merge one discount in to another discount, ' . | ||||
'optionally set the description, and delete the source 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. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$source = \App\Discount::find($this->argument('source')); | $source = $this->getObject(\App\Discount::class, $this->argument('source')); | ||||
if (!$source) { | if (!$source) { | ||||
$this->error("No such source discount: {$source}"); | $this->error("No such source discount: {$source}"); | ||||
return 1; | return 1; | ||||
} | } | ||||
$target = \App\Discount::find($this->argument('target')); | $target = $this->getObject(\App\Discount::class, $this->argument('target')); | ||||
if (!$target) { | if (!$target) { | ||||
$this->error("No such target discount: {$target}"); | $this->error("No such target discount: {$target}"); | ||||
return 1; | return 1; | ||||
} | } | ||||
if ($source->discount !== $target->discount) { | if ($source->discount !== $target->discount) { | ||||
$this->error("Can't merge two discounts that have different rates"); | $this->error("Can't merge two discounts that have different rates"); | ||||
Show All 17 Lines |