Adds a migration to create checkout acceptances

This creates the checkout acceptances for assets (basically what was previously shown in the „Unaccepted Assets“-report) when migrating the database
This commit is contained in:
Till Deeke 2018-09-10 17:37:24 +02:00
parent bbd1d6059a
commit e445e201f3

View file

@ -0,0 +1,43 @@
<?php
use App\Models\Actionlog;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class CreateCheckoutAcceptancesForUnacceptedAssets extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Get all assets not accepted
$assets = DB::table('assets')->where('assigned_type', 'App\Models\User')->where('accepted', 'pending')->get();
$acceptances = [];
foreach($assets as $asset) {
$acceptances[] = [
'checkoutable_type' => 'App\Models\Asset',
'checkoutable_id' => $asset->id,
'assigned_to_id' => $asset->assigned_to,
];
}
DB::table('checkout_acceptances')->insert($acceptances);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}