Page MenuHomePhorge

D5526.1775277585.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D5526.1775277585.diff

diff --git a/src/app/Console/Commands/User/SetSettingCommand.php b/src/app/Console/Commands/User/SetSettingCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/SetSettingCommand.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\Command;
+use App\User;
+
+class SetSettingCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:set-setting {user} {key} {--delete} {value?}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Set a user setting";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = $this->getUser($this->argument('user'));
+
+ if (!$user) {
+ $this->error("User not found.");
+ return 1;
+ }
+
+ if ($this->option("delete")) {
+ $user->removeSetting($this->argument('key'));
+ } else {
+ $user->setSetting($this->argument('key'), $this->argument('value'));
+ }
+ }
+}
diff --git a/src/app/Console/Commands/User/SettingCommand.php b/src/app/Console/Commands/User/SettingCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/SettingCommand.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\Command;
+use App\User;
+
+class SettingCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:setting {user} {key?}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Set a user setting";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = $this->getUser($this->argument('user'));
+
+ if (!$user) {
+ $this->error("User not found.");
+ return 1;
+ }
+
+ if (empty($this->argument('key'))) {
+ $user->settings()->orderBy('key')->each(
+ function ($setting) {
+ if ($setting->value !== null) {
+ $this->info("{$setting->key}: " . \str_replace("\n", ' ', $setting->value));
+ }
+ }
+ );
+ } else {
+ $this->info($user->getSetting($this->argument('key')));
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 4, 4:39 AM (5 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18828133
Default Alt Text
D5526.1775277585.diff (2 KB)

Event Timeline