1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Services/Migration/CompanyService.php

63 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Services\Migration;
2020-11-10 16:20:02 +01:00
use App\Models\Account;
class CompanyService
{
protected $isSuccessful;
protected $companies = [];
public function start()
{
2020-11-10 16:20:02 +01:00
try {
if (session(SESSION_USER_ACCOUNTS)) {
foreach (session(SESSION_USER_ACCOUNTS) as $company) {
$account = Account::find($company->account_id);
if ($account) {
$this->companies[] = [
'id' => $account->id,
'name' => $account->present()->name(),
'company_key' => $account->account_key,
];
}
2020-11-10 16:20:02 +01:00
}
} else {
$this->companies[] = [
'id' => auth()->user()->account->id,
'name' => auth()->user()->account->present()->name(),
'company_key' => auth()->user()->account->account_key,
];
}
2020-11-10 16:20:02 +01:00
$this->isSuccessful = true;
} catch (\Exception $th) {
$this->isSuccessful = false;
2020-11-10 16:20:02 +01:00
$this->errors = [];
}
return $this;
}
public function isSuccessful()
{
return $this->isSuccessful;
}
public function getCompanies()
{
if ($this->isSuccessful) {
return $this->companies;
}
return [];
}
public function getErrors()
{
return $this->errors;
}
}