2018-10-24 05:50:15 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-24 05:50:15 +02:00
|
|
|
|
|
|
|
namespace App\Jobs\Company;
|
|
|
|
|
2019-02-17 12:07:58 +01:00
|
|
|
use App\DataMapper\CompanySettings;
|
2018-10-24 05:50:15 +02:00
|
|
|
use App\Events\UserSignedUp;
|
2019-02-17 12:07:58 +01:00
|
|
|
use App\Models\Company;
|
2018-10-26 06:53:29 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-24 05:50:15 +02:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class CreateCompany
|
|
|
|
{
|
2018-10-26 06:53:29 +02:00
|
|
|
use MakesHash;
|
2018-10-24 05:50:15 +02:00
|
|
|
use Dispatchable;
|
|
|
|
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
protected $account;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-06-17 01:58:33 +02:00
|
|
|
public function __construct(array $request, $account)
|
2018-10-24 05:50:15 +02:00
|
|
|
{
|
|
|
|
$this->request = $request;
|
2019-06-17 01:58:33 +02:00
|
|
|
|
2018-10-24 05:50:15 +02:00
|
|
|
$this->account = $account;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-27 08:24:26 +01:00
|
|
|
public function handle() : ?Company
|
2018-10-24 05:50:15 +02:00
|
|
|
{
|
2019-10-05 02:11:04 +02:00
|
|
|
$settings = CompanySettings::defaults();
|
2019-11-12 22:26:40 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$settings->name = isset($this->request['name']) ? $this->request['name'] : '';
|
2018-10-24 05:50:15 +02:00
|
|
|
|
|
|
|
$company = new Company();
|
|
|
|
$company->account_id = $this->account->id;
|
2018-10-26 06:53:29 +02:00
|
|
|
$company->company_key = $this->createHash();
|
2018-12-02 11:42:06 +01:00
|
|
|
$company->ip = request()->ip();
|
2019-10-05 02:11:04 +02:00
|
|
|
$company->settings = $settings;
|
2019-03-27 23:21:28 +01:00
|
|
|
$company->db = config('database.default');
|
2020-05-27 01:49:06 +02:00
|
|
|
$company->enabled_modules = config('ninja.enabled_modules');
|
2019-12-10 21:53:41 +01:00
|
|
|
$company->subdomain = isset($this->request['subdomain']) ? $this->request['subdomain'] : '';
|
2018-10-24 05:50:15 +02:00
|
|
|
$company->save();
|
|
|
|
|
|
|
|
return $company;
|
|
|
|
}
|
|
|
|
}
|