1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 00:53:10 +01:00
invoiceninja/app/Jobs/Company/CreateCompanyToken.php

72 lines
1.9 KiB
PHP
Raw Normal View History

2019-03-26 05:46:08 +01: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
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
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
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $company;
protected $user;
protected $custom_token_name;
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
*/
public function __construct(Company $company, User $user, string $custom_token_name)
2019-03-26 05:46:08 +01:00
{
$this->company = $company;
2019-03-26 05:46:08 +01:00
$this->user = $user;
$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
*/
2019-03-26 22:17:28 +01:00
public function handle() : ?CompanyToken
2019-03-26 05:46:08 +01: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
$company_token = new CompanyToken;
$company_token->user_id = $this->user->id;
$company_token->company_id = $this->company->id;
$company_token->account_id = $this->user->account->id;
$company_token->name = $this->custom_token_name ?: $this->user->first_name.' '.$this->user->last_name;
$company_token->token = Str::random(64);
$company_token->is_system = true;
$company_token->save();
return $company_token;
2019-03-26 05:46:08 +01:00
}
}