PyroCMS Module (Upgrade)

PyroCMS Module (Upgrade)

README

This is how to upgrade a PyroCMS module; a process very-very easy (but some people couldn’t understand how to do this); a module upgrading let us change many features of the module itself like the table structure, settings and maybe integration with other modules. The upgrade button display is controlled by the function version_compare() used in the method Module_m::get_all() and the property public $version = 0.0 in the file details.php of each module.

This is an example of how to use it; just suppose which exists a module called Extrapage and the initial version of it was 0.6:

class Module_Extrapage extends Module{
    public $version = 0.6;
    public function info(){ ... }
    public function install(){ ... }
}

In sometime in the future one of the developers of the module had decided to add a table, and store in the core::settings table a configuration parameter to access it from the controller of the module, he doesn’t want to alter the database manually because he doesn’t remember all the commands to do something in the database engine used for the project. Well, he could write a code like this to upgrade the module version:

...
public $version = 0.8;
public function upgrade($old_version){
    $tables = array(
        'features'=>array(
            'id'=>array(
                'type'=>'INT',
                'constraint'=>11,
                'auto_increment'=>true,
                'primary'=>true ),
            'title'=>array(
                'type'=>'VARCHAR',
                'constraint'=>255,
                'default'=>'',
                'null'=>false ),
            'slug'=>array(
                'type'=>'VARCHAR',
                'constraint'=>255,
                'default'=>'',
                'null'=>false ),
            'content'=>array(
                'type'=>'VARCHAR',
                'constraint'=>255,
                'default'=>'' ),
            'module'=>array(
                'type'=>'VARCHAR',
                'constraint'=>255,
                'default'=>'' ),
            'subject_id'=>array(
                'type'=>'INT',
                'constraint'=>11 )
        )
    );
    $this->db->insert('settings', array(
        'slug'=>'sample_setting',
        'title'=>'Sample Setting',
        'description'=>'A Yes or No option for the Sample module',
        'default'=>'1',
        'value'=>'1',
        'type'=>'select',
        'options'=>'1=Yes|0=No',
        'is_required'=>1,
        'is_gui'=>1,
        'module'=>'sample'
    ));
    return $this->install_tables($tables) ? TRUE : FALSE;
}
Do you have a project idea? Let's make it together!