Page MenuHomePhorge

D1702.1775383559.diff
No OneTemporary

Authored By
Unknown
Size
121 KB
Referenced Files
None
Subscribers
None

D1702.1775383559.diff

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
@@ -27,10 +27,18 @@
*/
public function getObject($objectClass, $objectIdOrTitle, $objectTitle)
{
- $object = $objectClass::find($objectIdOrTitle);
+ if ($this->option('with-deleted')) {
+ $object = $objectClass::withTrashed()->find($objectIdOrTitle);
+ } else {
+ $object = $objectClass::find($objectIdOrTitle);
+ }
if (!$object && !empty($objectTitle)) {
- $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first();
+ if ($this->option('with-deleted')) {
+ $object = $objectClass::withTrashed()->where($objectTitle, $objectIdOrTitle)->first();
+ } else {
+ $object = $objectClass::where($objectTitle, $objectIdOrTitle)->first();
+ }
}
return $object;
diff --git a/src/app/Console/Commands/DBPing.php b/src/app/Console/Commands/DB/PingCommand.php
rename from src/app/Console/Commands/DBPing.php
rename to src/app/Console/Commands/DB/PingCommand.php
--- a/src/app/Console/Commands/DBPing.php
+++ b/src/app/Console/Commands/DB/PingCommand.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\DB;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\DB;
-class DBPing extends Command
+class PingCommand extends Command
{
/**
* The name and signature of the console command.
@@ -21,16 +21,6 @@
*/
protected $description = 'Ping the database [and wait for it to respond]';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/src/app/Console/Commands/Data/Export/BalanceCommand.php b/src/app/Console/Commands/Data/Export/BalanceCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Data/Export/BalanceCommand.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Console\Commands\Data\Export;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class VATCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'data:export:balance';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Export balance data';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $transactions = DB::select("
+ SELECT
+ YEAR(t.created_at) AS year,
+ MONTH(t.created_at) AS month,
+ SUM(t.amount) AS amount
+ FROM transactions t
+ INNER JOIN wallets w ON t.object_id = w.id
+ INNER JOIN user_settings u ON w.user_id = u.user_id
+ WHERE t.object_type = 'App\Wallet'
+ AND t.type = 'credit'
+ GROUP BY YEAR(t.created_at), MONTH(t.created_at)
+ ");
+
+ foreach ($transactions as $transaction) {
+ $this->info(
+ sprintf(
+ "%s %02d %d %d",
+ $transaction->{'year'},
+ $transaction->{'month'},
+ $transaction->{'amount'}
+ )
+ );
+ }
+ }
+}
diff --git a/src/app/Console/Commands/Data/Export/VATCommand.php b/src/app/Console/Commands/Data/Export/VATCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Data/Export/VATCommand.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Console\Commands\Data\Export;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class VATCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'data:export:vat';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Export VAT data';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $transactions = DB::select("
+ SELECT
+ YEAR(t.created_at) AS year,
+ MONTH(t.created_at) AS month,
+ SUM(t.amount) AS amount,
+ (0.077 * SUM(t.amount)) AS vat
+ FROM transactions t
+ INNER JOIN wallets w ON t.object_id = w.id
+ INNER JOIN user_settings u ON w.user_id = u.user_id
+ WHERE u.`key` = 'country'
+ AND u.value in ('CH', 'LI')
+ AND t.object_type = 'App\Wallet'
+ AND t.type = 'credit'
+ GROUP BY YEAR(t.created_at), MONTH(t.created_at)
+ ");
+
+ foreach ($transactions as $transaction) {
+ $this->info(
+ sprintf(
+ "%s %02d %d %d",
+ $transaction->{'year'},
+ $transaction->{'month'},
+ $transaction->{'amount'},
+ $transaction->{'vat'}
+ )
+ );
+ }
+ }
+}
diff --git a/src/app/Console/Commands/Data/ImportCommand.php b/src/app/Console/Commands/Data/ExportCommand.php
copy from src/app/Console/Commands/Data/ImportCommand.php
copy to src/app/Console/Commands/Data/ExportCommand.php
--- a/src/app/Console/Commands/Data/ImportCommand.php
+++ b/src/app/Console/Commands/Data/ExportCommand.php
@@ -4,31 +4,21 @@
use Illuminate\Console\Command;
-class ImportCommand extends Command
+class ExportCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = 'data:import';
+ protected $signature = 'data:export';
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Command description';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
+ protected $description = 'Export data to external sources';
/**
* Execute the console command.
@@ -38,9 +28,8 @@
public function handle()
{
$commands = [
- Import\CountriesCommand::class,
- Import\IP4NetsCommand::class,
- Import\IP6NetsCommand::class
+ Export\BalanceCommand::class,
+ Export\VATCommand::class
];
foreach ($commands as $command) {
@@ -48,7 +37,5 @@
$execution->output = $this->output;
$execution->handle();
}
-
- return 0;
}
}
diff --git a/src/app/Console/Commands/Data/ImportCommand.php b/src/app/Console/Commands/Data/ImportCommand.php
--- a/src/app/Console/Commands/Data/ImportCommand.php
+++ b/src/app/Console/Commands/Data/ImportCommand.php
@@ -18,7 +18,7 @@
*
* @var string
*/
- protected $description = 'Command description';
+ protected $description = 'Import data from external sources';
/**
* Create a new command instance.
@@ -48,7 +48,5 @@
$execution->output = $this->output;
$execution->handle();
}
-
- return 0;
}
}
diff --git a/src/app/Console/Commands/DiscountList.php b/src/app/Console/Commands/DiscountList.php
deleted file mode 100644
--- a/src/app/Console/Commands/DiscountList.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Discount;
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-
-class DiscountList extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'discount:list';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'List available (active) discounts';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- Discount::where('active', true)->orderBy('discount')->get()->each(
- function ($discount) {
- $name = $discount->description;
-
- if ($discount->code) {
- $name .= " [{$discount->code}]";
- }
-
- $this->info(
- sprintf(
- "%s %3d%% %s",
- $discount->id,
- $discount->discount,
- $name
- )
- );
- }
- );
- }
-}
diff --git a/src/app/Console/Commands/DiscountsCommand.php b/src/app/Console/Commands/DiscountsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DiscountsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class DiscountsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/DomainAdd.php b/src/app/Console/Commands/Domain/Add.php
rename from src/app/Console/Commands/DomainAdd.php
rename to src/app/Console/Commands/Domain/Add.php
--- a/src/app/Console/Commands/DomainAdd.php
+++ b/src/app/Console/Commands/Domain/Add.php
@@ -1,13 +1,13 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
use App\Domain;
use App\Entitlement;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\Queue;
-class DomainAdd extends Command
+class Add extends Command
{
/**
* The name and signature of the console command.
diff --git a/src/app/Console/Commands/DomainDelete.php b/src/app/Console/Commands/Domain/Delete.php
rename from src/app/Console/Commands/DomainDelete.php
rename to src/app/Console/Commands/Domain/Delete.php
--- a/src/app/Console/Commands/DomainDelete.php
+++ b/src/app/Console/Commands/Domain/Delete.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class DomainDelete extends Command
+class Delete extends Command
{
/**
* The name and signature of the console 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,9 +27,10 @@
*/
public function handle()
{
- $domain = \App\Domain::where('id', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
+ $this->error("Domain not found.");
return 1;
}
diff --git a/src/app/Console/Commands/DomainList.php b/src/app/Console/Commands/Domain/ListDomains.php
rename from src/app/Console/Commands/DomainList.php
rename to src/app/Console/Commands/Domain/ListDomains.php
--- a/src/app/Console/Commands/DomainList.php
+++ b/src/app/Console/Commands/Domain/ListDomains.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
-class DomainList extends Command
+class ListDomains extends Command
{
/**
* The name and signature of the console 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.
*
diff --git a/src/app/Console/Commands/DomainSetStatus.php b/src/app/Console/Commands/Domain/SetStatus.php
rename from src/app/Console/Commands/DomainSetStatus.php
rename to src/app/Console/Commands/Domain/SetStatus.php
--- a/src/app/Console/Commands/DomainSetStatus.php
+++ b/src/app/Console/Commands/Domain/SetStatus.php
@@ -1,12 +1,12 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
use Illuminate\Support\Facades\Queue;
-class DomainSetStatus extends Command
+class SetStatus extends Command
{
/**
* The name and signature of the console command.
@@ -29,9 +29,10 @@
*/
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;
}
diff --git a/src/app/Console/Commands/DomainSetWallet.php b/src/app/Console/Commands/Domain/SetWallet.php
rename from src/app/Console/Commands/DomainSetWallet.php
rename to src/app/Console/Commands/Domain/SetWallet.php
--- a/src/app/Console/Commands/DomainSetWallet.php
+++ b/src/app/Console/Commands/Domain/SetWallet.php
@@ -1,15 +1,15 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+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
+class SetWallet extends Command
{
/**
* The name and signature of the console command.
@@ -32,7 +32,7 @@
*/
public function handle()
{
- $domain = Domain::where('namespace', $this->argument('domain'))->first();
+ $domain = $this->getDomain($this->argument('domain'));
if (!$domain) {
$this->error("Domain not found.");
diff --git a/src/app/Console/Commands/DomainStatus.php b/src/app/Console/Commands/Domain/Status.php
rename from src/app/Console/Commands/DomainStatus.php
rename to src/app/Console/Commands/Domain/Status.php
--- a/src/app/Console/Commands/DomainStatus.php
+++ b/src/app/Console/Commands/Domain/Status.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
-class DomainStatus extends Command
+class Status extends Command
{
/**
* The name and signature of the console 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,9 +28,10 @@
*/
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;
}
@@ -48,15 +39,15 @@
'active' => Domain::STATUS_ACTIVE,
'suspended' => Domain::STATUS_SUSPENDED,
'deleted' => Domain::STATUS_DELETED,
- 'ldapReady' => Domain::STATUS_LDAP_READY,
- 'verified' => Domain::STATUS_VERIFIED,
'confirmed' => Domain::STATUS_CONFIRMED,
+ 'verified' => Domain::STATUS_VERIFIED,
+ 'ldapReady' => Domain::STATUS_LDAP_READY,
];
foreach ($statuses as $text => $bit) {
$func = 'is' . \ucfirst($text);
- $this->info(sprintf("%d %s: %s", $bit, $text, $domain->$func()));
+ $this->info(sprintf("%d %s: %s", $bit, $text, $domain->$func() ? "yes" : "no"));
}
$this->info("In total: {$domain->status}");
diff --git a/src/app/Console/Commands/DomainSuspend.php b/src/app/Console/Commands/Domain/Suspend.php
rename from src/app/Console/Commands/DomainSuspend.php
rename to src/app/Console/Commands/Domain/Suspend.php
--- a/src/app/Console/Commands/DomainSuspend.php
+++ b/src/app/Console/Commands/Domain/Suspend.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
-class DomainSuspend extends Command
+class Suspend extends Command
{
/**
* The name and signature of the console 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,14 +28,13 @@
*/
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;
}
- $this->info("Found domain: {$domain->id}");
-
$domain->suspend();
}
}
diff --git a/src/app/Console/Commands/DomainUnsuspend.php b/src/app/Console/Commands/Domain/Unsuspend.php
rename from src/app/Console/Commands/DomainUnsuspend.php
rename to src/app/Console/Commands/Domain/Unsuspend.php
--- a/src/app/Console/Commands/DomainUnsuspend.php
+++ b/src/app/Console/Commands/Domain/Unsuspend.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Domain;
+use App\Console\Command;
use App\Domain;
-use Illuminate\Console\Command;
-class DomainUnsuspend extends Command
+class Unsuspend extends Command
{
/**
* The name and signature of the console 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,14 +28,13 @@
*/
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;
}
- $this->info("Found domain {$domain->id}");
-
$domain->unsuspend();
}
}
diff --git a/src/app/Console/Commands/Domain/UsersCommand.php b/src/app/Console/Commands/Domain/UsersCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Domain/UsersCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Domain;
+
+use App\Console\ObjectRelationListCommand;
+
+class UsersCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectRelation = 'users';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/DomainListUsers.php b/src/app/Console/Commands/DomainListUsers.php
deleted file mode 100644
--- a/src/app/Console/Commands/DomainListUsers.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-
-class DomainListUsers extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'domain:list-users {domain}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'List the user accounts of a domain';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $domain = \App\Domain::where('namespace', $this->argument('domain'))->first();
-
- if (!$domain) {
- return 1;
- }
-
- if ($domain->isPublic()) {
- $this->error("This domain is a public registration domain.");
- return 1;
- }
-
- // TODO: actually implement listing users
- $wallet = $domain->wallet();
-
- if (!$wallet) {
- $this->error("This domain isn't billed to a wallet.");
- return 1;
- }
-
- $mailboxSKU = \App\Sku::where('title', 'mailbox')->first();
-
- if (!$mailboxSKU) {
- $this->error("No mailbox SKU available.");
- }
-
- $entitlements = $wallet->entitlements()
- ->where('entitleable_type', \App\User::class)
- ->where('sku_id', $mailboxSKU->id)->get();
-
- $users = [];
-
- foreach ($entitlements as $entitlement) {
- $users[] = $entitlement->entitleable;
- }
-
- usort($users, function ($a, $b) {
- return $a->email > $b->email;
- });
-
- foreach ($users as $user) {
- $this->info($user->email);
- }
- }
-}
diff --git a/src/app/Console/Commands/DomainsCommand.php b/src/app/Console/Commands/DomainsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/DomainsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class DomainsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/EntitlementsCommand.php b/src/app/Console/Commands/EntitlementsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/EntitlementsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class EntitlementsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
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,7 @@
namespace App\Console\Commands\Job;
-use App\Domain;
-use Illuminate\Console\Command;
+use App\Console\Command;
class DomainCreate extends Command
{
@@ -28,9 +27,10 @@
*/
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;
}
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,7 @@
namespace App\Console\Commands\Job;
-use App\Domain;
-use Illuminate\Console\Command;
+use App\Console\Command;
class DomainUpdate extends Command
{
@@ -28,9 +27,10 @@
*/
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;
}
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,7 @@
namespace App\Console\Commands\Job;
-use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserCreate extends Command
{
@@ -28,9 +27,10 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found");
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,7 @@
namespace App\Console\Commands\Job;
-use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class UserUpdate extends Command
{
@@ -28,9 +27,10 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found");
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
{
@@ -31,6 +31,7 @@
$wallet = Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
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,7 @@
namespace App\Console\Commands;
-use App\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
class MollieInfo extends Command
{
@@ -29,14 +28,13 @@
public function handle()
{
if ($this->argument('user')) {
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("Wallet not found");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$wallet = $user->wallets->first();
$provider = new \App\Providers\Payment\Mollie();
diff --git a/src/app/Console/Commands/Package/SkusCommand.php b/src/app/Console/Commands/Package/SkusCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Package/SkusCommand.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace App\Console\Commands\Package;
+
+use App\Console\Command;
+use App\Package;
+
+class SkusCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'package:skus {--package=}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "List SKUs for package(s).";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ if ($this->option('package')) {
+ $packages = Package::where('title', $this->option('package'))->get();
+ } else {
+ $packages = Package::all();
+ }
+
+ foreach ($packages as $package) {
+ $this->info("{$package->title}");
+
+ foreach ($package->skus as $sku) {
+ $this->info(sprintf(" %s (%d)", $sku->title, $sku->pivot->qty));
+ }
+ }
+ }
+}
diff --git a/src/app/Console/Commands/PackageSkus.php b/src/app/Console/Commands/PackageSkus.php
deleted file mode 100644
--- a/src/app/Console/Commands/PackageSkus.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Package;
-use Illuminate\Console\Command;
-
-class PackageSkus extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'package:skus';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = "List SKUs for packages.";
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $packages = Package::all();
-
- foreach ($packages as $package) {
- $this->info(sprintf("Package: %s", $package->title));
-
- foreach ($package->skus as $sku) {
- $this->info(sprintf(" SKU: %s (%d)", $sku->title, $sku->pivot->qty));
- }
- }
- }
-}
diff --git a/src/app/Console/Commands/PackagesCommand.php b/src/app/Console/Commands/PackagesCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PackagesCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class PackagesCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Package::class;
+ protected $objectName = 'package';
+ protected $objectTitle = '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
@@ -2,8 +2,8 @@
namespace App\Console\Commands;
+use App\Console\Command;
use App\Plan;
-use Illuminate\Console\Command;
class PlanPackages extends Command
{
@@ -21,16 +21,6 @@
*/
protected $description = "List packages for plans.";
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/src/app/Console/Commands/PlansCommand.php b/src/app/Console/Commands/PlansCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/PlansCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class PlansCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Plan::class;
+ protected $objectName = 'plan';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php b/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Discount/CreateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Discount;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php b/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Discount/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Discount;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Discount::class;
+ protected $objectName = 'discount';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php b/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/CreateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php b/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php b/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Domain/UpdateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Domain;
+
+use App\Console\ObjectUpdateCommand;
+
+class UpdateCommand extends ObjectUpdateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Domain::class;
+ protected $objectName = 'domain';
+ protected $objectTitle = 'namespace';
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/CreateCommand.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+
+ public function handle()
+ {
+ $this->properties = $this->getProperties();
+
+ $entitleable = call_user_func_array(
+ [$this->properties['entitleable_type'], 'find'],
+ [$this->properties['entitleable_id']]
+ );
+
+ if (!$entitleable) {
+ $this->error("No such {$this->properties['entitleable_type']}");
+ return 1;
+ }
+
+ if (!array_key_exists('entitleable_id', $this->properties)) {
+ $this->error("Specify --entitleable_id");
+ }
+
+ if (array_key_exists('sku_id', $this->properties)) {
+ $sku = \App\Sku::find($this->properties['sku_id']);
+
+ if (!$sku) {
+ $this->error("No such SKU {$this->properties['sku_id']}");
+ return 1;
+ }
+
+ if ($this->properties['cost'] == null) {
+ $this->properties['cost'] = $sku->cost;
+ }
+ }
+
+ if (array_key_exists('wallet_id', $this->properties)) {
+ $wallet = \App\Wallet::find($this->properties['wallet_id']);
+
+ if (!$wallet) {
+ $this->error("No such wallet {$this->properties['wallet_id']}");
+ return 1;
+ }
+ }
+
+ parent::handle();
+ }
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php b/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Entitlement/UpdateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Entitlement;
+
+use App\Console\ObjectUpdateCommand;
+
+class UpdateCommand extends ObjectUpdateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Entitlement::class;
+ protected $objectName = 'entitlement';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Package/ReadCommand.php b/src/app/Console/Commands/Scalpel/Package/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Package/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Package;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Package::class;
+ protected $objectName = 'package';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php b/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Plan/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Plan;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Plan::class;
+ protected $objectName = 'plan';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php b/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Sku/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Sku;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Sku::class;
+ protected $objectName = 'sku';
+ protected $objectTitle = 'title';
+}
diff --git a/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php b/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Transaction/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Transaction;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Transaction::class;
+ protected $objectName = 'transaction';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/User/CreateCommand.php b/src/app/Console/Commands/Scalpel/User/CreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/User/CreateCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\User;
+
+use App\Console\ObjectCreateCommand;
+
+class CreateCommand extends ObjectCreateCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/User/ReadCommand.php b/src/app/Console/Commands/Scalpel/User/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/User/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\User;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php b/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/UserSetting/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\UserSetting;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\UserSetting::class;
+ protected $objectName = 'user-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php b/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/Wallet/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\Wallet;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php b/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Scalpel/WalletSetting/ReadCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Scalpel\WalletSetting;
+
+use App\Console\ObjectReadCommand;
+
+class ReadCommand extends ObjectReadCommand
+{
+ protected $commandPrefix = 'scalpel';
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
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,14 +31,13 @@
public function handle()
{
if ($this->argument('user')) {
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$wallet = $user->wallets->first();
$provider = PaymentProvider::factory('stripe');
diff --git a/src/app/Console/Commands/TransactionsCommand.php b/src/app/Console/Commands/TransactionsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/TransactionsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class TransactionsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Transaction::class;
+ protected $objectName = 'transaction';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/UserAddAlias.php b/src/app/Console/Commands/User/AddAlias.php
rename from src/app/Console/Commands/UserAddAlias.php
rename to src/app/Console/Commands/User/AddAlias.php
--- a/src/app/Console/Commands/UserAddAlias.php
+++ b/src/app/Console/Commands/User/AddAlias.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
+use App\Console\Command;
use App\Http\Controllers\API\V4\UsersController;
-use Illuminate\Console\Command;
-class UserAddAlias extends Command
+class AddAlias extends Command
{
/**
* The name and signature of the console 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,9 +28,10 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
diff --git a/src/app/Console/Commands/User/AliasesCommand.php b/src/app/Console/Commands/User/AliasesCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/AliasesCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\ObjectRelationListCommand;
+
+class AliasesCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectRelation = 'aliases';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/UserDelete.php b/src/app/Console/Commands/User/Delete.php
rename from src/app/Console/Commands/UserDelete.php
rename to src/app/Console/Commands/User/Delete.php
--- a/src/app/Console/Commands/UserDelete.php
+++ b/src/app/Console/Commands/User/Delete.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class UserDelete extends Command
+class Delete extends Command
{
/**
* The name and signature of the console 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,9 +27,10 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
diff --git a/src/app/Console/Commands/UserDiscount.php b/src/app/Console/Commands/User/Discount.php
rename from src/app/Console/Commands/UserDiscount.php
rename to src/app/Console/Commands/User/Discount.php
--- a/src/app/Console/Commands/UserDiscount.php
+++ b/src/app/Console/Commands/User/Discount.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class UserDiscount extends Command
+class Discount extends Command
{
/**
* The name and signature of the console 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,20 +27,20 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user {$user->id}");
-
if ($this->argument('discount') === '0') {
$discount = null;
} else {
$discount = \App\Discount::find($this->argument('discount'));
if (!$discount) {
+ $this->error("Discount not found.");
return 1;
}
}
diff --git a/src/app/Console/Commands/User/DomainsCommand.php b/src/app/Console/Commands/User/DomainsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/DomainsCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\ObjectRelationListCommand;
+
+class DomainsCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectRelation = 'domains';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/User/EntitlementsCommand.php b/src/app/Console/Commands/User/EntitlementsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/EntitlementsCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\ObjectRelationListCommand;
+
+class EntitlementsCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectRelation = 'entitlements';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/UserForceDelete.php b/src/app/Console/Commands/User/ForceDelete.php
rename from src/app/Console/Commands/UserForceDelete.php
rename to src/app/Console/Commands/User/ForceDelete.php
--- a/src/app/Console/Commands/UserForceDelete.php
+++ b/src/app/Console/Commands/User/ForceDelete.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
use Illuminate\Support\Facades\DB;
-class UserForceDelete extends Command
+class ForceDelete extends Command
{
/**
* The name and signature of the console command.
@@ -28,14 +28,21 @@
*/
public function handle()
{
- $user = \App\User::withTrashed()->where('email', $this->argument('user'))->first();
+ $id = $this->argument('user');
+
+ if (is_numeric($id)) {
+ $user = \App\User::find($id);
+ } else {
+ $user = \App\User::withTrashed()->where('email', $id)->first();
+ }
if (!$user) {
+ $this->error("User not found.");
return 1;
}
if (!$user->trashed()) {
- $this->error('The user is not yet deleted');
+ $this->error("The user is not yet deleted");
return 1;
}
diff --git a/src/app/Console/Commands/UserStatus.php b/src/app/Console/Commands/User/Status.php
rename from src/app/Console/Commands/UserStatus.php
rename to src/app/Console/Commands/User/Status.php
--- a/src/app/Console/Commands/UserStatus.php
+++ b/src/app/Console/Commands/User/Status.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
-class UserStatus extends Command
+class Status extends Command
{
/**
* The name and signature of the console 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,9 +28,10 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
@@ -55,7 +46,7 @@
foreach ($statuses as $text => $bit) {
$func = 'is' . \ucfirst($text);
- $this->info(sprintf("%d %s: %s", $bit, $text, $user->$func()));
+ $this->info(sprintf("%d %s: %s", $bit, $text, $user->$func() ? "yes" : "no"));
}
$this->info("In total: {$user->status}");
diff --git a/src/app/Console/Commands/UserSuspend.php b/src/app/Console/Commands/User/Suspend.php
rename from src/app/Console/Commands/UserSuspend.php
rename to src/app/Console/Commands/User/Suspend.php
--- a/src/app/Console/Commands/UserSuspend.php
+++ b/src/app/Console/Commands/User/Suspend.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
-class UserSuspend extends Command
+class Suspend extends Command
{
/**
* The name and signature of the console 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,14 +28,13 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$user->suspend();
}
}
diff --git a/src/app/Console/Commands/UserUnsuspend.php b/src/app/Console/Commands/User/Unsuspend.php
rename from src/app/Console/Commands/UserUnsuspend.php
rename to src/app/Console/Commands/User/Unsuspend.php
--- a/src/app/Console/Commands/UserUnsuspend.php
+++ b/src/app/Console/Commands/User/Unsuspend.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
+use App\Console\Command;
use App\User;
-use Illuminate\Console\Command;
-class UserUnsuspend extends Command
+class Unsuspend extends Command
{
/**
* The name and signature of the console command.
@@ -21,16 +21,6 @@
*/
protected $description = 'Remove a user suspension';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
@@ -38,14 +28,13 @@
*/
public function handle()
{
- $user = User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user {$user->id}");
-
$user->unsuspend();
}
}
diff --git a/src/app/Console/Commands/UserVerify.php b/src/app/Console/Commands/User/Verify.php
rename from src/app/Console/Commands/UserVerify.php
rename to src/app/Console/Commands/User/Verify.php
--- a/src/app/Console/Commands/UserVerify.php
+++ b/src/app/Console/Commands/User/Verify.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class UserVerify extends Command
+class Verify extends Command
{
/**
* The name and signature of the console 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,14 +27,13 @@
*/
public function handle()
{
- $user = \App\User::where('email', $this->argument('user'))->first();
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$job = new \App\Jobs\User\VerifyJob($user->id);
$job->handle();
}
diff --git a/src/app/Console/Commands/User/WalletCommand.php b/src/app/Console/Commands/User/WalletCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/WalletCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\ObjectRelationListCommand;
+
+class WalletCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectRelation = 'wallet';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/User/WalletsCommand.php b/src/app/Console/Commands/User/WalletsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/WalletsCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\ObjectRelationListCommand;
+
+class WalletsCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectRelation = 'wallets';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/UserDomains.php b/src/app/Console/Commands/UserDomains.php
deleted file mode 100644
--- a/src/app/Console/Commands/UserDomains.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Domain;
-use App\User;
-use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
-
-class UserDomains extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:domains {userid}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = User::where('email', $this->argument('userid'))->first();
-
- if (!$user) {
- return 1;
- }
-
- foreach ($user->domains() as $domain) {
- $this->info("{$domain->namespace}");
- }
- }
-}
diff --git a/src/app/Console/Commands/UserEntitlements.php b/src/app/Console/Commands/UserEntitlements.php
deleted file mode 100644
--- a/src/app/Console/Commands/UserEntitlements.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Sku;
-use App\User;
-use Illuminate\Console\Command;
-
-class UserEntitlements extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:entitlements {userid}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = "List a user's entitlements.";
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = User::where('email', $this->argument('userid'))->first();
-
- if (!$user) {
- return 1;
- }
-
- $this->info("Found user: {$user->id}");
-
- $skus_counted = [];
-
- foreach ($user->entitlements as $entitlement) {
- if (!array_key_exists($entitlement->sku_id, $skus_counted)) {
- $skus_counted[$entitlement->sku_id] = 1;
- } else {
- $skus_counted[$entitlement->sku_id] += 1;
- }
- }
-
- foreach ($skus_counted as $id => $qty) {
- $sku = Sku::find($id);
- $this->info("SKU: {$sku->title} ({$qty})");
- }
- }
-}
diff --git a/src/app/Console/Commands/UserSettingsCommand.php b/src/app/Console/Commands/UserSettingsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UserSettingsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class UserSettingsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\UserSetting::class;
+ protected $objectName = 'user-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/UserWallets.php b/src/app/Console/Commands/UserWallets.php
deleted file mode 100644
--- a/src/app/Console/Commands/UserWallets.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-
-class UserWallets extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:wallets {user}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'List wallets for a user';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = \App\User::where('email', $this->argument('user'))->first();
-
- if (!$user) {
- return 1;
- }
-
- foreach ($user->wallets as $wallet) {
- $this->info("{$wallet->id} {$wallet->description}");
- }
- }
-}
diff --git a/src/app/Console/Commands/UsersCommand.php b/src/app/Console/Commands/UsersCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UsersCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class UsersCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\User::class;
+ protected $objectName = 'user';
+ protected $objectTitle = 'email';
+}
diff --git a/src/app/Console/Commands/WalletAddTransaction.php b/src/app/Console/Commands/Wallet/AddTransaction.php
rename from src/app/Console/Commands/WalletAddTransaction.php
rename to src/app/Console/Commands/Wallet/AddTransaction.php
--- a/src/app/Console/Commands/WalletAddTransaction.php
+++ b/src/app/Console/Commands/Wallet/AddTransaction.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletAddTransaction extends Command
+class AddTransaction extends Command
{
/**
* The name and signature of the console 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.
*
@@ -40,6 +30,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletBalances.php b/src/app/Console/Commands/Wallet/Balances.php
rename from src/app/Console/Commands/WalletBalances.php
rename to src/app/Console/Commands/Wallet/Balances.php
--- a/src/app/Console/Commands/WalletBalances.php
+++ b/src/app/Console/Commands/Wallet/Balances.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletBalances extends Command
+class Balances extends Command
{
/**
* The name and signature of the console command.
@@ -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.
*
diff --git a/src/app/Console/Commands/WalletCharge.php b/src/app/Console/Commands/Wallet/Charge.php
rename from src/app/Console/Commands/WalletCharge.php
rename to src/app/Console/Commands/Wallet/Charge.php
--- a/src/app/Console/Commands/WalletCharge.php
+++ b/src/app/Console/Commands/Wallet/Charge.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
+use App\Console\Command;
use App\Wallet;
-use Illuminate\Console\Command;
-class WalletCharge extends Command
+class Charge extends Command
{
/**
* The name and signature of the console 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.
*
@@ -43,6 +33,7 @@
$wallet = Wallet::find($wallet);
if (!$wallet || !$wallet->owner) {
+ $this->error("Wallet not found (or account deleted).");
return 1;
}
diff --git a/src/app/Console/Commands/Wallet/ControllersCommand.php b/src/app/Console/Commands/Wallet/ControllersCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Wallet/ControllersCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Wallet;
+
+use App\Console\ObjectRelationListCommand;
+
+class ControllersCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectRelation = 'controllers';
+ protected $objectTitle = null;
+}
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,13 @@
+<?php
+
+namespace App\Console\Commands\Wallet;
+
+use App\Console\ObjectRelationListCommand;
+
+class EntitlementsCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectRelation = 'entitlements';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/WalletExpected.php b/src/app/Console/Commands/Wallet/Expected.php
rename from src/app/Console/Commands/WalletExpected.php
rename to src/app/Console/Commands/Wallet/Expected.php
--- a/src/app/Console/Commands/WalletExpected.php
+++ b/src/app/Console/Commands/Wallet/Expected.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletExpected extends Command
+class Expected extends Command
{
/**
* The name and signature of the console 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,10 +28,10 @@
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) {
+ $this->error("User not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletGetBalance.php b/src/app/Console/Commands/Wallet/GetBalance.php
rename from src/app/Console/Commands/WalletGetBalance.php
rename to src/app/Console/Commands/Wallet/GetBalance.php
--- a/src/app/Console/Commands/WalletGetBalance.php
+++ b/src/app/Console/Commands/Wallet/GetBalance.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletGetBalance extends Command
+class GetBalance extends Command
{
/**
* The name and signature of the console 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.
*
@@ -40,6 +30,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletGetDiscount.php b/src/app/Console/Commands/Wallet/GetDiscount.php
rename from src/app/Console/Commands/WalletGetDiscount.php
rename to src/app/Console/Commands/Wallet/GetDiscount.php
--- a/src/app/Console/Commands/WalletGetDiscount.php
+++ b/src/app/Console/Commands/Wallet/GetDiscount.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletGetDiscount extends Command
+class GetDiscount extends Command
{
/**
* The name and signature of the console 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.
*
@@ -40,6 +30,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletMandate.php b/src/app/Console/Commands/Wallet/Mandate.php
rename from src/app/Console/Commands/WalletMandate.php
rename to src/app/Console/Commands/Wallet/Mandate.php
--- a/src/app/Console/Commands/WalletMandate.php
+++ b/src/app/Console/Commands/Wallet/Mandate.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
+use App\Console\Command;
use App\Http\Controllers\API\V4\PaymentsController;
-use Illuminate\Console\Command;
-class WalletMandate extends Command
+class Mandate extends Command
{
/**
* The name and signature of the console 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.
*
@@ -41,6 +31,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/Wallet/OwnerCommand.php b/src/app/Console/Commands/Wallet/OwnerCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Wallet/OwnerCommand.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Console\Commands\Wallet;
+
+use App\Console\ObjectRelationListCommand;
+
+class OwnerCommand extends ObjectRelationListCommand
+{
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectRelation = 'owner';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/WalletSetBalance.php b/src/app/Console/Commands/Wallet/SetBalance.php
rename from src/app/Console/Commands/WalletSetBalance.php
rename to src/app/Console/Commands/Wallet/SetBalance.php
--- a/src/app/Console/Commands/WalletSetBalance.php
+++ b/src/app/Console/Commands/Wallet/SetBalance.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletSetBalance extends Command
+class SetBalance extends Command
{
/**
* The name and signature of the console 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.
*
@@ -40,6 +30,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletSetDiscount.php b/src/app/Console/Commands/Wallet/SetDiscount.php
rename from src/app/Console/Commands/WalletSetDiscount.php
rename to src/app/Console/Commands/Wallet/SetDiscount.php
--- a/src/app/Console/Commands/WalletSetDiscount.php
+++ b/src/app/Console/Commands/Wallet/SetDiscount.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletSetDiscount extends Command
+class SetDiscount extends Command
{
/**
* The name and signature of the console 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,9 +27,10 @@
*/
public function handle()
{
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+ $wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
@@ -51,6 +42,7 @@
$discount = \App\Discount::find($this->argument('discount'));
if (!$discount) {
+ $this->error("Discount not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletTransactions.php b/src/app/Console/Commands/Wallet/Transactions.php
rename from src/app/Console/Commands/WalletTransactions.php
rename to src/app/Console/Commands/Wallet/Transactions.php
--- a/src/app/Console/Commands/WalletTransactions.php
+++ b/src/app/Console/Commands/Wallet/Transactions.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletTransactions extends Command
+class Transactions extends Command
{
/**
* The name and signature of the console 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,9 +27,10 @@
*/
public function handle()
{
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+ $wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletUntil.php b/src/app/Console/Commands/Wallet/Until.php
rename from src/app/Console/Commands/WalletUntil.php
rename to src/app/Console/Commands/Wallet/Until.php
--- a/src/app/Console/Commands/WalletUntil.php
+++ b/src/app/Console/Commands/Wallet/Until.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\Wallet;
-use Illuminate\Console\Command;
+use App\Console\Command;
-class WalletUntil extends Command
+class Until extends Command
{
/**
* The name and signature of the console 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.
*
@@ -40,6 +30,7 @@
$wallet = \App\Wallet::find($this->argument('wallet'));
if (!$wallet) {
+ $this->error("Wallet not found");
return 1;
}
diff --git a/src/app/Console/Commands/WalletDiscount.php b/src/app/Console/Commands/WalletDiscount.php
deleted file mode 100644
--- a/src/app/Console/Commands/WalletDiscount.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-
-class WalletDiscount extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'wallet:discount {wallet} {discount}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Apply a discount to a wallet';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
-
- if (!$wallet) {
- return 1;
- }
-
- // FIXME: Using '0' for delete might be not that obvious
-
- if ($this->argument('discount') === '0') {
- $wallet->discount()->dissociate();
- } else {
- $discount = \App\Discount::find($this->argument('discount'));
-
- if (!$discount) {
- return 1;
- }
-
- $wallet->discount()->associate($discount);
- }
-
- $wallet->save();
- }
-}
diff --git a/src/app/Console/Commands/WalletSettingsCommand.php b/src/app/Console/Commands/WalletSettingsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletSettingsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class WalletSettingsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\WalletSetting::class;
+ protected $objectName = 'wallet-setting';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Commands/WalletsCommand.php b/src/app/Console/Commands/WalletsCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletsCommand.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\ObjectListCommand;
+
+class WalletsCommand extends ObjectListCommand
+{
+ protected $objectClass = \App\Wallet::class;
+ protected $objectName = 'wallet';
+ protected $objectTitle = null;
+}
diff --git a/src/app/Console/Development/DomainStatus.php b/src/app/Console/Development/DomainStatus.php
deleted file mode 100644
--- a/src/app/Console/Development/DomainStatus.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-
-namespace App\Console\Development;
-
-use App\Domain;
-use Illuminate\Console\Command;
-
-class DomainStatus extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'domain:status {domain} {--add=} {--del=}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = "Set/get a domain's status.";
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $domain = Domain::where('namespace', $this->argument('domain'))->firstOrFail();
-
- $this->info("Found domain: {$domain->id}");
-
- $statuses = [
- 'active' => Domain::STATUS_ACTIVE,
- 'suspended' => Domain::STATUS_SUSPENDED,
- 'deleted' => Domain::STATUS_DELETED,
- 'ldapReady' => Domain::STATUS_LDAP_READY,
- 'verified' => Domain::STATUS_VERIFIED,
- 'confirmed' => Domain::STATUS_CONFIRMED,
- ];
-
- // I'd prefer "-state" and "+state" syntax, but it's not possible
- $delete = false;
- if ($update = $this->option('del')) {
- $delete = true;
- } elseif ($update = $this->option('add')) {
- // do nothing
- }
-
- if (!empty($update)) {
- $map = \array_change_key_case($statuses);
- $update = \strtolower($update);
-
- if (isset($map[$update])) {
- if ($delete && $domain->status & $map[$update]) {
- $domain->status ^= $map[$update];
- $domain->save();
- } elseif (!$delete && !($domain->status & $map[$update])) {
- $domain->status |= $map[$update];
- $domain->save();
- }
- }
- }
-
- $domain_state = [];
- foreach (\array_keys($statuses) as $state) {
- $func = 'is' . \ucfirst($state);
- if ($domain->$func()) {
- $domain_state[] = $state;
- }
- }
-
- $this->info("Status: " . \implode(',', $domain_state));
- }
-}
diff --git a/src/app/Console/Development/UserStatus.php b/src/app/Console/Development/UserStatus.php
deleted file mode 100644
--- a/src/app/Console/Development/UserStatus.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php
-
-namespace App\Console\Development;
-
-use App\User;
-use Illuminate\Console\Command;
-
-class UserStatus extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:status {userid} {--add=} {--del=}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = "Set/get a user's status.";
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = User::where('email', $this->argument('userid'))->firstOrFail();
-
- $this->info("Found user: {$user->id}");
-
- $statuses = [
- 'active' => User::STATUS_ACTIVE,
- 'suspended' => User::STATUS_SUSPENDED,
- 'deleted' => User::STATUS_DELETED,
- 'ldapReady' => User::STATUS_LDAP_READY,
- 'imapReady' => User::STATUS_IMAP_READY,
- ];
-
- // I'd prefer "-state" and "+state" syntax, but it's not possible
- $delete = false;
- if ($update = $this->option('del')) {
- $delete = true;
- } elseif ($update = $this->option('add')) {
- // do nothing
- }
-
- if (!empty($update)) {
- $map = \array_change_key_case($statuses);
- $update = \strtolower($update);
-
- if (isset($map[$update])) {
- if ($delete && $user->status & $map[$update]) {
- $user->status ^= $map[$update];
- $user->save();
- } elseif (!$delete && !($user->status & $map[$update])) {
- $user->status |= $map[$update];
- $user->save();
- }
- }
- }
-
- $user_state = [];
- foreach (\array_keys($statuses) as $state) {
- $func = 'is' . \ucfirst($state);
- if ($user->$func()) {
- $user_state[] = $state;
- }
- }
-
- $this->info("Status: " . \implode(',', $user_state));
- }
-}
diff --git a/src/app/Console/ObjectCreateCommand.php b/src/app/Console/ObjectCreateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectCreateCommand.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Console;
+
+abstract class ObjectCreateCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature;
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description;
+
+ protected $commandPrefix = null;
+ protected $objectClass;
+ protected $objectName;
+ protected $objectTitle;
+
+ protected $properties = [];
+
+ public function __construct()
+ {
+ $this->description = "Create a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:create",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName
+ );
+
+ $class = new $this->objectClass();
+
+ foreach ($class->getFillable() as $fillable) {
+ $this->signature .= " {--{$fillable}=}";
+ }
+
+ parent::__construct();
+ }
+
+ public function getProperties()
+ {
+ if (!empty($this->properties)) {
+ return $this->properties;
+ }
+
+ $class = new $this->objectClass();
+
+ $this->properties = [];
+
+ foreach ($class->getFillable() as $fillable) {
+ $this->properties[$fillable] = $this->option($fillable);
+ }
+
+ return $this->properties;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $class = new $this->objectClass();
+
+ $object = $this->objectClass::create($this->properties);
+
+ $objectKey = $object->{$class->getKeyName()};
+
+ $savedObject = $this->objectClass::find($objectKey);
+
+ if ($savedObject) {
+ $this->info($savedObject->{$class->getKeyName()});
+ } else {
+ $this->error("Object could not be created.");
+ }
+
+ return $savedObject;
+ }
+}
diff --git a/src/app/Console/ObjectListCommand.php b/src/app/Console/ObjectListCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectListCommand.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+abstract class ObjectListCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature;
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description;
+
+ protected $commandPrefix = null;
+ protected $objectClass;
+ protected $objectName;
+ protected $objectTitle;
+
+ public function __construct()
+ {
+ $this->description = "List {$this->objectName}s";
+
+ $classes = class_uses_recursive($this->objectClass);
+
+ if (in_array(SoftDeletes::class, $classes)) {
+ $this->signature = sprintf(
+ "%s%ss {--with-deleted : Include deleted %ss}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectName
+ );
+ } else {
+ $this->signature = "{$this->objectName}s";
+ }
+
+ $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $classes = class_uses_recursive($this->objectClass);
+
+ if (in_array(SoftDeletes::class, $classes) && $this->option('with-deleted')) {
+ $objects = $this->objectClass::withTrashed();
+ } else {
+ $objects = new $this->objectClass();
+ }
+
+ $objects->each(
+ function ($object) {
+ if ($object->deleted_at) {
+ $this->info("{$this->toString($object)} (deleted at {$object->deleted_at}");
+ } else {
+ $this->info("{$this->toString($object)}");
+ }
+ }
+ );
+ }
+}
diff --git a/src/app/Console/ObjectReadCommand.php b/src/app/Console/ObjectReadCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectReadCommand.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Console;
+
+abstract class ObjectReadCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature;
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description;
+
+ protected $commandPrefix = null;
+ protected $objectClass;
+ protected $objectName;
+ protected $objectTitle;
+
+ public function __construct()
+ {
+ $this->description = "Read a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:read {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectName
+ );
+
+ $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject($this->objectClass, $argument, $this->objectTitle);
+
+ if (!$object) {
+ return 1;
+ }
+
+ $this->info($this->toString($object));
+ }
+}
diff --git a/src/app/Console/ObjectRelationListCommand.php b/src/app/Console/ObjectRelationListCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectRelationListCommand.php
@@ -0,0 +1,125 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+abstract class ObjectRelationListCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature;
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description;
+
+ protected $commandPrefix = null;
+
+ /**
+ * The object class to use in querying the subject.
+ *
+ * @var string
+ */
+ protected $objectClass;
+
+ /**
+ * The machine name for the object, i.e. 'user', 'wallet', etc.
+ *
+ * @var string
+ */
+ protected $objectName;
+
+ /**
+ * The "relation" -- a method or property.
+ *
+ * @var string
+ */
+ protected $objectRelation;
+
+ /**
+ * The name of an alternative database field to look up objects with, such as the 'email' field
+ * for users, or the 'title' field for SKUs.
+ *
+ * @var string
+ */
+ protected $objectTitle;
+
+ /**
+ * Supplement the base command constructor with a derived or generated signature and
+ * description.
+ *
+ * @return mixed
+ */
+ public function __construct()
+ {
+ $this->description = "List {$this->objectRelation} for a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:%s {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectRelation,
+ $this->objectName
+ );
+
+ $this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject(
+ $this->objectClass,
+ $argument,
+ $this->objectTitle
+ );
+
+ if (!$object) {
+ $this->error("No such {$this->objectName} {$argument}");
+ return 1;
+ }
+
+ if (method_exists($object, $this->objectRelation)) {
+ $result = call_user_func([$object, $this->objectRelation]);
+ } elseif (property_exists($object, $this->objectRelation)) {
+ $result = $object->{"{$this->objectRelation}"};
+ } else {
+ $this->error("No such relation {$this->objectRelation}");
+ return 1;
+ }
+
+ if ($result instanceof \Illuminate\Database\Eloquent\Collection) {
+ $result->each(
+ function ($entry) {
+ $this->info($this->toString($entry));
+ }
+ );
+ } elseif ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) {
+ $result->each(
+ function ($entry) {
+ $this->info($this->toString($entry));
+ }
+ );
+ } elseif (is_array($result)) {
+ foreach ($result as $entry) {
+ $this->info($this->toString($entry));
+ }
+ } else {
+ $this->info($this->toString($result));
+ }
+ }
+}
diff --git a/src/app/Console/ObjectUpdateCommand.php b/src/app/Console/ObjectUpdateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/ObjectUpdateCommand.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Support\Facades\Schema;
+
+abstract class ObjectUpdateCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature;
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description;
+
+ protected $commandPrefix = null;
+ protected $objectClass;
+ protected $objectName;
+ protected $objectTitle;
+
+ protected $properties = [];
+
+ public function __construct()
+ {
+ $this->description = "Update a {$this->objectName}";
+ $this->signature = sprintf(
+ "%s%s:update {%s}",
+ $this->commandPrefix ? $this->commandPrefix . ":" : "",
+ $this->objectName,
+ $this->objectName
+ );
+
+ $class = new $this->objectClass();
+
+ foreach (Schema::getColumnListing($class->getTable()) as $column) {
+ if ($column == "id") {
+ continue;
+ }
+
+ $this->signature .= " {--{$column}=}";
+ }
+
+ $this->signature .= sprintf(
+ " {--with-deleted : Include deleted %ss}",
+ $this->objectName
+ );
+
+ parent::__construct();
+ }
+
+ public function getProperties()
+ {
+ if (!empty($this->properties)) {
+ return $this->properties;
+ }
+
+ $class = new $this->objectClass();
+
+ $this->properties = [];
+
+ foreach (Schema::getColumnListing($class->getTable()) as $column) {
+ if ($column == "id") {
+ continue;
+ }
+
+ if (($value = $this->option($column)) !== null) {
+ $this->properties[$column] = $value;
+ }
+ }
+
+ return $this->properties;
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $argument = $this->argument($this->objectName);
+
+ $object = $this->getObject($this->objectClass, $argument, $this->objectTitle);
+
+ if (!$object) {
+ return 1;
+ }
+
+ foreach ($this->getProperties() as $property => $value) {
+ if ($property == "deleted_at" && $value == "null") {
+ $value = null;
+ }
+
+ $object->{$property} = $value;
+ }
+
+ $object->save(['timestamps' => false]);
+ }
+}
diff --git a/src/app/Domain.php b/src/app/Domain.php
--- a/src/app/Domain.php
+++ b/src/app/Domain.php
@@ -96,8 +96,75 @@
return $this;
}
+ /**
+ * Ownership verification by checking for a TXT (or CNAME) record
+ * in the domain's DNS (that matches the verification hash).
+ *
+ * @return bool True if verification was successful, false otherwise
+ * @throws \Exception Throws exception on DNS or DB errors
+ */
+ public function confirm(): bool
+ {
+ if ($this->isConfirmed()) {
+ return true;
+ }
+
+ $hash = $this->hash(self::HASH_TEXT);
+ $confirmed = false;
+
+ // Get DNS records and find a matching TXT entry
+ $records = \dns_get_record($this->namespace, DNS_TXT);
+
+ if ($records === false) {
+ throw new \Exception("Failed to get DNS record for {$this->namespace}");
+ }
+
+ foreach ($records as $record) {
+ if ($record['txt'] === $hash) {
+ $confirmed = true;
+ break;
+ }
+ }
+
+ // Get DNS records and find a matching CNAME entry
+ // Note: some servers resolve every non-existing name
+ // so we need to define left and right side of the CNAME record
+ // i.e.: kolab-verify IN CNAME <hash>.domain.tld.
+ if (!$confirmed) {
+ $cname = $this->hash(self::HASH_CODE) . '.' . $this->namespace;
+ $records = \dns_get_record('kolab-verify.' . $this->namespace, DNS_CNAME);
+
+ if ($records === false) {
+ throw new \Exception("Failed to get DNS record for {$this->namespace}");
+ }
+
+ foreach ($records as $records) {
+ if ($records['target'] === $cname) {
+ $confirmed = true;
+ break;
+ }
+ }
+ }
+
+ if ($confirmed) {
+ $this->status |= Domain::STATUS_CONFIRMED;
+ $this->save();
+ }
+
+ return $confirmed;
+ }
+
+ /**
+ * Return the entitlement for this domain.
+ *
+ * @return \App\Entitlement|null
+ */
public function entitlement()
{
+ if ($this->isPublic()) {
+ return null;
+ }
+
return $this->morphOne('App\Entitlement', 'entitleable');
}
@@ -111,6 +178,26 @@
return self::whereRaw($where)->get(['namespace'])->pluck('namespace')->toArray();
}
+ /**
+ * Generate a verification hash for this domain
+ *
+ * @param int $mod One of: HASH_CNAME, HASH_CODE (Default), HASH_TEXT
+ *
+ * @return string Verification hash
+ */
+ public function hash($mod = null): string
+ {
+ $cname = 'kolab-verify';
+
+ if ($mod === self::HASH_CNAME) {
+ return $cname;
+ }
+
+ $hash = \md5('hkccp-verify-' . $this->namespace);
+
+ return $mod === self::HASH_TEXT ? "$cname=$hash" : $hash;
+ }
+
/**
* Returns whether this domain is active.
*
@@ -278,84 +365,6 @@
$this->attributes['status'] = $new_status;
}
- /**
- * Ownership verification by checking for a TXT (or CNAME) record
- * in the domain's DNS (that matches the verification hash).
- *
- * @return bool True if verification was successful, false otherwise
- * @throws \Exception Throws exception on DNS or DB errors
- */
- public function confirm(): bool
- {
- if ($this->isConfirmed()) {
- return true;
- }
-
- $hash = $this->hash(self::HASH_TEXT);
- $confirmed = false;
-
- // Get DNS records and find a matching TXT entry
- $records = \dns_get_record($this->namespace, DNS_TXT);
-
- if ($records === false) {
- throw new \Exception("Failed to get DNS record for {$this->namespace}");
- }
-
- foreach ($records as $record) {
- if ($record['txt'] === $hash) {
- $confirmed = true;
- break;
- }
- }
-
- // Get DNS records and find a matching CNAME entry
- // Note: some servers resolve every non-existing name
- // so we need to define left and right side of the CNAME record
- // i.e.: kolab-verify IN CNAME <hash>.domain.tld.
- if (!$confirmed) {
- $cname = $this->hash(self::HASH_CODE) . '.' . $this->namespace;
- $records = \dns_get_record('kolab-verify.' . $this->namespace, DNS_CNAME);
-
- if ($records === false) {
- throw new \Exception("Failed to get DNS record for {$this->namespace}");
- }
-
- foreach ($records as $records) {
- if ($records['target'] === $cname) {
- $confirmed = true;
- break;
- }
- }
- }
-
- if ($confirmed) {
- $this->status |= Domain::STATUS_CONFIRMED;
- $this->save();
- }
-
- return $confirmed;
- }
-
- /**
- * Generate a verification hash for this domain
- *
- * @param int $mod One of: HASH_CNAME, HASH_CODE (Default), HASH_TEXT
- *
- * @return string Verification hash
- */
- public function hash($mod = null): string
- {
- $cname = 'kolab-verify';
-
- if ($mod === self::HASH_CNAME) {
- return $cname;
- }
-
- $hash = \md5('hkccp-verify-' . $this->namespace);
-
- return $mod === self::HASH_TEXT ? "$cname=$hash" : $hash;
- }
-
/**
* Suspend this domain.
*
@@ -400,6 +409,49 @@
$this->save();
}
+ /**
+ * List user accounts for this domain.
+ *
+ * @return \App\User[] A list of users.
+ */
+ public function users()
+ {
+ if ($this->isPublic()) {
+ $this->error("This domain is a public registration domain.");
+ return 1;
+ }
+
+ // TODO: actually implement listing users
+ $wallet = $this->wallet();
+
+ if (!$wallet) {
+ $this->error("This domain isn't billed to a wallet.");
+ return 1;
+ }
+
+ $mailboxSKU = \App\Sku::where('title', 'mailbox')->first();
+
+ if (!$mailboxSKU) {
+ $this->error("No mailbox SKU available.");
+ }
+
+ $entitlements = $wallet->entitlements()
+ ->where('entitleable_type', \App\User::class)
+ ->where('sku_id', $mailboxSKU->id)->get();
+
+ $users = [];
+
+ foreach ($entitlements as $entitlement) {
+ $users[] = $entitlement->entitleable;
+ }
+
+ usort($users, function ($a, $b) {
+ return $a->email > $b->email;
+ });
+
+ return $users;
+ }
+
/**
* Verify if a domain exists in DNS
*
diff --git a/src/app/User.php b/src/app/User.php
--- a/src/app/User.php
+++ b/src/app/User.php
@@ -54,10 +54,8 @@
* @var array
*/
protected $fillable = [
- 'id',
'email',
'password',
- 'password_ldap',
'status'
];
diff --git a/src/database/seeds/local/UserSeeder.php b/src/database/seeds/local/UserSeeder.php
--- a/src/database/seeds/local/UserSeeder.php
+++ b/src/database/seeds/local/UserSeeder.php
@@ -108,7 +108,7 @@
$ned->assignSku(\App\Sku::where('title', 'activesync')->first(), 1);
- // Ned is a controller on Jack's wallet
+ // Ned is a controller on John's wallet
$john->wallets()->first()->addController($ned);
// Ned is also our 2FA test user
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/AddTest.php
rename from src/tests/Feature/Console/UserDiscountTest.php
rename to src/tests/Feature/Console/Domain/AddTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/AddTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class AddTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/DeleteTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/DeleteTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/DeleteTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class DeleteTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/Domain/ListDomainsTest.php b/src/tests/Feature/Console/Domain/ListDomainsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Domain/ListDomainsTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\Domain;
+
+use Tests\TestCase;
+
+class ListDomainsTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->artisan('domain:list')
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/ListUsersTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/ListUsersTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/ListUsersTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class ListUsersTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/SetStatusTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/SetStatusTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/SetStatusTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class SetStatusTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/SetWalletTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/SetWalletTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/SetWalletTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class SetWalletTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/Domain/StatusTest.php b/src/tests/Feature/Console/Domain/StatusTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Domain/StatusTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\Domain;
+
+use Tests\TestCase;
+
+class StatusTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->artisan('domain:status kolab.org')
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/SuspendTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/SuspendTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/SuspendTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class SuspendTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Domain/UnsuspendTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/Domain/UnsuspendTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Domain/UnsuspendTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Domain;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class UnsuspendTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/AddAliasTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/User/AddAliasTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/AddAliasTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class AddAliasTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/WalletDiscountTest.php b/src/tests/Feature/Console/User/DeleteTest.php
rename from src/tests/Feature/Console/WalletDiscountTest.php
rename to src/tests/Feature/Console/User/DeleteTest.php
--- a/src/tests/Feature/Console/WalletDiscountTest.php
+++ b/src/tests/Feature/Console/User/DeleteTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class WalletDiscountTest extends TestCase
+class DeleteTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/DiscountTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/User/DiscountTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/DiscountTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class DiscountTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDomainsTest.php b/src/tests/Feature/Console/User/DomainsTest.php
rename from src/tests/Feature/Console/UserDomainsTest.php
rename to src/tests/Feature/Console/User/DomainsTest.php
--- a/src/tests/Feature/Console/UserDomainsTest.php
+++ b/src/tests/Feature/Console/User/DomainsTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDomainsTest extends TestCase
+class DomainsTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->artisan('user:domains john@kolab.org')
diff --git a/src/tests/Feature/Console/UserEntitlementsTest.php b/src/tests/Feature/Console/User/EntitlementsTest.php
rename from src/tests/Feature/Console/UserEntitlementsTest.php
rename to src/tests/Feature/Console/User/EntitlementsTest.php
--- a/src/tests/Feature/Console/UserEntitlementsTest.php
+++ b/src/tests/Feature/Console/User/EntitlementsTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserEntitlementsTest extends TestCase
+class EntitlementsTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->artisan('user:entitlements john@kolab.org')
diff --git a/src/tests/Feature/Console/UserForceDeleteTest.php b/src/tests/Feature/Console/User/ForceDeleteTest.php
rename from src/tests/Feature/Console/UserForceDeleteTest.php
rename to src/tests/Feature/Console/User/ForceDeleteTest.php
--- a/src/tests/Feature/Console/UserForceDeleteTest.php
+++ b/src/tests/Feature/Console/User/ForceDeleteTest.php
@@ -1,11 +1,11 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class UserForceDeleteTest extends TestCase
+class ForceDeleteTest extends TestCase
{
/**
* {@inheritDoc}
diff --git a/src/tests/Feature/Console/User/StatusTest.php b/src/tests/Feature/Console/User/StatusTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/StatusTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class StatusTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->artisan('user:status john@kolab.org')
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/SuspendTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/User/SuspendTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/SuspendTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class SuspendTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/UnsuspendTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/User/UnsuspendTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/UnsuspendTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class UnsuspendTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/VerifyTest.php
copy from src/tests/Feature/Console/UserDiscountTest.php
copy to src/tests/Feature/Console/User/VerifyTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/VerifyTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class VerifyTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserWalletsTest.php b/src/tests/Feature/Console/User/WalletsTest.php
rename from src/tests/Feature/Console/UserWalletsTest.php
rename to src/tests/Feature/Console/User/WalletsTest.php
--- a/src/tests/Feature/Console/UserWalletsTest.php
+++ b/src/tests/Feature/Console/User/WalletsTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserWalletsTest extends TestCase
+class WalletsTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->artisan('user:wallets john@kolab.org')
diff --git a/src/tests/Feature/Console/Wallet/AddTransactionTest.php b/src/tests/Feature/Console/Wallet/AddTransactionTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/AddTransactionTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class AddTransactionTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/BalancesTest.php b/src/tests/Feature/Console/Wallet/BalancesTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/BalancesTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class BalancesTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->artisan('wallet:balances')
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/WalletChargeTest.php b/src/tests/Feature/Console/Wallet/ChargeTest.php
rename from src/tests/Feature/Console/WalletChargeTest.php
rename to src/tests/Feature/Console/Wallet/ChargeTest.php
--- a/src/tests/Feature/Console/WalletChargeTest.php
+++ b/src/tests/Feature/Console/Wallet/ChargeTest.php
@@ -1,11 +1,11 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Wallet;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class WalletChargeTest extends TestCase
+class ChargeTest extends TestCase
{
/**
* {@inheritDoc}
diff --git a/src/tests/Feature/Console/Wallet/ExpectedTest.php b/src/tests/Feature/Console/Wallet/ExpectedTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/ExpectedTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class ExpectedTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->artisan('wallet:expected')
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/GetBalanceTest.php b/src/tests/Feature/Console/Wallet/GetBalanceTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/GetBalanceTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class GetBalanceTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/GetDiscountTest.php b/src/tests/Feature/Console/Wallet/GetDiscountTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/GetDiscountTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class GetDiscountTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/Wallet/MandateTest.php
rename from src/tests/Feature/Console/UserDiscountTest.php
rename to src/tests/Feature/Console/Wallet/MandateTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/Wallet/MandateTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\Wallet;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class MandateTest extends TestCase
{
+ /**
+ * Test the command run
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/Wallet/SetBalanceTest.php b/src/tests/Feature/Console/Wallet/SetBalanceTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/SetBalanceTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class SetBalanceTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/SetDiscountTest.php b/src/tests/Feature/Console/Wallet/SetDiscountTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/SetDiscountTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class SetDiscountTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/TransactionsTest.php b/src/tests/Feature/Console/Wallet/TransactionsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/TransactionsTest.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class TransactionsTest extends TestCase
+{
+ /**
+ * Test the command run
+ */
+ public function testHandle(): void
+ {
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/Wallet/UntilTest.php b/src/tests/Feature/Console/Wallet/UntilTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Wallet/UntilTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Tests\Feature\Console\Wallet;
+
+use Tests\TestCase;
+
+class UntilTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('wallet-charge@kolabnow.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('wallet-charge@kolabnow.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test command run for a specified wallet
+ */
+ public function testHandleSingle(): void
+ {
+ $user = $this->getTestUser('wallet-charge@kolabnow.com');
+ $wallet = $user->wallets()->first();
+
+ // Non-existing wallet
+ $this->artisan('wallet:until unknown')
+ ->expectsOutput("Wallet not found")
+ ->assertExitCode(1);
+
+ // TODO
+ $this->artisan('wallet:until ' . $wallet->id)
+ ->assertExitCode(0);
+
+ $this->markTestIncomplete();
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 10:05 AM (14 h, 46 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18833144
Default Alt Text
D1702.1775383559.diff (121 KB)

Event Timeline