Wiki ⇒ v9 Developer's Manual ⇒ Installer ⇒ cpg_inst.php ⇒ CPG Dragonfly™ CMS
Wikiv9 Developer's ManualInstaller ⇒ cpg_inst.php

13.1. 1: cpg_inst.php Parent


It is an installer helper but also a controller for module install and upgrade. Within this document you will find detailed information about cpg_inst.php and how to use it.

Table of content

Structure

Class name
must be the same, case sensitive, module name. Within this document we use Example as Class name

Class constructor
must be the same, case sensitive, as the Class name. Within this document we use Example as constructor name. PHP5 users can directly use function __construct() instead.

$this->radmin
if true you will be able to set admin permission rules for this module.

$this->version
Versioning wiki entry

$this->modname
the name of your module, used in the credits.html

$this->description
the module description that will show up in different areas of DragonflyCMS, including credits.html

$this->author
well thats easy

$this->website
website url where support can be found

$this->prefix
by default every module will prefix tables using is own name. Using the untouched defaults, which we strongly suggest, you will have all of your tables called cms_example. It means that the installer will prepend the global and user defined database tables $prefix to the module's $this->prefix

$this->db_tables
default empty, module doesn't use database tables and you don't even need this file then. If our module needs to store its own data, then we use it as follow:
$this->dbtables = array($this->prefix, $this->prefix.'_cat', $this->prefix.'_config');
we will end up by having cms_example, cms_example_cat and cms_example_config tables.

function install()
called only when installing a module, most luckily we don't need to modify this function at all. Keep reading and you will found out why.

function uninstall()
called only when uninstalling, most luckily we don't need to modify this function at all. Keep reading and you will found out why.

function upgrade()
called for module's upgrade, red or blue pill?

File content

<?php
/*********************************************
  CPG Dragonfly™ CMS
  ********************************************
  Copyright © 2004 - 2008 by CPG-Nuke Dev Team
  http://dragonflycms.org

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version
**********************************************/
if (!defined('ADMIN_MOD_INSTALL')) { exit; }

class 
Example {
    var 
$radmin;
    var 
$version;
    var 
$modname;
    var 
$description;
    var 
$author;
    var 
$website;
    var 
$prefix;
    var 
$dbtables;

    function 
Example() {
        
$this->radmin true;
        
$this->version '0.0.0.1';
        
$this->modname 'Example';
        
$this->description 'Store and display your favorite examples.';
        
$this->author 'Your name';
        
$this->website 'example.com';
        
$this->prefix strtolower(__CLASS__);
        
$this->dbtables = array();
    }

# module installer
    
function install() {
        global 
$tablelist$tables$indexes$records;
        foreach (
$tables AS $table => $columns) {
            if (isset(
$tablelist[$table])) { $db->query('DROP TABLE '.$tablelist[$table]); }
            
db_check::create_table($table$columns$indexes[$table]);
        }
        if (
is_array($records) && !empty($records)) {
            foreach (
$records AS $table => $content) {
                
db_check::table_data($table$content);
            }
        }
        return 
true;
    }
    
# module uninstaller
    
function uninstall() {
        global 
$installer;
        foreach (
$this->dbtables as $table) {
            
$installer->add_query('DROP'$table);
        }
        return 
true;
    }

# module upgrader
    
function upgrade($prev_version) {
        global 
$tablelist$tables$indexes$records$installer;
        foreach (
$tables AS $table => $columns) {
            
db_check::table_structure($table$columns$indexes[$table]);
        }
        if (
is_array($records) && !empty($records)) {
            foreach (
$records AS $table => $content) {
                
db_check::table_data($table$content);
            }
        }
        return 
true;
    }
}

?>

Examples

Install


Upgrade



Created: Friday, February 29, 2008 (08:50:44) by NanoCaiordo
Updated: Sunday, October 23, 2011 (06:07:02) by Dizfunkshunal