Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117907841
D4740.1775392472.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
D4740.1775392472.diff
View Options
diff --git a/src/app/Console/Commands/Domain/SetWalletCommand.php b/src/app/Console/Commands/Domain/SetWalletCommand.php
--- a/src/app/Console/Commands/Domain/SetWalletCommand.php
+++ b/src/app/Console/Commands/Domain/SetWalletCommand.php
@@ -3,9 +3,7 @@
namespace App\Console\Commands\Domain;
use App\Console\Command;
-use App\Entitlement;
-use App\Domain;
-use App\Sku;
+use App\Package;
use Illuminate\Support\Facades\Queue;
class SetWalletCommand extends Command
@@ -15,7 +13,7 @@
*
* @var string
*/
- protected $signature = 'domain:set-wallet {domain} {wallet}';
+ protected $signature = 'domain:set-wallet {domain} {wallet} {--package=}';
/**
* The console command description.
@@ -46,23 +44,28 @@
}
if ($entitlement = $domain->entitlements()->first()) {
- $this->error("Domain already assigned to a wallet: {$entitlement->wallet->id}.");
+ $this->error("Domain already assigned to a wallet: {$entitlement->wallet_id}.");
return 1;
}
- $sku = Sku::withObjectTenantContext($domain)->where('title', 'domain-hosting')->first();
+ if ($p = $this->option('package')) {
+ $package = Package::withObjectTenantContext($domain)->find($p);
+
+ if (!$package) {
+ $package = Package::withObjectTenantContext($domain)->where('title', $p)->first();
+ }
+ } else {
+ $package = Package::withObjectTenantContext($domain)->where('title', 'domain-hosting')->first();
+ }
+
+ if (!$package) {
+ $this->error("Package not found.");
+ return 1;
+ }
Queue::fake(); // ignore LDAP for now (note: adding entitlements updates the domain)
- Entitlement::create(
- [
- 'wallet_id' => $wallet->id,
- 'sku_id' => $sku->id,
- 'cost' => 0,
- 'fee' => 0,
- 'entitleable_id' => $domain->id,
- 'entitleable_type' => Domain::class,
- ]
- );
+ // Assign package the same as we do in DomainsController when a new domain is created
+ $domain->assignPackageAndWallet($package, $wallet);
}
}
diff --git a/src/tests/Feature/Console/Domain/SetWalletTest.php b/src/tests/Feature/Console/Domain/SetWalletTest.php
--- a/src/tests/Feature/Console/Domain/SetWalletTest.php
+++ b/src/tests/Feature/Console/Domain/SetWalletTest.php
@@ -54,7 +54,14 @@
$john = $this->getTestUser('john@kolab.org');
$wallet = $john->wallets->first();
- $code = \Artisan::call("domain:set-wallet domain-delete.com " . $wallet->id);
+ // Non-existing package
+ $code = \Artisan::call("domain:set-wallet domain-delete.com {$wallet->id} --package=123");
+ $output = trim(\Artisan::output());
+ $this->assertSame(1, $code);
+ $this->assertSame("Package not found.", $output);
+
+ // All good, expect success
+ $code = \Artisan::call("domain:set-wallet domain-delete.com {$wallet->id}");
$output = trim(\Artisan::output());
$this->assertSame(0, $code);
$this->assertSame('', $output);
@@ -67,7 +74,7 @@
$this->assertSame($wallet->id, $entitlement->wallet_id);
// Already assigned to a wallet
- $code = \Artisan::call("domain:set-wallet domain-delete.com " . $wallet->id);
+ $code = \Artisan::call("domain:set-wallet domain-delete.com {$wallet->id}");
$output = trim(\Artisan::output());
$this->assertSame(1, $code);
$this->assertSame("Domain already assigned to a wallet: {$wallet->id}.", $output);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 12:34 PM (8 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18826649
Default Alt Text
D4740.1775392472.diff (3 KB)
Attached To
Mode
D4740: Improve domain:set-wallet
Attached
Detach File
Event Timeline