Page MenuHomePhorge

D4388.1775508238.diff
No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None

D4388.1775508238.diff

diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php
--- a/src/app/Console/Command.php
+++ b/src/app/Console/Command.php
@@ -199,6 +199,11 @@
return $this->getObject(\App\Wallet::class, $wallet, null);
}
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
public function handle()
{
if ($this->dangerous) {
diff --git a/src/app/Console/Commands/Scalpel/TenantSetting/CreateCommand.php b/src/app/Console/Commands/Scalpel/TenantSetting/CreateCommand.php
--- a/src/app/Console/Commands/Scalpel/TenantSetting/CreateCommand.php
+++ b/src/app/Console/Commands/Scalpel/TenantSetting/CreateCommand.php
@@ -6,6 +6,8 @@
class CreateCommand extends ObjectCreateCommand
{
+ protected $hidden = true;
+
protected $commandPrefix = 'scalpel';
protected $objectClass = \App\TenantSetting::class;
protected $objectName = 'tenant-setting';
diff --git a/src/app/Console/Commands/Scalpel/TenantSetting/UpdateCommand.php b/src/app/Console/Commands/Scalpel/TenantSetting/UpdateCommand.php
--- a/src/app/Console/Commands/Scalpel/TenantSetting/UpdateCommand.php
+++ b/src/app/Console/Commands/Scalpel/TenantSetting/UpdateCommand.php
@@ -6,6 +6,8 @@
class UpdateCommand extends ObjectUpdateCommand
{
+ protected $hidden = true;
+
protected $commandPrefix = 'scalpel';
protected $objectClass = \App\TenantSetting::class;
protected $objectName = 'tenant-setting';
diff --git a/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php b/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php
--- a/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php
+++ b/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php
@@ -6,6 +6,8 @@
class SettingsCommand extends ObjectRelationListCommand
{
+ protected $hidden = true;
+
protected $commandPrefix = 'scalpel';
protected $objectClass = \App\Wallet::class;
protected $objectName = 'wallet';
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php
--- a/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php
@@ -6,6 +6,8 @@
class CreateCommand extends ObjectCreateCommand
{
+ protected $hidden = true;
+
protected $commandPrefix = 'scalpel';
protected $objectClass = \App\WalletSetting::class;
protected $objectName = 'wallet-setting';
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php
--- a/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php
@@ -6,6 +6,8 @@
class UpdateCommand extends ObjectUpdateCommand
{
+ protected $hidden = true;
+
protected $commandPrefix = 'scalpel';
protected $objectClass = \App\WalletSetting::class;
protected $objectName = 'wallet-setting';
diff --git a/src/app/Console/ObjectCreateCommand.php b/src/app/Console/ObjectCreateCommand.php
--- a/src/app/Console/ObjectCreateCommand.php
+++ b/src/app/Console/ObjectCreateCommand.php
@@ -25,7 +25,7 @@
parent::__construct();
}
- public function getProperties()
+ protected function getProperties()
{
if (!empty($this->properties)) {
return $this->properties;
@@ -44,19 +44,13 @@
/**
* Execute the console command.
- *
- * @return mixed
*/
public function handle()
{
- $this->getProperties();
-
- $class = new $this->objectClass();
-
- $object = $this->objectClass::create($this->properties);
+ $object = $this->objectClass::create($this->getProperties());
if ($object) {
- $this->info($object->{$class->getKeyName()});
+ $this->info($object->{$object->getKeyName()});
} else {
$this->error("Object could not be created.");
}
diff --git a/src/app/Console/ObjectDeleteCommand.php b/src/app/Console/ObjectDeleteCommand.php
--- a/src/app/Console/ObjectDeleteCommand.php
+++ b/src/app/Console/ObjectDeleteCommand.php
@@ -20,20 +20,6 @@
$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);
if (in_array(SoftDeletes::class, $classes)) {
@@ -43,29 +29,6 @@
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.
*
diff --git a/src/app/Console/ObjectUpdateCommand.php b/src/app/Console/ObjectUpdateCommand.php
--- a/src/app/Console/ObjectUpdateCommand.php
+++ b/src/app/Console/ObjectUpdateCommand.php
@@ -12,26 +12,35 @@
{
public function __construct()
{
+ global $argv;
+
+ $command = sprintf("%s%s:update", $this->commandPrefix ? $this->commandPrefix . ':' : '', $this->objectName);
+
$this->description = "Update a {$this->objectName}";
- $this->signature = sprintf(
- "%s%s:update {%s}",
- $this->commandPrefix ? $this->commandPrefix . ":" : "",
- $this->objectName,
- $this->objectName
- );
+ $this->signature = "{$command} {{$this->objectName}}";
$class = new $this->objectClass();
- try {
- foreach (Schema::getColumnListing($class->getTable()) as $column) {
- if ($column == "id") {
- continue;
+ // This constructor is called for every defined command, no matter which artisan
+ // command is being executed. We get the list of columns only when the cammand
+ // that requires it is being executed.
+ // This causes performance issue, but also for example use of `composer install`
+ // didn't work w/o a database connection.
+ // FIXME: $argv is different when invoking commands programmatically (e.g. in tests).
+ // Need to find a way to handle that in a better way. Maybe we "just" have to store
+ // list of available columns in the code.
+ if (strpos($argv[0] ?? '', 'artisan') === false || ($argv[1] ?? '') === $command) {
+ try {
+ foreach (Schema::getColumnListing($class->getTable()) as $column) {
+ if ($column == 'id') {
+ continue;
+ }
+
+ $this->signature .= " {--{$column}=}";
}
-
- $this->signature .= " {--{$column}=}";
+ } catch (\Exception $e) {
+ \Log::error("Could not extract options: {$e->getMessage()}");
}
- } catch (\Exception $e) {
- \Log::error("Could not extract options: {$e->getMessage()}");
}
$classes = class_uses_recursive($this->objectClass);
@@ -54,7 +63,7 @@
$this->properties = [];
foreach (Schema::getColumnListing($class->getTable()) as $column) {
- if ($column == "id") {
+ if ($column == 'id') {
continue;
}
@@ -90,8 +99,6 @@
$object->{$property} = $value;
}
- $object->timestamps = false;
-
if ($this->commandPrefix == 'scalpel') {
$object->saveQuietly();
} else {

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 8:43 PM (1 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18839471
Default Alt Text
D4388.1775508238.diff (8 KB)

Event Timeline