プラグインテーブルにデータ追加
プラグインテーブルにデータ追加
まだNetCommons3 に追加モジュールインストールの仕組みが用意されていないので、モジュールを追加するために手作業で操作を行います。[2016-10-10]
データベーステーブルを修正するマイグレーション用phpファイルを作成します。
作業を簡略化させるため、アクセスカウンタープラグインからコピーして編集します。
# mkdir /var/www/app/app/Plugin/Simpletexts/Config/Migration
# cd /var/www/app/app/Plugin/Simpletexts/Config/Migration
# cp /var/www/app/app/Plugin/AccessCounters/Config/Migration/001_plugin_records.php .
編集後の/var/www/app/app/Plugin/Simpletexts/Config/Migration/001_plugin_records.php
<?php /** * Add plugin migration * * @author yourname <yourname@yourname.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'); /** * Add plugin migration * * @package NetCommons\Simpletexts\Config\Migration */ class PluginRecords extends NetCommonsMigration { /** * Migration description * * @var string */ public $description = 'plugin_records'; /** * Actions to be performed * * @var array $migration */ public $migration = array( 'up' => array(), 'down' => array(), ); /** * plugin data * * @var array $migration */ public $records = array( 'Plugin' => array( //日本語 array( 'language_id' => '2', 'key' => 'simpletexts', 'namespace' => 'netcommons/simpletexts', 'name' => 'シンプルテキスト', 'type' => 1, 'default_action' => 'simpletexts/view', 'default_setting_action' => 'simpletext_blocks/index', ), //英語 array( 'language_id' => '1', 'key' => 'simpletexts', 'namespace' => 'netcommons/simpletexts', 'name' => 'Simpletexts', 'type' => 1, 'default_action' => 'simpletexts/view', 'default_setting_action' => 'simpletext_blocks/index', ), ), 'PluginsRole' => array( array( 'role_key' => 'room_administrator', 'plugin_key' => 'simpletexts', ), ), 'PluginsRoom' => array( //パブリックスペース array('room_id' => '1', 'plugin_key' => 'simpletexts', ), //プライベートスペース array('room_id' => '2', 'plugin_key' => 'simpletexts', ), //グループスペース array('room_id' => '3', 'plugin_key' => 'simpletexts', ), ), ); /** * 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) { $this->loadModels([ 'Plugin' => 'PluginManager.Plugin', ]); if ($direction === 'down') { $this->Plugin->uninstallPlugin($this->records['Plugin'][0]['key']); return true; } foreach ($this->records as $model => $records) { if (!$this->updateRecords($model, $records)) { return false; } } return true; } }
マイグレーション実行
# cd /var/www/app/app # Console/cake Migrations.migration run all -c master -i master -p Simpletexts Cake Migration Shell --------------------------------------------------------------- Running migrations: [001] 001_plugin_records --------------------------------------------------------------- All migrations have completed.
マイグレーションでテンポラリのファイルのオーナーが変わるので、chown する。
# chown -R apache:apache /var/www/app/app/