Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117815883
D2452.1775284857.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
46 KB
Referenced Files
None
Subscribers
None
D2452.1775284857.diff
View Options
diff --git a/src/app/Console/Command.php b/src/app/Console/Command.php
--- a/src/app/Console/Command.php
+++ b/src/app/Console/Command.php
@@ -2,6 +2,8 @@
namespace App\Console;
+use Illuminate\Support\Facades\DB;
+
abstract class Command extends \Illuminate\Console\Command
{
/**
@@ -23,13 +25,14 @@
/**
* Find the domain.
*
- * @param string $domain Domain ID or namespace
+ * @param string $domain Domain ID or namespace
+ * @param bool $withDeleted Include deleted
*
* @return \App\Domain|null
*/
- public function getDomain($domain)
+ public function getDomain($domain, $withDeleted = false)
{
- return $this->getObject(\App\Domain::class, $domain, 'namespace');
+ return $this->getObject(\App\Domain::class, $domain, 'namespace', $withDeleted);
}
/**
@@ -38,38 +41,86 @@
* @param string $objectClass The name of the class
* @param string $objectIdOrTitle The name of a database field to match.
* @param string|null $objectTitle An additional database field to match.
+ * @param bool $withDeleted Act as if --with-deleted was used
*
* @return mixed
*/
- public function getObject($objectClass, $objectIdOrTitle, $objectTitle = null)
+ public function getObject($objectClass, $objectIdOrTitle, $objectTitle = null, $withDeleted = false)
{
- if ($this->hasOption('with-deleted') && $this->option('with-deleted')) {
- $object = $objectClass::withTrashed()->find($objectIdOrTitle);
- } else {
- $object = $objectClass::find($objectIdOrTitle);
+ if (!$withDeleted) {
+ $withDeleted = $this->hasOption('with-deleted') && $this->option('with-deleted');
}
+ $object = $this->getObjectModel($objectClass, $withDeleted)->find($objectIdOrTitle);
+
if (!$object && !empty($objectTitle)) {
- if ($this->hasOption('with-deleted') && $this->option('with-deleted')) {
- $object = $objectClass::withTrashed()->where($objectTitle, $objectIdOrTitle)->first();
- } else {
- $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first();
- }
+ $object = $this->getObjectModel($objectClass, $withDeleted)
+ ->where($objectTitle, $objectIdOrTitle)->first();
}
return $object;
}
+ /**
+ * Returns a preconfigured Model object for a specified class.
+ *
+ * @param string $objectClass The name of the class
+ * @param bool $withDeleted Include withTrashed() query
+ *
+ * @return mixed
+ */
+ protected function getObjectModel($objectClass, $withDeleted = false)
+ {
+ if ($withDeleted) {
+ $model = $objectClass::withTrashed();
+ } else {
+ $model = new $objectClass();
+ }
+
+ $modelsWithTenant = [
+ \App\Discount::class,
+ \App\Domain::class,
+ \App\Group::class,
+ \App\Package::class,
+ \App\Plan::class,
+ \App\Sku::class,
+ \App\User::class,
+ ];
+
+ $modelsWithOwner = [
+ \App\Wallet::class,
+ ];
+
+ $tenant_id = \config('app.tenant_id');
+
+ // Add tenant filter
+ if (in_array($objectClass, $modelsWithTenant)) {
+ $model = $model->withEnvTenant();
+ } elseif (in_array($objectClass, $modelsWithOwner)) {
+ $model = $model->whereExists(function ($query) use ($tenant_id) {
+ $query->select(DB::raw(1))
+ ->from('users')
+ ->whereRaw('wallets.user_id = users.id')
+ ->whereRaw('users.tenant_id ' . ($tenant_id ? "= $tenant_id" : 'is null'));
+ });
+ }
+
+ // TODO: tenant check for Entitlement, Transaction, etc.
+
+ return $model;
+ }
+
/**
* Find the user.
*
- * @param string $user User ID or email
+ * @param string $user User ID or email
+ * @param bool $withDeleted Include deleted
*
* @return \App\User|null
*/
- public function getUser($user)
+ public function getUser($user, $withDeleted = false)
{
- return $this->getObject(\App\User::class, $user, 'email');
+ return $this->getObject(\App\User::class, $user, 'email', $withDeleted);
}
/**
diff --git a/src/app/Console/Commands/Discount/MergeCommand.php b/src/app/Console/Commands/Discount/MergeCommand.php
--- a/src/app/Console/Commands/Discount/MergeCommand.php
+++ b/src/app/Console/Commands/Discount/MergeCommand.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands\Discount;
-use Illuminate\Console\Command;
+use App\Console\Command;
/**
* Merge one discount (source) with another discount (target), and delete the source discount.
@@ -43,16 +43,6 @@
protected $description = 'Merge one discount in to another discount, ' .
'optionally set the description, and delete the source discount';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -60,14 +50,14 @@
*/
public function handle()
{
- $source = \App\Discount::find($this->argument('source'));
+ $source = $this->getObject(\App\Discount::class, $this->argument('source'));
if (!$source) {
$this->error("No such source discount: {$source}");
return 1;
}
- $target = \App\Discount::find($this->argument('target'));
+ $target = $this->getObject(\App\Discount::class, $this->argument('target'));
if (!$target) {
$this->error("No such target discount: {$target}");
diff --git a/src/app/Console/Commands/DomainDelete.php b/src/app/Console/Commands/DomainDelete.php
--- a/src/app/Console/Commands/DomainDelete.php
+++ b/src/app/Console/Commands/DomainDelete.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class DomainDelete extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Delete a domain';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $domain = \App\Domain::where('id', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/DomainList.php b/src/app/Console/Commands/DomainList.php
--- a/src/app/Console/Commands/DomainList.php
+++ b/src/app/Console/Commands/DomainList.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainList extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'List domains';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -44,7 +34,7 @@
$domains = Domain::orderBy('namespace');
}
- $domains->each(
+ $domains->withEnvTenant()->each(
function ($domain) {
$msg = $domain->namespace;
diff --git a/src/app/Console/Commands/DomainListUsers.php b/src/app/Console/Commands/DomainListUsers.php
--- a/src/app/Console/Commands/DomainListUsers.php
+++ b/src/app/Console/Commands/DomainListUsers.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class DomainListUsers extends Command
{
@@ -37,7 +37,7 @@
*/
public function handle()
{
- $domain = \App\Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/DomainRestore.php b/src/app/Console/Commands/DomainRestore.php
--- a/src/app/Console/Commands/DomainRestore.php
+++ b/src/app/Console/Commands/DomainRestore.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\DB;
class DomainRestore extends Command
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $domain = \App\Domain::withTrashed()->where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'), true);
if (!$domain) {
$this->error("Domain not found.");
diff --git a/src/app/Console/Commands/DomainSetStatus.php b/src/app/Console/Commands/DomainSetStatus.php
--- a/src/app/Console/Commands/DomainSetStatus.php
+++ b/src/app/Console/Commands/DomainSetStatus.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
use Illuminate\Support\Facades\Queue;
class DomainSetStatus extends Command
@@ -29,7 +29,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/DomainSetWallet.php b/src/app/Console/Commands/DomainSetWallet.php
--- a/src/app/Console/Commands/DomainSetWallet.php
+++ b/src/app/Console/Commands/DomainSetWallet.php
@@ -2,11 +2,11 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Entitlement;
use App\Domain;
use App\Sku;
use App\Wallet;
-use Illuminate\Console\Command;
use Illuminate\Support\Facades\Queue;
class DomainSetWallet extends Command
@@ -32,14 +32,14 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
$this->error("Domain not found.");
return 1;
}
- $wallet = Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
$this->error("Wallet not found.");
diff --git a/src/app/Console/Commands/DomainStatus.php b/src/app/Console/Commands/DomainStatus.php
--- a/src/app/Console/Commands/DomainStatus.php
+++ b/src/app/Console/Commands/DomainStatus.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainStatus extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Display the status of a domain';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/DomainSuspend.php b/src/app/Console/Commands/DomainSuspend.php
--- a/src/app/Console/Commands/DomainSuspend.php
+++ b/src/app/Console/Commands/DomainSuspend.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainSuspend extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Suspend a domain';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/DomainUnsuspend.php b/src/app/Console/Commands/DomainUnsuspend.php
--- a/src/app/Console/Commands/DomainUnsuspend.php
+++ b/src/app/Console/Commands/DomainUnsuspend.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainUnsuspend extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Remove a domain suspension';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/Job/DomainCreate.php b/src/app/Console/Commands/Job/DomainCreate.php
--- a/src/app/Console/Commands/Job/DomainCreate.php
+++ b/src/app/Console/Commands/Job/DomainCreate.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Job;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainCreate extends Command
{
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/Job/DomainUpdate.php b/src/app/Console/Commands/Job/DomainUpdate.php
--- a/src/app/Console/Commands/Job/DomainUpdate.php
+++ b/src/app/Console/Commands/Job/DomainUpdate.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Job;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
class DomainUpdate extends Command
{
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
return 1;
diff --git a/src/app/Console/Commands/Job/UserCreate.php b/src/app/Console/Commands/Job/UserCreate.php
--- a/src/app/Console/Commands/Job/UserCreate.php
+++ b/src/app/Console/Commands/Job/UserCreate.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Job;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
class UserCreate extends Command
{
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/Job/UserUpdate.php b/src/app/Console/Commands/Job/UserUpdate.php
--- a/src/app/Console/Commands/Job/UserUpdate.php
+++ b/src/app/Console/Commands/Job/UserUpdate.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Job;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
class UserUpdate extends Command
{
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/Job/WalletCheck.php b/src/app/Console/Commands/Job/WalletCheck.php
--- a/src/app/Console/Commands/Job/WalletCheck.php
+++ b/src/app/Console/Commands/Job/WalletCheck.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands\Job;
+use App\Console\Command;
use App\Wallet;
-use Illuminate\Console\Command;
class WalletCheck extends Command
{
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $wallet = Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/MollieInfo.php b/src/app/Console/Commands/MollieInfo.php
--- a/src/app/Console/Commands/MollieInfo.php
+++ b/src/app/Console/Commands/MollieInfo.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
class MollieInfo extends Command
{
@@ -29,7 +29,7 @@
public function handle()
{
if ($this->argument('user')) {
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/OpenVidu/RoomCreate.php b/src/app/Console/Commands/OpenVidu/RoomCreate.php
--- a/src/app/Console/Commands/OpenVidu/RoomCreate.php
+++ b/src/app/Console/Commands/OpenVidu/RoomCreate.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands\OpenVidu;
-use Illuminate\Console\Command;
+use App\Console\Command;
class RoomCreate extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Create a room for a user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/OpenVidu/Rooms.php b/src/app/Console/Commands/OpenVidu/Rooms.php
--- a/src/app/Console/Commands/OpenVidu/Rooms.php
+++ b/src/app/Console/Commands/OpenVidu/Rooms.php
@@ -20,16 +20,6 @@
*/
protected $description = 'List OpenVidu rooms';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/src/app/Console/Commands/OpenVidu/Sessions.php b/src/app/Console/Commands/OpenVidu/Sessions.php
--- a/src/app/Console/Commands/OpenVidu/Sessions.php
+++ b/src/app/Console/Commands/OpenVidu/Sessions.php
@@ -20,16 +20,6 @@
*/
protected $description = 'List OpenVidu sessions';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/src/app/Console/Commands/PackageSkus.php b/src/app/Console/Commands/PackageSkus.php
--- a/src/app/Console/Commands/PackageSkus.php
+++ b/src/app/Console/Commands/PackageSkus.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Package;
-use Illuminate\Console\Command;
class PackageSkus extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = "List SKUs for packages.";
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $packages = Package::all();
+ $packages = Package::withEnvTenant()->get();
foreach ($packages as $package) {
$this->info(sprintf("Package: %s", $package->title));
diff --git a/src/app/Console/Commands/PlanPackages.php b/src/app/Console/Commands/PlanPackages.php
--- a/src/app/Console/Commands/PlanPackages.php
+++ b/src/app/Console/Commands/PlanPackages.php
@@ -38,7 +38,7 @@
*/
public function handle()
{
- $plans = Plan::all();
+ $plans = Plan::withEnvTenant()->get();
foreach ($plans as $plan) {
$this->info(sprintf("Plan: %s", $plan->title));
diff --git a/src/app/Console/Commands/Sku/ListUsers.php b/src/app/Console/Commands/Sku/ListUsers.php
--- a/src/app/Console/Commands/Sku/ListUsers.php
+++ b/src/app/Console/Commands/Sku/ListUsers.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands\Sku;
-use Illuminate\Console\Command;
+use App\Console\Command;
class ListUsers extends Command
{
@@ -27,11 +27,7 @@
*/
public function handle()
{
- $sku = \App\Sku::find($this->argument('sku'));
-
- if (!$sku) {
- $sku = \App\Sku::where('title', $this->argument('sku'))->first();
- }
+ $sku = $this->getObject(\App\Sku::class, $this->argument('sku'), 'title');
if (!$sku) {
$this->error("Unable to find the SKU.");
diff --git a/src/app/Console/Commands/StripeInfo.php b/src/app/Console/Commands/StripeInfo.php
--- a/src/app/Console/Commands/StripeInfo.php
+++ b/src/app/Console/Commands/StripeInfo.php
@@ -2,9 +2,9 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Providers\PaymentProvider;
use App\User;
-use Illuminate\Console\Command;
use Stripe as StripeAPI;
class StripeInfo extends Command
@@ -31,7 +31,7 @@
public function handle()
{
if ($this->argument('user')) {
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserAddAlias.php b/src/app/Console/Commands/UserAddAlias.php
--- a/src/app/Console/Commands/UserAddAlias.php
+++ b/src/app/Console/Commands/UserAddAlias.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Http\Controllers\API\V4\UsersController;
-use Illuminate\Console\Command;
class UserAddAlias extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Add an email alias to a user (forcefully)';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserAssignSku.php b/src/app/Console/Commands/UserAssignSku.php
--- a/src/app/Console/Commands/UserAssignSku.php
+++ b/src/app/Console/Commands/UserAssignSku.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserAssignSku extends Command
{
@@ -27,18 +27,14 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
$this->error("Unable to find the user {$this->argument('user')}.");
return 1;
}
- $sku = \App\Sku::find($this->argument('sku'));
-
- if (!$sku) {
- $sku = \App\Sku::where('title', $this->argument('sku'))->first();
- }
+ $sku = $this->getObject(\App\Sku::class, $this->argument('sku'), 'title');
if (!$sku) {
$this->error("Unable to find the SKU {$this->argument('sku')}.");
diff --git a/src/app/Console/Commands/UserDelete.php b/src/app/Console/Commands/UserDelete.php
--- a/src/app/Console/Commands/UserDelete.php
+++ b/src/app/Console/Commands/UserDelete.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserDelete extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Delete a user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserDiscount.php b/src/app/Console/Commands/UserDiscount.php
--- a/src/app/Console/Commands/UserDiscount.php
+++ b/src/app/Console/Commands/UserDiscount.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserDiscount extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = "Apply a discount to all of the user's wallets";
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
@@ -48,7 +38,7 @@
if ($this->argument('discount') === '0') {
$discount = null;
} else {
- $discount = \App\Discount::find($this->argument('discount'));
+ $discount = $this->getObject(\App\Discount::class, $this->argument('discount'));
if (!$discount) {
return 1;
diff --git a/src/app/Console/Commands/UserDomains.php b/src/app/Console/Commands/UserDomains.php
--- a/src/app/Console/Commands/UserDomains.php
+++ b/src/app/Console/Commands/UserDomains.php
@@ -2,10 +2,7 @@
namespace App\Console\Commands;
-use App\Domain;
-use App\User;
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
+use App\Console\Command;
class UserDomains extends Command
{
@@ -23,16 +20,6 @@
*/
protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -40,7 +27,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('userid'))->first();
+ $user = $this->getUser($this->argument('userid'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserEntitlements.php b/src/app/Console/Commands/UserEntitlements.php
--- a/src/app/Console/Commands/UserEntitlements.php
+++ b/src/app/Console/Commands/UserEntitlements.php
@@ -2,9 +2,7 @@
namespace App\Console\Commands;
-use App\Sku;
-use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserEntitlements extends Command
{
@@ -22,16 +20,6 @@
*/
protected $description = "List a user's entitlements.";
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -39,7 +27,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('userid'))->first();
+ $user = $this->getUser($this->argument('userid'));
if (!$user) {
return 1;
@@ -58,7 +46,7 @@
}
foreach ($skus_counted as $id => $qty) {
- $sku = Sku::find($id);
+ $sku = \App\Sku::find($id);
$this->info("SKU: {$sku->title} ({$qty})");
}
}
diff --git a/src/app/Console/Commands/UserForceDelete.php b/src/app/Console/Commands/UserForceDelete.php
--- a/src/app/Console/Commands/UserForceDelete.php
+++ b/src/app/Console/Commands/UserForceDelete.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\DB;
class UserForceDelete extends Command
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $user = \App\User::withTrashed()->where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'), true);
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserRestore.php b/src/app/Console/Commands/UserRestore.php
--- a/src/app/Console/Commands/UserRestore.php
+++ b/src/app/Console/Commands/UserRestore.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\DB;
class UserRestore extends Command
@@ -28,7 +28,7 @@
*/
public function handle()
{
- $user = \App\User::withTrashed()->where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'), true);
if (!$user) {
$this->error('User not found.');
diff --git a/src/app/Console/Commands/UserStatus.php b/src/app/Console/Commands/UserStatus.php
--- a/src/app/Console/Commands/UserStatus.php
+++ b/src/app/Console/Commands/UserStatus.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
class UserStatus extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Display the status of a user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserSuspend.php b/src/app/Console/Commands/UserSuspend.php
--- a/src/app/Console/Commands/UserSuspend.php
+++ b/src/app/Console/Commands/UserSuspend.php
@@ -3,7 +3,7 @@
namespace App\Console\Commands;
use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserSuspend extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Suspend a user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserUnsuspend.php b/src/app/Console/Commands/UserUnsuspend.php
--- a/src/app/Console/Commands/UserUnsuspend.php
+++ b/src/app/Console/Commands/UserUnsuspend.php
@@ -2,8 +2,7 @@
namespace App\Console\Commands;
-use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserUnsuspend extends Command
{
@@ -21,16 +20,6 @@
*/
protected $description = 'Remove a user suspension';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +27,7 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserVerify.php b/src/app/Console/Commands/UserVerify.php
--- a/src/app/Console/Commands/UserVerify.php
+++ b/src/app/Console/Commands/UserVerify.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserVerify extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Verify the state of a user account';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/UserWallets.php b/src/app/Console/Commands/UserWallets.php
--- a/src/app/Console/Commands/UserWallets.php
+++ b/src/app/Console/Commands/UserWallets.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserWallets extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'List wallets for a user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
return 1;
diff --git a/src/app/Console/Commands/WalletAddTransaction.php b/src/app/Console/Commands/WalletAddTransaction.php
--- a/src/app/Console/Commands/WalletAddTransaction.php
+++ b/src/app/Console/Commands/WalletAddTransaction.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletAddTransaction extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Add a transaction to a wallet';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/WalletBalances.php b/src/app/Console/Commands/WalletBalances.php
--- a/src/app/Console/Commands/WalletBalances.php
+++ b/src/app/Console/Commands/WalletBalances.php
@@ -20,16 +20,6 @@
*/
protected $description = 'Show the balance on wallets';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,13 +27,18 @@
*/
public function handle()
{
- \App\Wallet::all()->each(
+ $wallets = \App\Wallet::select('wallets.*')
+ ->join('users', 'users.id', '=', 'wallets.user_id')
+ ->withEnvTenant('users')
+ ->all();
+
+ $wallets->each(
function ($wallet) {
if ($wallet->balance == 0) {
return;
}
- $user = \App\User::where('id', $wallet->user_id)->first();
+ $user = $wallet->owner;
if (!$user) {
return;
diff --git a/src/app/Console/Commands/WalletCharge.php b/src/app/Console/Commands/WalletCharge.php
--- a/src/app/Console/Commands/WalletCharge.php
+++ b/src/app/Console/Commands/WalletCharge.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Wallet;
-use Illuminate\Console\Command;
class WalletCharge extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Charge wallets';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -40,9 +30,9 @@
{
if ($wallet = $this->argument('wallet')) {
// Find specified wallet by ID
- $wallet = Wallet::find($wallet);
+ $wallet = $this->getWallet($wallet);
- if (!$wallet || !$wallet->owner || $wallet->owner->tenant_id != \config('app.tenant_id')) {
+ if (!$wallet || !$wallet->owner) {
return 1;
}
diff --git a/src/app/Console/Commands/WalletDiscount.php b/src/app/Console/Commands/WalletDiscount.php
--- a/src/app/Console/Commands/WalletDiscount.php
+++ b/src/app/Console/Commands/WalletDiscount.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletDiscount extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Apply a discount to a wallet';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
@@ -48,7 +38,7 @@
if ($this->argument('discount') === '0') {
$wallet->discount()->dissociate();
} else {
- $discount = \App\Discount::find($this->argument('discount'));
+ $discount = $this->getObject(\App\Discount::class, $this->argument('discount'));
if (!$discount) {
return 1;
diff --git a/src/app/Console/Commands/WalletExpected.php b/src/app/Console/Commands/WalletExpected.php
--- a/src/app/Console/Commands/WalletExpected.php
+++ b/src/app/Console/Commands/WalletExpected.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletExpected extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Show expected charges to wallets (for user)';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,8 +28,7 @@
public function handle()
{
if ($this->option('user')) {
- $user = \App\User::where('email', $this->option('user'))
- ->orWhere('id', $this->option('user'))->first();
+ $user = $this->getUser($this->option('user'));
if (!$user) {
return 1;
@@ -47,7 +36,10 @@
$wallets = $user->wallets;
} else {
- $wallets = \App\Wallet::all();
+ $wallets = \App\Wallet::select('wallets.*')
+ ->join('users', 'users.id', '=', 'wallets.user_id')
+ ->withEnvTenant('users')
+ ->all();
}
foreach ($wallets as $wallet) {
diff --git a/src/app/Console/Commands/WalletGetBalance.php b/src/app/Console/Commands/WalletGetBalance.php
--- a/src/app/Console/Commands/WalletGetBalance.php
+++ b/src/app/Console/Commands/WalletGetBalance.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletGetBalance extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Display the balance of a wallet';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/WalletGetDiscount.php b/src/app/Console/Commands/WalletGetDiscount.php
--- a/src/app/Console/Commands/WalletGetDiscount.php
+++ b/src/app/Console/Commands/WalletGetDiscount.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletGetDiscount extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Display the existing discount to a wallet, if any.';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/WalletMandate.php b/src/app/Console/Commands/WalletMandate.php
--- a/src/app/Console/Commands/WalletMandate.php
+++ b/src/app/Console/Commands/WalletMandate.php
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Http\Controllers\API\V4\PaymentsController;
-use Illuminate\Console\Command;
class WalletMandate extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = 'Show expected charges to wallets';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,7 +28,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/WalletSetBalance.php b/src/app/Console/Commands/WalletSetBalance.php
--- a/src/app/Console/Commands/WalletSetBalance.php
+++ b/src/app/Console/Commands/WalletSetBalance.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletSetBalance extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Set the balance of a wallet';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,13 +27,13 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
}
- $wallet->balance = (int)($this->argument('balance'));
+ $wallet->balance = (int) $this->argument('balance');
$wallet->save();
}
}
diff --git a/src/app/Console/Commands/WalletSetDiscount.php b/src/app/Console/Commands/WalletSetDiscount.php
--- a/src/app/Console/Commands/WalletSetDiscount.php
+++ b/src/app/Console/Commands/WalletSetDiscount.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletSetDiscount extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Apply a discount to a wallet';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
@@ -48,7 +38,7 @@
if ($this->argument('discount') === '0') {
$wallet->discount()->dissociate();
} else {
- $discount = \App\Discount::find($this->argument('discount'));
+ $discount = $this->getObject(\App\Discount::class, $this->argument('discount'));
if (!$discount) {
return 1;
diff --git a/src/app/Console/Commands/WalletTransactions.php b/src/app/Console/Commands/WalletTransactions.php
--- a/src/app/Console/Commands/WalletTransactions.php
+++ b/src/app/Console/Commands/WalletTransactions.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletTransactions extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'List the transactions against a wallet.';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
diff --git a/src/app/Console/Commands/WalletUntil.php b/src/app/Console/Commands/WalletUntil.php
--- a/src/app/Console/Commands/WalletUntil.php
+++ b/src/app/Console/Commands/WalletUntil.php
@@ -2,7 +2,7 @@
namespace App\Console\Commands;
-use Illuminate\Console\Command;
+use App\Console\Command;
class WalletUntil extends Command
{
@@ -20,16 +20,6 @@
*/
protected $description = 'Show until when the balance on a wallet lasts.';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -37,7 +27,7 @@
*/
public function handle()
{
- $wallet = \App\Wallet::find($this->argument('wallet'));
+ $wallet = $this->getWallet($this->argument('wallet'));
if (!$wallet) {
return 1;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 6:40 AM (7 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18800382
Default Alt Text
D2452.1775284857.diff (46 KB)
Attached To
Mode
D2452: Tenant scope for CLI commands
Attached
Detach File
Event Timeline