Skip to content

Commit

Permalink
Fixed Updates 1.1.7 data update
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jan 8, 2018
1 parent f2c4dfd commit 5e4e27f
Showing 1 changed file with 11 additions and 37 deletions.
48 changes: 11 additions & 37 deletions app/Listeners/Updates/Version117.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
namespace App\Listeners\Updates;

use App\Events\UpdateFinished;
use App\Models\Setting\Currency;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use MediaUploader;
use Artisan;

class Version117 extends Listener
Expand All @@ -28,36 +25,7 @@ public function handle(UpdateFinished $event)
return;
}

Schema::create('media', function (Blueprint $table) {
$table->increments('id');
$table->string('disk', 32);
$table->string('directory');
$table->string('filename');
$table->string('extension', 32);
$table->string('mime_type', 128);
$table->string('aggregate_type', 32);
$table->integer('size')->unsigned();
$table->timestamps();
$table->softDeletes();

$table->index(['disk', 'directory']);
$table->unique(['disk', 'directory', 'filename', 'extension']);
$table->index('aggregate_type');
});

Schema::create('mediables', function (Blueprint $table) {
$table->integer('media_id')->unsigned();
$table->string('mediable_type');
$table->integer('mediable_id')->unsigned();
$table->string('tag');
$table->integer('order')->unsigned();

$table->primary(['media_id', 'mediable_type', 'mediable_id', 'tag']);
$table->index(['mediable_id', 'mediable_type']);
$table->index('tag');
$table->index('order');
$table->foreign('media_id')->references('id')->on('media')->onDelete('cascade');
});
$data = [];

$migrations = [
'\App\Models\Auth\User' => 'picture',
Expand All @@ -77,6 +45,15 @@ public function handle(UpdateFinished $event)
$items = $model::all();
}

$data[basename($model)] = $items;
}

// Update database
Artisan::call('migrate', ['--force' => true]);

foreach ($migrations as $model => $name) {
$items = $data[basename($model)];

foreach ($items as $item) {
if ($item->$name) {
$path = explode('uploads/', $item->$name);
Expand All @@ -87,8 +64,5 @@ public function handle(UpdateFinished $event)
}
}
}

// Update database
Artisan::call('migrate', ['--force' => true]);
}
}

0 comments on commit 5e4e27f

Please sign in to comment.