diff --git a/src/app/Console/Commands/Tenant/CreateCommand.php b/src/app/Console/Commands/Tenant/CreateCommand.php --- a/src/app/Console/Commands/Tenant/CreateCommand.php +++ b/src/app/Console/Commands/Tenant/CreateCommand.php @@ -13,14 +13,14 @@ * * @var string */ - protected $signature = 'tenant:create {user} {--title=}'; + protected $signature = 'tenant:create {user} {domain} {--title=} {--password=}'; /** * The console command description. * * @var string */ - protected $description = "Create a tenant (with a set of SKUs/plans/packages) and make the user a reseller."; + protected $description = "Create a tenant (with a set of SKUs/plans/packages), and a reseller user and domain for it."; /** * Execute the console command. @@ -29,11 +29,12 @@ */ public function handle() { - $user = $this->getUser($this->argument('user')); + $user = \App\User::where('email', $this->argument('user'))->first(); if (!$user) { - $this->error('User not found.'); - return 1; + $user = new \App\User(); + $user->email = $this->argument('user'); + $user->password = $this->option('password'); } DB::beginTransaction(); @@ -162,5 +163,36 @@ } $this->info("Created tenant {$tenant->id}."); + + // Set up the primary tenant domain + $domain = \App\Domain::where('namespace', $this->argument('domain'))->first(); + if (!$domain) { + // Set up the primary tenant domain + $domain = \App\Domain::create( + [ + 'namespace' => $this->argument('domain'), + 'type' => \App\Domain::TYPE_PUBLIC, + ] + ); + } + $domain->type = \App\Domain::TYPE_PUBLIC; + $domain->tenant_id = $tenant->id; + $domain->status = \App\Domain::STATUS_CONFIRMED | \App\Domain::STATUS_ACTIVE; + $domain->save(); + + $this->info("Created domain {$domain->id}."); + + $tenant->setSettings([ + "app.name" => $this->option("title"), + "app.url" => $this->argument("domain"), + "app.public_url" => $this->argument("domain"), + "app.support_url" => $this->argument("domain") . "/support", + "app.sender.address" => "noreply@kolabnowreseller.kolab.io", + "app.sender.name" => $this->option("title"), + "app.replyto.address" => "noreply@" . $this->argument("domain"), + "app.replyto.name" => $this->option("title"), + ]); + + $this->info("Applied default tenant settings."); } }