Fixed tests

This commit is contained in:
Burak Çakırel 2021-05-20 02:11:03 +03:00
parent 35effbafd2
commit a1b3d954c0
No known key found for this signature in database
GPG Key ID: 48FFBB7771B99C7C
2 changed files with 14 additions and 3 deletions

View File

@ -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();
});
}
}

View File

@ -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');
});