Skip to content

Commit

Permalink
Merge pull request #107 from s-nakajima/master
Browse files Browse the repository at this point in the history
多言語対応
  • Loading branch information
s-nakajima committed Dec 23, 2016
2 parents af73714 + c2c579a commit c99d587
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 143 deletions.
74 changes: 74 additions & 0 deletions Config/Migration/1480996349_add_fields_for_m17n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* 多言語化対応
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsMigration', 'NetCommons.Config/Migration');

/**
* 多言語化対応
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Bbses\Config\Migration
*/
class AddFieldsForM17n extends NetCommonsMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'add_fields_for_m17n';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
'create_field' => array(
'bbs_articles' => array(
'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか', 'after' => 'is_latest'),
'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか', 'after' => 'is_origin'),
),
'bbses' => array(
'language_id' => array('type' => 'integer', 'null' => false, 'default' => '2', 'length' => 6, 'unsigned' => false, 'comment' => '言語ID', 'after' => 'block_id'),
'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか', 'after' => 'language_id'),
'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか', 'after' => 'is_origin'),
),
),
),
'down' => array(
'drop_field' => array(
'bbs_articles' => array('is_origin', 'is_translation'),
'bbses' => array('language_id', 'is_origin', 'is_translation'),
),
),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
return true;
}
}
67 changes: 67 additions & 0 deletions Config/Migration/1481005012_modified_from_bbs_id_to_bbs_key.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsMigration', 'NetCommons.Config/Migration');

/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Bbses\Config\Migration
*/
class ModifiedFromBbsIdToBbsKey extends CakeMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'modified_from_bbs_id_to_bbs_key';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
'create_field' => array(
'bbs_articles' => array(
'bbs_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '掲示板Key', 'charset' => 'utf8', 'after' => 'bbs_id'),
),
),
),
'down' => array(
'drop_field' => array(
'bbs_articles' => array('bbs_key'),
),
),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
return true;
}
}
77 changes: 77 additions & 0 deletions Config/Migration/1481005013_modified_from_bbs_id_to_bbs_key_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsMigration', 'NetCommons.Config/Migration');

/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Bbses\Config\Migration
*/
class ModifiedFromBbsIdToBbsKey1 extends CakeMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'modified_from_bbs_id_to_bbs_key_1';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
),
'down' => array(
),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
$BbsArticle = $this->generateModel('BbsArticle');

$bbsTable = $BbsArticle->tablePrefix . 'bbses Bbs';
$bbsArticleTable = $BbsArticle->tablePrefix . 'bbs_articles BbsArticle';

if ($direction === 'up') {
$sql = 'UPDATE ' . $bbsTable . ', ' . $bbsArticleTable .
' SET BbsArticle.bbs_key = Bbs.key' .
' WHERE BbsArticle.bbs_id' . ' = Bbs.id' .
'';
} else {
$sql = 'UPDATE ' . $bbsTable . ', ' . $bbsArticleTable .
' SET BbsArticle.bbs_id = Bbs.id' .
' WHERE BbsArticle.bbs_key' . ' = Bbs.key' .
' AND BbsArticle.language_id' . ' = Bbs.language_id' .
'';
}
$BbsArticle->query($sql);
return true;
}
}
90 changes: 90 additions & 0 deletions Config/Migration/1481006697_modified_from_bbs_id_to_bbs_key_2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('NetCommonsMigration', 'NetCommons.Config/Migration');

/**
* 多言語化対応のためbbs_keyに変更
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Bbses\Config\Migration
*/
class ModifiedFromBbsIdToBbsKey2 extends NetCommonsMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'modified_from_bbs_id_to_bbs_key_2';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
'drop_field' => array(
'bbs_articles' => array('bbs_id', 'indexes' => array('bbs_id')),
),
'alter_field' => array(
'bbs_articles' => array(
'bbs_key' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => '掲示板Key', 'charset' => 'utf8'),
),
),
'create_field' => array(
'bbs_articles' => array(
'indexes' => array(
'bbs_key' => array('column' => array('bbs_key', 'language_id'), 'unique' => 0),
),
),
),
),
'down' => array(
'create_field' => array(
'bbs_articles' => array(
'bbs_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => '記事のID'),
'indexes' => array(
'bbs_id' => array('column' => 'bbs_id', 'unique' => 0),
),
),
),
'alter_field' => array(
'bbs_articles' => array(
'bbs_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '掲示板Key', 'charset' => 'utf8'),
),
),
'drop_field' => array(
'bbs_articles' => array('indexes' => array('bbs_key')),
),
),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
return true;
}
}
11 changes: 8 additions & 3 deletions Config/Schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ public function after($event = array()) {
*/
public $bbs_articles = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'),
'bbs_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index', 'comment' => '記事のID'),
'bbs_key' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => '掲示板Key', 'charset' => 'utf8'),
'block_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
'language_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 6, 'unsigned' => false, 'comment' => '言語ID'),
'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4, 'unsigned' => false, 'comment' => '公開状況 1:公開中、2:公開申請中、3:下書き中、4:差し戻し'),
'is_active' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => 'アクティブなコンテンツかどうか 0:アクティブでない 1:アクティブ'),
'is_latest' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '最新コンテンツかどうか 0:最新でない 1:最新'),
'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか'),
'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか'),
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => 'キー', 'charset' => 'utf8'),
'title' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'タイトル', 'charset' => 'utf8'),
'title_icon' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
Expand All @@ -94,8 +96,8 @@ public function after($event = array()) {
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '更新日時'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'bbs_id' => array('column' => 'bbs_id', 'unique' => 0),
'key' => array('column' => 'key', 'unique' => 0)
'key' => array('column' => 'key', 'unique' => 0),
'bbs_key' => array('column' => array('bbs_key', 'language_id'), 'unique' => 0)
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB')
);
Expand Down Expand Up @@ -129,6 +131,9 @@ public function after($event = array()) {
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'comment' => 'ID'),
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'comment' => '掲示板キー', 'charset' => 'utf8'),
'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'),
'language_id' => array('type' => 'integer', 'null' => false, 'default' => '2', 'length' => 6, 'unsigned' => false, 'comment' => '言語ID'),
'is_origin' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'comment' => 'オリジナルかどうか'),
'is_translation' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'comment' => '翻訳したかどうか'),
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '掲示板名称', 'charset' => 'utf8'),
'bbs_article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => '記事の最終更新日時'),
'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => '作成者'),
Expand Down
Loading

0 comments on commit c99d587

Please sign in to comment.