1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Jobs/Company/CreateCompany.php

82 lines
2.1 KiB
PHP
Raw Normal View History

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