Skip to content

Commit

Permalink
company_id dropped on user invitations
Browse files Browse the repository at this point in the history
  • Loading branch information
sevannerse committed Jun 28, 2022
1 parent 90a2330 commit d7c101e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
69 changes: 69 additions & 0 deletions app/Listeners/Update/V30/Version304.php
@@ -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.');
}
}
2 changes: 1 addition & 1 deletion app/Models/Auth/UserInvitation.php
Expand Up @@ -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()
{
Expand Down
1 change: 1 addition & 0 deletions app/Providers/Event.php
Expand Up @@ -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',
Expand Down
18 changes: 6 additions & 12 deletions app/Traits/Users.php
Expand Up @@ -110,31 +110,25 @@ public function getLandingPageOfUser()
}

/**
* 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;
}
Expand Down
30 changes: 30 additions & 0 deletions database/migrations/2022_06_28_000000_core_v304.php
@@ -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()
{
//
}
};

0 comments on commit d7c101e

Please sign in to comment.