Skip to content

A free open source IT asset/license management system

Adds a migration to create checkout acceptances

Till Deekee445e201f312
diff --git a/database/migrations/2018_09_10_082212_create_checkout_acceptances_for_unaccepted_assets.php b/database/migrations/2018_09_10_082212_create_checkout_acceptances_for_unaccepted_assets.php
new file mode 100644
index 0000000000..ddf6949b69
--- /dev/null
+++ b/database/migrations/2018_09_10_082212_create_checkout_acceptances_for_unaccepted_assets.php
@@ -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()
+ {
+ //
+ }
+}