Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/ObjectUpdateCommand.php
- This file was added.
<?php | |||||
namespace App\Console; | |||||
use Illuminate\Support\Facades\Schema; | |||||
/** | |||||
* This abstract class provides a means to treat objects in our model using CRUD. | |||||
*/ | |||||
abstract class ObjectUpdateCommand extends ObjectCommand | |||||
{ | |||||
public function __construct() | |||||
{ | |||||
$this->description = "Update a {$this->objectName}"; | |||||
$this->signature = sprintf( | |||||
"%s%s:update {%s}", | |||||
$this->commandPrefix ? $this->commandPrefix . ":" : "", | |||||
$this->objectName, | |||||
$this->objectName | |||||
); | |||||
$class = new $this->objectClass(); | |||||
foreach (Schema::getColumnListing($class->getTable()) as $column) { | |||||
if ($column == "id") { | |||||
continue; | |||||
} | |||||
$this->signature .= " {--{$column}=}"; | |||||
} | |||||
$this->signature .= sprintf( | |||||
" {--with-deleted : Include deleted %ss}", | |||||
$this->objectName | |||||
); | |||||
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() | |||||
{ | |||||
$argument = $this->argument($this->objectName); | |||||
$object = $this->getObject($this->objectClass, $argument, $this->objectTitle); | |||||
if (!$object) { | |||||
return 1; | |||||
machniak: An error message here. | |||||
} | |||||
foreach ($this->getProperties() as $property => $value) { | |||||
if ($property == "deleted_at" && $value == "null") { | |||||
$value = null; | |||||
} | |||||
$object->{$property} = $value; | |||||
} | |||||
$object->save(['timestamps' => false]); | |||||
machniakUnsubmitted Not Done Inline ActionsWe should make sure this timestamps=false really works. machniak: We should make sure this timestamps=false really works. | |||||
vanmeeuwenAuthorUnsubmitted Not Done Inline ActionsIt doesn't :/ It's a laravel 8.x-ism i think. vanmeeuwen: It doesn't :/
It's a laravel 8.x-ism i think. | |||||
} | |||||
} |
An error message here.