From a1b3d954c08770e2644bf6bb9b4c2e4417d33440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Thu, 20 May 2021 02:11:03 +0300 Subject: [PATCH] Fixed tests --- app/Listeners/Update/V21/Version2114.php | 13 ++++++++++++- .../migrations/2021_05_17_000000_core_v2114.php | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Listeners/Update/V21/Version2114.php b/app/Listeners/Update/V21/Version2114.php index 78af312f8..a409ba6cb 100644 --- a/app/Listeners/Update/V21/Version2114.php +++ b/app/Listeners/Update/V21/Version2114.php @@ -5,8 +5,11 @@ namespace App\Listeners\Update\V21; use App\Abstracts\Listeners\Update as Listener; use App\Events\Install\UpdateFinished as Event; use App\Models\Common\Media; +use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; +use App\Scopes\Company; +use Illuminate\Support\Facades\Schema; class Version2114 extends Listener { @@ -36,7 +39,7 @@ class Version2114 extends Listener { $company_ids = []; - foreach (Media::withTrashed()->cursor() as $media) { + foreach (Media::withTrashed()->withoutGlobalScope(Company::class)->cursor() as $media) { $company_id = null; if (preg_match('/\d{4}(\/\d{2}){2}\/(\d+)\//', $media->directory, $matches) && isset($matches[2])) { // 2021/04/09/34235/invoices @@ -56,5 +59,13 @@ class Version2114 extends Listener DB::table('media')->whereIn('id', $media_ids)->update(['company_id' => $company_id]); DB::table('mediables')->whereIn('media_id', $media_ids)->update(['company_id' => $company_id]); } + + Schema::table('media', function (Blueprint $table) { + $table->unsignedInteger('company_id')->default(null)->change(); + }); + + Schema::table('mediables', function (Blueprint $table) { + $table->unsignedInteger('company_id')->default(null)->change(); + }); } } diff --git a/database/migrations/2021_05_17_000000_core_v2114.php b/database/migrations/2021_05_17_000000_core_v2114.php index f10d7360c..90d5de76b 100644 --- a/database/migrations/2021_05_17_000000_core_v2114.php +++ b/database/migrations/2021_05_17_000000_core_v2114.php @@ -14,13 +14,13 @@ class CoreV2114 extends Migration public function up() { Schema::table('media', function (Blueprint $table) { - $table->unsignedInteger('company_id')->after('id'); + $table->unsignedInteger('company_id')->default(0)->after('id'); $table->index('company_id'); }); Schema::table('mediables', function (Blueprint $table) { - $table->unsignedInteger('company_id')->after('media_id'); + $table->unsignedInteger('company_id')->default(0)->after('media_id'); $table->index('company_id'); });