Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117736777
D2086.1775151190.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D2086.1775151190.diff
View Options
diff --git a/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php b/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Wallet/SettingsCommand.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Wallet;
+
+use App\Console\ObjectRelationListCommand;
+
+class SettingsCommand extends ObjectRelationListCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectTitle = null;
+ protected $objectRelation = 'settings';
+}
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/CreateCommand.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\WalletSetting;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $cacheKeys = ['wallet_settings_%wallet_id%'];
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/UpdateCommand.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\WalletSetting;
+
+use App\Console\ObjectUpdateCommand;
+
+class UpdateCommand extends ObjectUpdateCommand
+{
+ protected $cacheKeys = ['wallet_settings_%wallet_id%'];
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/ObjectCommand.php b/src/app/Console/ObjectCommand.php
--- a/src/app/Console/ObjectCommand.php
+++ b/src/app/Console/ObjectCommand.php
@@ -2,6 +2,8 @@
namespace App\Console;
+use Illuminate\Support\Facades\Cache;
+
abstract class ObjectCommand extends Command
{
/**
@@ -43,4 +45,30 @@
* @var array
*/
protected $properties;
+
+
+ /**
+ * List of cache keys to refresh after updating/creating an object
+ *
+ * @var array
+ */
+ protected $cacheKeys = [];
+
+ /**
+ * Reset the cache for specified object using defined cacheKeys.
+ *
+ * @param object The object that was updated/created
+ */
+ protected function cacheRefresh($object): void
+ {
+ foreach ($this->cacheKeys as $cacheKey) {
+ foreach ($object->toArray() as $propKey => $propValue) {
+ if (!is_object($propValue)) {
+ $cacheKey = str_replace('%' . $propKey . '%', $propValue, $cacheKey);
+ }
+ }
+
+ Cache::forget($cacheKey);
+ }
+ }
}
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
@@ -56,6 +56,7 @@
$object = $this->objectClass::create($this->properties);
if ($object) {
+ $this->cacheRefresh($object);
$this->info($object->{$class->getKeyName()});
} else {
$this->error("Object could not be created.");
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
@@ -92,5 +92,7 @@
$object->timestamps = false;
$object->save(['timestamps' => false]);
+
+ $this->cacheRefresh($object);
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 2, 5:33 PM (3 h, 2 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18820028
Default Alt Text
D2086.1775151190.diff (3 KB)
Attached To
Mode
D2086: Add scalpel:wallet-setting:update, scalpel:wallet-setting:create, scalpel:wallet:settings
Attached
Detach File
Event Timeline