Browse Source

Init languages on migration

master
Egorka 6 years ago
parent
commit
c1c1d68f46
  1. 12
      common/modules/languages/migrations/m180827_210614_create_languages_table.php
  2. 33
      common/modules/languages/migrations/m180905_063026_init_first_languages.php

12
common/modules/languages/migrations/m180827_210614_create_languages_table.php

@ -12,14 +12,14 @@ class m180827_210614_create_languages_table extends Migration
*/
public function safeUp()
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
$this->createTable('{{%languages}}', [
'id' => $this->primaryKey(),
'name' => $this->string(2)->notNull(),
'title' => $this->string(64)->notNull(),
'status' => $this->integer(1)->defaultValue(1),
'default' => $this->integer(1)->defaultValue(0),
'id' => $this->primaryKey(),
'name' => $this->string(2)->notNull(),
'title' => $this->string(64)->notNull(),
'status' => $this->integer(1)->defaultValue(1),
'default' => $this->integer(1)->defaultValue(0),
], $tableOptions);
}

33
common/modules/languages/migrations/m180905_063026_init_first_languages.php

@ -0,0 +1,33 @@
<?php
use yii\db\Migration;
use common\modules\languages\entities\Language;
/**
* Class m180905_063026_init_first_languages
*/
class m180905_063026_init_first_languages extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$languages = Language::find()->all();
if (!$languages) {
$this->batchInsert('{{%languages}}', ['name', 'title', 'status', 'default'], [
['ru', 'Русский', Language::STATUS_ACTIVE, Language::DEFAULT_TRUE],
['en', 'English', Language::STATUS_ACTIVE, Language::DEFAULT_FALSE],
]);
}
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->delete('{{%languages}}', ['in', 'name', ['ru', 'en']]);
}
}
Loading…
Cancel
Save