2019-03-26 05:46:08 +01: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
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. 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
|
|
|
*/
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
namespace App\Jobs\Company;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
2019-03-26 22:17:28 +01:00
|
|
|
use App\Models\CompanyToken;
|
2019-03-26 05:46:08 +01:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2019-09-26 15:00:51 +02:00
|
|
|
use Illuminate\Support\Str;
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
class CreateCompanyToken implements ShouldQueue
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
use Dispatchable;
|
|
|
|
use InteractsWithQueue;
|
|
|
|
use Queueable;
|
|
|
|
use SerializesModels;
|
2019-03-26 05:46:08 +01:00
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
|
|
|
protected $user;
|
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
protected $custom_token_name;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-03-26 05:46:08 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param Company $company
|
|
|
|
* @param User $user
|
|
|
|
* @param string $custom_token_name
|
2019-03-26 05:46:08 +01:00
|
|
|
*/
|
2019-11-26 09:14:01 +01:00
|
|
|
public function __construct(Company $company, User $user, string $custom_token_name)
|
2019-03-26 05:46:08 +01:00
|
|
|
{
|
|
|
|
$this->company = $company;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-03-26 05:46:08 +01:00
|
|
|
$this->user = $user;
|
2019-11-21 09:38:57 +01:00
|
|
|
|
2019-11-26 09:14:01 +01:00
|
|
|
$this->custom_token_name = $custom_token_name;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return CompanyToken|null
|
2019-03-26 05:46:08 +01:00
|
|
|
*/
|
2024-01-14 05:05:00 +01:00
|
|
|
public function handle(): ?CompanyToken
|
2019-03-26 05:46:08 +01:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->custom_token_name = $this->custom_token_name ?: $this->user->first_name.' '.$this->user->last_name;
|
2019-03-26 22:17:28 +01:00
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$company_token = new CompanyToken();
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->user_id = $this->user->id;
|
|
|
|
$company_token->company_id = $this->company->id;
|
|
|
|
$company_token->account_id = $this->user->account->id;
|
2020-09-06 11:38:10 +02:00
|
|
|
$company_token->name = $this->custom_token_name ?: $this->user->first_name.' '.$this->user->last_name;
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->token = Str::random(64);
|
2020-07-21 07:03:04 +02:00
|
|
|
$company_token->is_system = true;
|
|
|
|
|
2020-04-09 12:48:04 +02:00
|
|
|
$company_token->save();
|
|
|
|
|
|
|
|
return $company_token;
|
2019-03-26 05:46:08 +01:00
|
|
|
}
|
|
|
|
}
|