FEATURE: add language to content pages

This commit is contained in:
Michal Kváček
2016-07-22 14:55:51 +02:00
parent 2189bbed5e
commit f90aee4108
7 changed files with 107 additions and 14 deletions
View File
@@ -0,0 +1,75 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AddLanguageToContentPages extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$platform = Schema::getConnection()
->getDoctrineSchemaManager()
->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
DB::raw('ALTER TABLE `languages`
CHANGE `code` `code` varchar(8) COLLATE \'utf8_general_ci\' NOT NULL FIRST,
CHANGE `name` `name` varchar(255) COLLATE \'utf8_general_ci\' NOT NULL COMMENT \'Translated name for given language\' AFTER `code`,
CHANGE `script` `script` varchar(16) COLLATE \'utf8_general_ci\' NOT NULL DEFAULT \'Latn\' COMMENT \'ISO code for locale script (Latn, Arab, ...)\' AFTER `name`,
CHANGE `native` `native` varchar(255) COLLATE \'utf8_general_ci\' NOT NULL COMMENT \'Native name for language\' AFTER `script`,
COLLATE \'utf8_general_ci\';');
Schema::table('contents', function (Blueprint $table) {
$table->string('language', 8)
->after('template')
->default(\App::getLocale());
});
Schema::table('contents', function (Blueprint $table) {
$table->index('language')
->change();
$table->unique(['language', 'url']);
$doctrine = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableDetails('contents');
// remove unique index from URL column
if ($doctrine->hasIndex('url_UNIQUE')) {
$table->dropUnique('url_UNIQUE');
} else {
$table->dropUnique('contents_url_unique');
}
$table->foreign('language')
->references('code')
->on('languages')
->onDelete('cascade')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contents', function (Blueprint $table) {
$table->dropForeign('contents_language_foreign');
$table->dropIndex('contents_language_index');
$table->dropUnique('contents_language_url_unique');
$table->dropColumn('language');
$table->unique('url');
});
}
}