2018-10-24 14:50:15 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2022-04-27 13:20:41 +10:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 13:32:07 +10:00
|
|
|
*/
|
2018-10-24 14:50:15 +11:00
|
|
|
|
|
|
|
|
namespace App\Jobs\Company;
|
|
|
|
|
|
2021-09-30 08:14:48 +10:00
|
|
|
use App\DataMapper\ClientRegistrationFields;
|
2019-02-17 22:07:58 +11:00
|
|
|
use App\DataMapper\CompanySettings;
|
2021-05-24 19:39:21 +10:00
|
|
|
use App\Libraries\MultiDB;
|
2019-02-17 22:07:58 +11:00
|
|
|
use App\Models\Company;
|
2021-05-24 19:39:21 +10:00
|
|
|
use App\Utils\Ninja;
|
2018-10-26 15:53:29 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2018-10-24 14:50:15 +11:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class CreateCompany
|
|
|
|
|
{
|
2018-10-26 15:53:29 +11:00
|
|
|
use MakesHash;
|
2018-10-24 14:50:15 +11:00
|
|
|
use Dispatchable;
|
|
|
|
|
|
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
|
|
protected $account;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param array $request
|
|
|
|
|
* @param $account
|
2018-10-24 14:50:15 +11:00
|
|
|
*/
|
2019-06-17 09:58:33 +10:00
|
|
|
public function __construct(array $request, $account)
|
2018-10-24 14:50:15 +11:00
|
|
|
{
|
|
|
|
|
$this->request = $request;
|
2019-06-17 09:58:33 +10:00
|
|
|
|
2018-10-24 14:50:15 +11:00
|
|
|
$this->account = $account;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @return Company|null
|
2018-10-24 14:50:15 +11:00
|
|
|
*/
|
2018-11-27 18:24:26 +11:00
|
|
|
public function handle() : ?Company
|
2018-10-24 14:50:15 +11:00
|
|
|
{
|
2019-10-05 10:11:04 +10:00
|
|
|
$settings = CompanySettings::defaults();
|
2019-11-13 08:26:40 +11:00
|
|
|
|
2020-09-06 19:38:10 +10:00
|
|
|
$settings->name = isset($this->request['name']) ? $this->request['name'] : '';
|
2018-10-24 14:50:15 +11:00
|
|
|
|
|
|
|
|
$company = new Company();
|
|
|
|
|
$company->account_id = $this->account->id;
|
2018-10-26 15:53:29 +11:00
|
|
|
$company->company_key = $this->createHash();
|
2018-12-02 21:42:06 +11:00
|
|
|
$company->ip = request()->ip();
|
2019-10-05 10:11:04 +10:00
|
|
|
$company->settings = $settings;
|
2019-03-28 09:21:28 +11:00
|
|
|
$company->db = config('database.default');
|
2020-05-27 09:49:06 +10:00
|
|
|
$company->enabled_modules = config('ninja.enabled_modules');
|
2019-12-11 07:53:41 +11:00
|
|
|
$company->subdomain = isset($this->request['subdomain']) ? $this->request['subdomain'] : '';
|
2021-03-13 17:45:41 +11:00
|
|
|
$company->custom_fields = new \stdClass;
|
2021-03-22 21:55:09 +11:00
|
|
|
$company->default_password_timeout = 1800000;
|
2021-09-30 08:14:48 +10:00
|
|
|
$company->client_registration_fields = ClientRegistrationFields::generate();
|
2022-09-05 17:18:08 +10:00
|
|
|
$company->markdown_email_enabled = true;
|
|
|
|
|
$company->markdown_enabled = false;
|
2022-06-21 09:57:17 +00:00
|
|
|
|
|
|
|
|
if (Ninja::isHosted()) {
|
2021-05-24 19:39:21 +10:00
|
|
|
$company->subdomain = MultiDB::randomSubdomainGenerator();
|
2022-06-21 09:57:17 +00:00
|
|
|
} else {
|
2021-05-24 19:39:21 +10:00
|
|
|
$company->subdomain = '';
|
2022-06-21 09:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:50:15 +11:00
|
|
|
$company->save();
|
|
|
|
|
|
|
|
|
|
return $company;
|
|
|
|
|
}
|
|
|
|
|
}
|