company_id dropped on user invitations

This commit is contained in:
Sevan Nerse 2022-06-28 21:44:19 +03:00
parent 90a2330ae2
commit d7c101e025
5 changed files with 107 additions and 13 deletions

View File

@ -0,0 +1,69 @@
<?php
namespace App\Listeners\Update\V30;
use App\Abstracts\Listeners\Update as Listener;
use App\Events\Install\UpdateFinished as Event;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
class Version304 extends Listener
{
const ALIAS = 'core';
const VERSION = '3.0.4';
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
if ($this->skipThisUpdate($event)) {
return;
}
Log::channel('stderr')->info('Starting the Akaunting 3.0.4 update...');
$this->updateDatabase();
$this->deleteOldFiles();
Log::channel('stderr')->info('Akaunting 3.0.4 update finished.');
}
public function updateDatabase()
{
Log::channel('stderr')->info('Updating database...');
DB::table('migrations')->insert([
'id' => DB::table('migrations')->max('id') + 1,
'migration' => '2022_06_28_000000_core_v304',
'batch' => DB::table('migrations')->max('batch') + 1,
]);
Artisan::call('migrate', ['--force' => true]);
Log::channel('stderr')->info('Database updated.');
}
public function deleteOldFiles()
{
Log::channel('stderr')->info('Deleting old files...');
$files = [
'app/Events/Auth/InvitationCreated.php',
'app/Listeners/Auth/SendUserInvitation.php',
];
foreach ($files as $file) {
File::delete(base_path($file));
}
Log::channel('stderr')->info('Old files deleted.');
}
}

View File

@ -20,7 +20,7 @@ class UserInvitation extends Model
* *
* @var string[] * @var string[]
*/ */
protected $fillable = ['user_id', 'company_id', 'token']; protected $fillable = ['user_id', 'token'];
public function user() public function user()
{ {

View File

@ -17,6 +17,7 @@ class Event extends Provider
'App\Listeners\Module\UpdateExtraModules', 'App\Listeners\Module\UpdateExtraModules',
'App\Listeners\Update\V30\Version300', 'App\Listeners\Update\V30\Version300',
'App\Listeners\Update\V30\Version303', 'App\Listeners\Update\V30\Version303',
'App\Listeners\Update\V30\Version304',
], ],
'Illuminate\Auth\Events\Login' => [ 'Illuminate\Auth\Events\Login' => [
'App\Listeners\Auth\Login', 'App\Listeners\Auth\Login',

View File

@ -110,31 +110,25 @@ trait Users
} }
/** /**
* Checks if the given user has a pending invitation for the * Checks if the given user has a pending invitation.
* provided Company.
* *
* @return bool * @return bool
*/ */
public function hasPendingInvitation($company_id = null) public function hasPendingInvitation()
{ {
$company_id = $company_id ?: company_id(); $invitation = UserInvitation::where('user_id', $this->id)->first();
$invitation = UserInvitation::where('user_id', $this->id)->where('company_id', $company_id)->first();
return $invitation ? true : false; return $invitation ? true : false;
} }
/** /**
* Returns if the given user has a pending invitation for the * Returns if the given user has a pending invitation.
* provided Company.
* *
* @return null|UserInvitation * @return null|UserInvitation
*/ */
public function getPendingInvitation($company_id = null) public function getPendingInvitation()
{ {
$company_id = $company_id ?: company_id(); $invitation = UserInvitation::where('user_id', $this->id)->first();
$invitation = UserInvitation::where('user_id', $this->id)->where('company_id', $company_id)->first();
return $invitation; return $invitation;
} }

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('user_invitations', function (Blueprint $table) {
$table->dropColumn('company_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};