Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117767643
D4540.1775234142.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D4540.1775234142.diff
View Options
diff --git a/src/app/Console/Commands/User/EntitlementsCommand.php b/src/app/Console/Commands/User/EntitlementsCommand.php
--- a/src/app/Console/Commands/User/EntitlementsCommand.php
+++ b/src/app/Console/Commands/User/EntitlementsCommand.php
@@ -11,7 +11,7 @@
*
* @var string
*/
- protected $signature = 'user:entitlements {userid}';
+ protected $signature = 'user:entitlements {user}';
/**
* The console command description.
@@ -27,7 +27,7 @@
*/
public function handle()
{
- $user = $this->getUser($this->argument('userid'));
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
$this->error("User not found.");
diff --git a/src/app/Console/Commands/Wallet/EntitlementsCommand.php b/src/app/Console/Commands/Wallet/EntitlementsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Wallet/EntitlementsCommand.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Console\Commands\Wallet;
+
+use App\Console\Command;
+
+class EntitlementsCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'wallet:entitlements {wallet} {--details}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "List a wallet's entitlements.";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $wallet = $this->getWallet($this->argument('wallet'));
+
+ if (!$wallet) {
+ $this->error("Wallet not found.");
+ return 1;
+ }
+
+ $details = $this->option('details');
+
+ $discount = $wallet->getDiscountRate();
+
+ $entitlements = $wallet->entitlements()
+ ->select('skus.title', 'entitlements.*')
+ ->join('skus', 'skus.id', '=', 'entitlements.sku_id')
+ ->orderBy('entitleable_type')
+ ->orderBy('entitleable_id')
+ ->orderBy('sku_id')
+ ->orderBy('created_at')
+ ->get();
+
+ foreach ($entitlements as $entitlement) {
+ // sanity check, deleted entitleable?
+ if (!$entitlement->entitleable) {
+ $this->info("{$entitlement->id}: DELETED {$entitlement->entitleable_type} {$entitlement->entitleable_id}");
+ continue;
+ }
+
+ $title = $entitlement->title; // @phpstan-ignore-line
+ $cost = $wallet->money((int) ($entitlement->cost * $discount));
+ $entitleableTitle = $entitlement->entitleable->toString();
+ $add = '';
+
+ if ($details) {
+ $add = sprintf(
+ "(created: %s, updated: %s",
+ $entitlement->created_at->toDateString(),
+ $entitlement->updated_at->toDateString()
+ );
+
+ if ($discount) {
+ $add .= sprintf(", cost: %s", $wallet->money($entitlement->cost));
+ }
+
+ $add .= ")";
+ }
+
+ $this->info("{$entitlement->id}: {$entitleableTitle} ({$title}) {$cost}{$add}");
+ }
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/EntitlementsTest.php b/src/tests/Feature/Console/Wallet/EntitlementsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/EntitlementsTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class EntitlementsTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("wallet:entitlements unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("Wallet not found.", $output);
+
+ $user = $this->getTestUser('john@kolab.org');
+ $wallet = $user->wallets()->first();
+
+ $code = \Artisan::call("wallet:entitlements {$wallet->id} --details");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertTrue(strpos($output, "john@kolab.org (mailbox) 5,00 CHF") !== false);
+ $this->assertTrue(strpos($output, "john@kolab.org (groupware) 4,90 CHF") !== false);
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 4:35 PM (1 h, 38 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18824812
Default Alt Text
D4540.1775234142.diff (4 KB)
Attached To
Mode
D4540: Add wallet:entitlements command
Attached
Detach File
Event Timeline