diff --git a/src/app/Console/Commands/Discount/MergeCommand.php b/src/app/Console/Commands/Discount/MergeCommand.php index 272764c0..a581cc16 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 = $target; + $wallet->discount_id = $target->id; $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/ObjectDeleteCommand.php b/src/app/Console/ObjectDeleteCommand.php index 3e228480..098d2097 100644 --- a/src/app/Console/ObjectDeleteCommand.php +++ b/src/app/Console/ObjectDeleteCommand.php @@ -1,95 +1,95 @@ description = "Delete a {$this->objectName}"; $this->signature = sprintf( "%s%s:delete {%s}", $this->commandPrefix ? $this->commandPrefix . ":" : "", $this->objectName, $this->objectName ); $class = new $this->objectClass(); try { foreach (Schema::getColumnListing($class->getTable()) as $column) { if ($column == "id") { continue; } $this->signature .= " {--{$column}=}"; } } catch (\Exception $e) { \Log::error("Could not extract options: {$e->getMessage()}"); } $classes = class_uses_recursive($this->objectClass); parent::__construct(); } public function getProperties() { if (!empty($this->properties)) { return $this->properties; } $class = new $this->objectClass(); $this->properties = []; foreach (Schema::getColumnListing($class->getTable()) as $column) { if ($column == "id") { continue; } if (($value = $this->option($column)) !== null) { $this->properties[$column] = $value; } } return $this->properties; } /** * Execute the console command. * * @return mixed */ public function handle() { $result = parent::handle(); if (!$result) { return 1; } $argument = $this->argument($this->objectName); $object = $this->getObject($this->objectClass, $argument, $this->objectTitle); if (!$object) { $this->error("No such {$this->objectName} {$argument}"); return 1; } if ($this->commandPrefix == 'scalpel') { $this->objectClass::withoutEvents( function () use ($object) { $object->delete(); } ); } } }