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/Commands/Domain/CreateCommand.php b/src/app/Console/Commands/Domain/CreateCommand.php index c60bc878..e976539f 100644 --- a/src/app/Console/Commands/Domain/CreateCommand.php +++ b/src/app/Console/Commands/Domain/CreateCommand.php @@ -1,90 +1,90 @@ argument('domain')); // must use withTrashed(), because unique constraint $domain = \App\Domain::withTrashed()->where('namespace', $namespace)->first(); if ($domain && !$this->option('force')) { $this->error("Domain {$namespace} already exists."); return 1; } if ($domain) { if ($domain->deleted_at) { // set the status back to new $domain->status = \App\Domain::STATUS_NEW; $domain->save(); // remove existing entitlement $entitlement = \App\Entitlement::withTrashed()->where( [ 'entitleable_id' => $domain->id, 'entitleable_type' => \App\Domain::class ] )->first(); if ($entitlement) { $entitlement->forceDelete(); } // restore the domain to allow for the observer to handle the create job $domain->restore(); $this->info( sprintf( "Domain %s with ID %d revived. Remember to assign it to a wallet with 'domain:set-wallet'", $domain->namespace, $domain->id ) ); } else { $this->error("Domain {$namespace} not marked as deleted... examine more closely"); return 1; } } else { $domain = \App\Domain::create( [ 'namespace' => $namespace, - 'type' => Domain::TYPE_EXTERNAL, + 'type' => \App\Domain::TYPE_EXTERNAL, ] ); $this->info( sprintf( "Domain %s created with ID %d. Remember to assign it to a wallet with 'domain:set-wallet'", $domain->namespace, $domain->id ) ); } } } 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(); } ); } } } diff --git a/src/app/Console/ObjectRelationListCommand.php b/src/app/Console/ObjectRelationListCommand.php index 786dede6..fd9049a9 100644 --- a/src/app/Console/ObjectRelationListCommand.php +++ b/src/app/Console/ObjectRelationListCommand.php @@ -1,90 +1,87 @@ description = "List {$this->objectRelation} for a {$this->objectName}"; $this->signature = sprintf( "%s%s:%s {%s}", $this->commandPrefix ? $this->commandPrefix . ":" : "", $this->objectName, $this->objectRelation, $this->objectName ); $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}"; parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $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 (method_exists($object, $this->objectRelation)) { $result = call_user_func([$object, $this->objectRelation]); } elseif (property_exists($object, $this->objectRelation)) { $result = $object->{"{$this->objectRelation}"}; } else { $this->error("No such relation {$this->objectRelation}"); return 1; } - if ($result instanceof \Illuminate\Database\Eloquent\Collection) { - $result->each( - function ($entry) { - $this->info($this->toString($entry)); - } - ); - } elseif ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) { - $result->each( - function ($entry) { - $this->info($this->toString($entry)); - } - ); - } elseif (is_array($result)) { + // Convert query builder into a collection + if ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) { + $result = $result->get(); + } + + // Print the result + if ( + ($result instanceof \Illuminate\Database\Eloquent\Collection) + || is_array($result) + ) { foreach ($result as $entry) { $this->info($this->toString($entry)); } } else { $this->info($this->toString($result)); } } }