Skip to content

Commit

Permalink
Merge pull request #6 from s-nakajima/master
Browse files Browse the repository at this point in the history
Fix schema file and migration file
  • Loading branch information
s-nakajima committed Jul 18, 2015
2 parents 61f99c9 + ca267ac commit eed323d
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ before_script:
- git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR
- cd $NETCOMMONS_BUILD_DIR
- git checkout $NETCOMMONS_VERSION
- . tools/build/plugins/cakephp/travis/pre.sh
- travis_wait . tools/build/plugins/cakephp/travis/pre.sh
- . tools/build/plugins/cakephp/travis/environment.sh

script:
- . tools/build/plugins/cakephp/travis/main.sh
Expand Down
160 changes: 160 additions & 0 deletions Config/Migration/1434983278_init.php
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 removed Config/Schema/empty
Empty file.
104 changes: 104 additions & 0 deletions Config/Schema/schema.php
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')
);

}
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
}
},
"require": {
"cakephp/cakephp": "~2.4",
"cakephp/debug_kit": "~2.2",
"cakedc/migrations": "~2.2",
"twbs/bootstrap": "~3.1",
"components/jquery": "~2.1"
"cakephp/cakephp": "~2.6.9",
"cakephp/debug_kit": "~2.2",
"components/jquery": "~2.1",
"twbs/bootstrap": "~3.1"
},
"require-dev": {
"mustangostang/spyc": "dev-master",
"satooshi/php-coveralls": "dev-master",
"netcommons/boxes": "dev-master",
"netcommons/frames": "dev-master",
"netcommons/m17n": "dev-master",
"netcommons/net-commons": "dev-master",
"netcommons/pages": "dev-master",
"netcommons/plugin-manager": "dev-master",
"netcommons/rooms": "dev-master",
"netcommons/users": "dev-master"
"netcommons/users": "dev-master",
"satooshi/php-coveralls": "dev-master"
},
"license": "NetCommons License",
"authors": [
Expand Down

0 comments on commit eed323d

Please sign in to comment.