diff --git a/app/Listeners/Update/V30/Version304.php b/app/Listeners/Update/V30/Version304.php new file mode 100644 index 000000000..fd836f850 --- /dev/null +++ b/app/Listeners/Update/V30/Version304.php @@ -0,0 +1,69 @@ +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.'); + } +} diff --git a/app/Models/Auth/UserInvitation.php b/app/Models/Auth/UserInvitation.php index 661088a5f..2b8a85b23 100644 --- a/app/Models/Auth/UserInvitation.php +++ b/app/Models/Auth/UserInvitation.php @@ -20,7 +20,7 @@ class UserInvitation extends Model * * @var string[] */ - protected $fillable = ['user_id', 'company_id', 'token']; + protected $fillable = ['user_id', 'token']; public function user() { diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 0e9351031..ae239981c 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -17,6 +17,7 @@ class Event extends Provider 'App\Listeners\Module\UpdateExtraModules', 'App\Listeners\Update\V30\Version300', 'App\Listeners\Update\V30\Version303', + 'App\Listeners\Update\V30\Version304', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/app/Traits/Users.php b/app/Traits/Users.php index 4ef8dc26e..c127d214b 100644 --- a/app/Traits/Users.php +++ b/app/Traits/Users.php @@ -110,31 +110,25 @@ trait Users } /** - * Checks if the given user has a pending invitation for the - * provided Company. + * Checks if the given user has a pending invitation. * * @return bool */ - public function hasPendingInvitation($company_id = null) + public function hasPendingInvitation() { - $company_id = $company_id ?: company_id(); - - $invitation = UserInvitation::where('user_id', $this->id)->where('company_id', $company_id)->first(); + $invitation = UserInvitation::where('user_id', $this->id)->first(); return $invitation ? true : false; } /** - * Returns if the given user has a pending invitation for the - * provided Company. + * Returns if the given user has a pending invitation. * * @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)->where('company_id', $company_id)->first(); + $invitation = UserInvitation::where('user_id', $this->id)->first(); return $invitation; } diff --git a/database/migrations/2022_06_28_000000_core_v304.php b/database/migrations/2022_06_28_000000_core_v304.php new file mode 100644 index 000000000..95dccd039 --- /dev/null +++ b/database/migrations/2022_06_28_000000_core_v304.php @@ -0,0 +1,30 @@ +dropColumn('company_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};