Module Install & Upgrade - mymagic/open_hub GitHub Wiki
Module Installation
install
public function install($forceReset = false){}
installDb
public function installDb($forceReset = false){}
Module Upgrade
Please note that unlike
Yii migrate
which run on CLI, module upgrade runs thru Web Server (e.g. Apache) and this could break your upgrade process if it took too long beyond the limit of PHPmax_execution_time
setting or depends on it is running asmod_php
ormod_fastcgi
. This too can be affected if you are behind proxy or firewall (e.g. Cloudflare).
The modular architecture of OpenHub comes with built-in versioning control. Update version numbering in protected/modules/[moduleCode]/config/about.yaml
Migration instruction file is located at protected/modules/[moduleCode]/upgrades/upgrade-1.1.php
:
<?php
function upgrade_module_1_1($about)
{
$migration = Yii::app()->db->createCommand();
$migration->addColumn('todo', 'organization_id', 'integer NULL');
$migration->addColumn('todo', 'status', "enum('new','pending','processing','done','cancel','fail') DEFAULT 'new'");
// addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null )
$migration->addForeignKey('fk_todo-organization_id', 'todo', 'organization_id', 'organization', 'id', 'SET NULL', 'CASCADE');
// if your upgrade consist of new controller and you want to allow the action to be accessed by certain role
// Access::setAccessRole('[moduleCode]','controller_file',['action1','action2'],['role1','role2']);
Access::setAccessRole('todo','TodoController',['index','admin'],['admin','developer']);
return "Upgraded to version 1.1\n";
}
Instructions in this file will run automatically when you upgrade your module.
Click on Upgrade button to upgrade your module from backend.
You will see this when Upgrade migration completed successfully.