-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from s-nakajima/master
Fix schema file and migration file
- Loading branch information
Showing
5 changed files
with
272 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
/** | ||
* Init migration | ||
* | ||
* @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 | ||
*/ | ||
|
||
/** | ||
* Init migration | ||
* | ||
* @author Shohei Nakajima <nakajimashouhei@gmail.com> | ||
* @package NetCommons\Blocks\Config\Migration | ||
*/ | ||
class Init extends CakeMigration { | ||
|
||
/** | ||
* Migration description | ||
* | ||
* @var string | ||
*/ | ||
public $description = 'init'; | ||
|
||
/** | ||
* Actions to be performed | ||
* | ||
* @var array $migration | ||
*/ | ||
public $migration = array( | ||
'up' => array( | ||
'create_table' => array( | ||
'block_role_permissions' => array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), | ||
'roles_room_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), | ||
'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | ||
'permission' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Permission name | ||
e.g.) create_content, post_top_article', 'charset' => 'utf8'), | ||
'value' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1), | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | ||
), | ||
'blocks' => array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), | ||
'language_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 6, 'unsigned' => false), | ||
'room_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), | ||
'plugin_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'block key | プラグインKEY | plugins.key | ', 'charset' => 'utf8'), | ||
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Key of the block.', 'charset' => 'utf8'), | ||
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Name of the block.', 'charset' => 'utf8'), | ||
'public_type' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 4, 'unsigned' => false, 'comment' => '一般以下のパートが閲覧可能かどうか。 | ||
(0:非公開, 1:公開, 2:期間限定公開) | ||
ルーム配下ならルーム管理者、またはそれに準ずるユーザ(room_parts.edit_page, room_parts.create_page 双方が true のユーザ)はこの値に関わらず閲覧できる。 | ||
e.g.) ルーム管理者、またはそれに準ずるユーザ: ルーム管理者、編集長 | ||
期間限定公開の場合、現在時刻がfrom-toカラムの範囲内の時に公開。'), | ||
'from' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Datetime display frame from.'), | ||
'to' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Datetime display frame to.'), | ||
'translation_engine' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | ||
'is_auto_translated' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'is_first_auto_translation' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1), | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | ||
), | ||
), | ||
), | ||
'down' => array( | ||
'drop_table' => array( | ||
'block_role_permissions', 'blocks' | ||
), | ||
), | ||
); | ||
|
||
/** | ||
* Records keyed by model name. | ||
* | ||
* @var array $records | ||
*/ | ||
public $records = array( | ||
'Block' => array( | ||
array( | ||
'id' => '1', | ||
'language_id' => '2', | ||
'room_id' => '1', | ||
'plugin_key' => 'announcements', | ||
'key' => 'block_1', | ||
), | ||
array( | ||
'id' => '2', | ||
'language_id' => '2', | ||
'room_id' => '1', | ||
'plugin_key' => 'menus', | ||
'key' => 'block_2', | ||
), | ||
), | ||
); | ||
|
||
/** | ||
* 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) { | ||
if ($direction === 'down') { | ||
return true; | ||
} | ||
|
||
foreach ($this->records as $model => $records) { | ||
if (!$this->updateRecords($model, $records)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Update model records | ||
* | ||
* @param string $model model name to update | ||
* @param string $records records to be stored | ||
* @param string $scope ? | ||
* @return bool Should process continue | ||
*/ | ||
public function updateRecords($model, $records, $scope = null) { | ||
$Model = $this->generateModel($model); | ||
foreach ($records as $record) { | ||
$Model->create(); | ||
if (!$Model->save($record, false)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Schema file | ||
* | ||
* @author Noriko Arai <arai@nii.ac.jp> | ||
* @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 | ||
*/ | ||
|
||
/** | ||
* Schema file | ||
* | ||
* @author Shohei Nakajima <nakajimashouhei@gmail.com> | ||
* @package NetCommons\Blocks\Config\Schema | ||
* @SuppressWarnings(PHPMD.LongVariable) | ||
* @SuppressWarnings(PHPMD.TooManyFields) | ||
*/ | ||
class AppSchema extends CakeSchema { | ||
|
||
/** | ||
* Database connection | ||
* | ||
* @var string | ||
*/ | ||
public $connection = 'master'; | ||
|
||
/** | ||
* before | ||
* | ||
* @param array $event savent | ||
* @return bool | ||
*/ | ||
public function before($event = array()) { | ||
return true; | ||
} | ||
|
||
/** | ||
* after | ||
* | ||
* @param array $event event | ||
* @return void | ||
*/ | ||
public function after($event = array()) { | ||
} | ||
|
||
/** | ||
* block_role_permissions table | ||
* | ||
* @var array | ||
*/ | ||
public $block_role_permissions = array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), | ||
'roles_room_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), | ||
'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | ||
'permission' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Permission name | ||
e.g.) create_content, post_top_article', 'charset' => 'utf8'), | ||
'value' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1) | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') | ||
); | ||
|
||
/** | ||
* blocks table | ||
* | ||
* @var array | ||
*/ | ||
public $blocks = array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), | ||
'language_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 6, 'unsigned' => false), | ||
'room_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), | ||
'plugin_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'block key | プラグインKEY | plugins.key | ', 'charset' => 'utf8'), | ||
'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Key of the block.', 'charset' => 'utf8'), | ||
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'Name of the block.', 'charset' => 'utf8'), | ||
'public_type' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 4, 'unsigned' => false, 'comment' => '一般以下のパートが閲覧可能かどうか。 | ||
(0:非公開, 1:公開, 2:期間限定公開) | ||
ルーム配下ならルーム管理者、またはそれに準ずるユーザ(room_parts.edit_page, room_parts.create_page 双方が true のユーザ)はこの値に関わらず閲覧できる。 | ||
e.g.) ルーム管理者、またはそれに準ずるユーザ: ルーム管理者、編集長 | ||
期間限定公開の場合、現在時刻がfrom-toカラムの範囲内の時に公開。'), | ||
'from' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Datetime display frame from.'), | ||
'to' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Datetime display frame to.'), | ||
'translation_engine' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | ||
'is_auto_translated' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'is_first_auto_translation' => array('type' => 'boolean', 'null' => false, 'default' => null), | ||
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), | ||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | ||
'indexes' => array( | ||
'PRIMARY' => array('column' => 'id', 'unique' => 1) | ||
), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters