Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/DomainSetWallet.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use App\Console\Command; | |||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Sku; | use App\Sku; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Console\Command; | |||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
class DomainSetWallet extends Command | class DomainSetWallet extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
Show All 9 Lines | class DomainSetWallet extends Command | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$domain = Domain::where('namespace', $this->argument('domain'))->first(); | $domain = $this->getDomain($this->argument('domain')); | ||||
if (!$domain) { | if (!$domain) { | ||||
$this->error("Domain not found."); | $this->error("Domain not found."); | ||||
return 1; | return 1; | ||||
} | } | ||||
$wallet = Wallet::find($this->argument('wallet')); | $wallet = $this->getWallet($this->argument('wallet')); | ||||
if (!$wallet) { | if (!$wallet) { | ||||
$this->error("Wallet not found."); | $this->error("Wallet not found."); | ||||
return 1; | return 1; | ||||
} | } | ||||
if ($domain->entitlement) { | if ($domain->entitlement) { | ||||
$this->error("Domain already assigned to a wallet: {$domain->entitlement->wallet->id}."); | $this->error("Domain already assigned to a wallet: {$domain->entitlement->wallet->id}."); | ||||
return 1; | return 1; | ||||
} | } | ||||
$sku = Sku::where('title', 'domain-hosting')->first(); | $sku = Sku::where('title', 'domain-hosting')->first(); | ||||
Queue::fake(); // ignore LDAP for now (note: adding entitlements updates the domain) | Queue::fake(); // ignore LDAP for now (note: adding entitlements updates the domain) | ||||
Entitlement::create( | Entitlement::create( | ||||
[ | [ | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => 0, | 'cost' => 0, | ||||
'fee' => 0, | |||||
'entitleable_id' => $domain->id, | 'entitleable_id' => $domain->id, | ||||
'entitleable_type' => Domain::class, | 'entitleable_type' => Domain::class, | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
} | } |