Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/UserEntitlementsCommand.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use App\Domain; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
class UserEntitlementsCommand extends Command | class UserEntitlementsCommand extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
Show All 25 Lines | class UserEntitlementsCommand extends Command | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = User::where('email', $this->argument('userid'))->first(); | $user = User::where('email', $this->argument('userid'))->first(); | ||||
$this->info("Found user: {$user->id}"); | $this->info("Found user: {$user->id}"); | ||||
$entitlements = $user->entitlements()->get(); | $skus_counted = []; | ||||
foreach ($entitlements as $entitlement) { | foreach ($user->entitlements as $entitlement) { | ||||
//yes: dd($entitlement); | if (!array_key_exists($entitlement->sku_id, $skus_counted)) { | ||||
$_entitleable = $entitlement->entitleable; | $skus_counted[$entitlement->sku_id] = 1; | ||||
} else { | |||||
if ($_entitleable instanceof Domain) { | $skus_counted[$entitlement->sku_id] += 1; | ||||
$this->info(sprintf("Domain: %s", $_entitleable->namespace)); | |||||
} | } | ||||
if ($_entitleable instanceof User) { | |||||
$this->info(sprintf("User: %s", $_entitleable->email)); | |||||
} | } | ||||
foreach ($skus_counted as $id => $qty) { | |||||
$sku = Sku::find($id); | |||||
$this->info("SKU: {$sku->title} ({$qty})"); | |||||
} | } | ||||
} | } | ||||
} | } |