1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Migrate company_user with users (#3598)

This commit is contained in:
Benjamin Beganović 2020-04-07 22:43:44 +02:00 committed by GitHub
parent 28cc7d5e52
commit 6a0ddd6c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -281,7 +281,7 @@ class Import implements ShouldQueue
$modified = $resource;
unset($modified['id']);
$user = $user_repository->save($modified, $this->fetchUser($resource['email']), true);
$user = $user_repository->save($modified, $this->fetchUser($resource['email']), true, false);
$user_agent = array_key_exists('token_name', $resource) ?: request()->server('HTTP_USER_AGENT');

View File

@ -45,12 +45,24 @@ class UserRepository extends BaseRepository
*
* @return user|\App\Models\user|null user Object
*/
public function save(array $data, User $user, $is_migrating = false)
public function save(array $data, User $user, $is_migrating = false, $unset_company_user = false)
{
$details = $data;
/**
* Getting: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'company_user'
* because of User::unguard().
* Solution. Unset company_user per request.
*/
if ($unset_company_user) {
unset($details['company_user']);
}
$company = auth()->user()->company();
$account_id = $company->account->id;
$user->fill($data);
$user->fill($details);
$user->account_id = $account_id;
$user->save();