diff --git a/bin/doctum b/bin/doctum index 1aab12a7..569d076b 100755 --- a/bin/doctum +++ b/bin/doctum @@ -1,15 +1,15 @@ #!/bin/bash cwd=$(dirname $0) pushd ${cwd}/../src/ -rm -rf ../docs/build/main/ cache/store/ +rm -rf cache/store/ php -dmemory_limit=-1 \ vendor/bin/doctum.php \ update \ doctum.config.php \ -v popd diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php index 63808a8e..2036fb70 100644 --- a/src/app/Console/Command.php +++ b/src/app/Console/Command.php @@ -1,112 +1,104 @@ getObject(\App\Domain::class, $domain, 'namespace'); } /** * Find an object. * * @param string $objectClass The name of the class * @param string $objectIdOrTitle The name of a database field to match. * @param string|null $objectTitle An additional database field to match. * * @return mixed */ public function getObject($objectClass, $objectIdOrTitle, $objectTitle) { - if ($this->hasOption('with-deleted') && $this->option('with-deleted')) { - $object = $objectClass::withTrashed()->find($objectIdOrTitle); - } else { - $object = $objectClass::find($objectIdOrTitle); - } + $object = $objectClass::find($objectIdOrTitle); if (!$object && !empty($objectTitle)) { - if ($this->hasOption('with-deleted') && $this->option('with-deleted')) { - $object = $objectClass::withTrashed()->where($objectTitle, $objectIdOrTitle)->first(); - } else { - $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first(); - } + $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first(); } return $object; } /** * Find the user. * * @param string $user User ID or email * * @return \App\User|null */ public function getUser($user) { return $this->getObject(\App\User::class, $user, 'email'); } /** * Find the wallet. * * @param string $wallet Wallet ID * * @return \App\Wallet|null */ public function getWallet($wallet) { return $this->getObject(\App\Wallet::class, $wallet, null); } /** * Return a string for output, with any additional attributes specified as well. * * @param mixed $entry An object * * @return string */ protected function toString($entry) { /** * Haven't figured out yet, how to test if this command implements an option for additional * attributes. if (!in_array('attr', $this->options())) { return $entry->{$entry->getKeyName()}; } */ $str = [ $entry->{$entry->getKeyName()} ]; foreach ($this->option('attr') as $attr) { if ($attr == $entry->getKeyName()) { $this->warn("Specifying {$attr} is not useful."); continue; } if (!array_key_exists($attr, $entry->toArray())) { $this->error("Attribute {$attr} isn't available"); continue; } if (is_numeric($entry->{$attr})) { $str[] = $entry->{$attr}; } else { $str[] = !empty($entry->{$attr}) ? $entry->{$attr} : "null"; } } return implode(" ", $str); } } diff --git a/src/app/Console/Commands/DiscountsCommand.php b/src/app/Console/Commands/DiscountsCommand.php deleted file mode 100644 index ad469186..00000000 --- a/src/app/Console/Commands/DiscountsCommand.php +++ /dev/null @@ -1,12 +0,0 @@ -properties = $this->getProperties(); - - $entitleable = call_user_func_array( - [$this->properties['entitleable_type'], 'find'], - [$this->properties['entitleable_id']] - ); - - if (!$entitleable) { - $this->error("No such {$this->properties['entitleable_type']}"); - return 1; - } - - if (!array_key_exists('entitleable_id', $this->properties)) { - $this->error("Specify --entitleable_id"); - } - - if (array_key_exists('sku_id', $this->properties)) { - $sku = \App\Sku::find($this->properties['sku_id']); - - if (!$sku) { - $this->error("No such SKU {$this->properties['sku_id']}"); - return 1; - } - - if ($this->properties['cost'] == null) { - $this->properties['cost'] = $sku->cost; - } - } - - if (array_key_exists('wallet_id', $this->properties)) { - $wallet = \App\Wallet::find($this->properties['wallet_id']); - - if (!$wallet) { - $this->error("No such wallet {$this->properties['wallet_id']}"); - return 1; - } - } - - parent::handle(); - } -} diff --git a/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php deleted file mode 100644 index fd6437a7..00000000 --- a/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php +++ /dev/null @@ -1,13 +0,0 @@ -description = "Create a {$this->objectName}"; - $this->signature = sprintf( - "%s%s:create", - $this->commandPrefix ? $this->commandPrefix . ":" : "", - $this->objectName - ); - - $class = new $this->objectClass(); - - foreach ($class->getFillable() as $fillable) { - $this->signature .= " {--{$fillable}=}"; - } - - parent::__construct(); - } - - public function getProperties() - { - if (!empty($this->properties)) { - return $this->properties; - } - - $class = new $this->objectClass(); - - $this->properties = []; - - foreach ($class->getFillable() as $fillable) { - $this->properties[$fillable] = $this->option($fillable); - } - - return $this->properties; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - $this->getProperties(); - - $class = new $this->objectClass(); - - $object = $this->objectClass::create($this->properties); - - if ($object) { - $this->info($object->{$class->getKeyName()}); - } else { - $this->error("Object could not be created."); - } - - return $object; - } -} diff --git a/src/app/Console/ObjectListCommand.php b/src/app/Console/ObjectListCommand.php deleted file mode 100644 index 159f896b..00000000 --- a/src/app/Console/ObjectListCommand.php +++ /dev/null @@ -1,56 +0,0 @@ -description = "List {$this->objectName}s"; - - $classes = class_uses_recursive($this->objectClass); - - $this->signature = $this->commandPrefix ? $this->commandPrefix . ":" : ""; - $this->signature .= "{$this->objectName}s"; - - if (in_array(SoftDeletes::class, $classes)) { - $this->signature .= " {--with-deleted : Include deleted {$this->objectName}s}"; - } - - $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}"; - - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - $classes = class_uses_recursive($this->objectClass); - - if (in_array(SoftDeletes::class, $classes) && $this->option('with-deleted')) { - $objects = $this->objectClass::withTrashed(); - } else { - $objects = new $this->objectClass(); - } - - $objects->each( - function ($object) { - if ($object->deleted_at) { - $this->info("{$this->toString($object)} (deleted at {$object->deleted_at}"); - } else { - $this->info("{$this->toString($object)}"); - } - } - ); - } -} diff --git a/src/app/Console/ObjectReadCommand.php b/src/app/Console/ObjectReadCommand.php deleted file mode 100644 index 002fbe98..00000000 --- a/src/app/Console/ObjectReadCommand.php +++ /dev/null @@ -1,43 +0,0 @@ -description = "Read a {$this->objectName}"; - $this->signature = sprintf( - "%s%s:read {%s}", - $this->commandPrefix ? $this->commandPrefix . ":" : "", - $this->objectName, - $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; - } - - $this->info($this->toString($object)); - } -} diff --git a/src/app/Console/ObjectRelationListCommand.php b/src/app/Console/ObjectRelationListCommand.php deleted file mode 100644 index 40a89042..00000000 --- a/src/app/Console/ObjectRelationListCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -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)) { - foreach ($result as $entry) { - $this->info($this->toString($entry)); - } - } else { - $this->info($this->toString($result)); - } - } -} diff --git a/src/app/Console/ObjectUpdateCommand.php b/src/app/Console/ObjectUpdateCommand.php deleted file mode 100644 index c136a8c1..00000000 --- a/src/app/Console/ObjectUpdateCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -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) { - $this->error("No such {$this->objectName} {$argument}"); - return 1; - } - - foreach ($this->getProperties() as $property => $value) { - if ($property == "deleted_at" && $value == "null") { - $value = null; - } - - $object->{$property} = $value; - } - - $object->timestamps = false; - - $object->save(['timestamps' => false]); - } -}