Plugin Specific Files

Plugin Specific Files

makelos

This is a script that is used for installing, uninstalling and testing your plugin. Search for geo_kit in this file for places that will need modification for your plugin. The installation script, called from this script, is what does the actual installation and uninstallation. In this example, it is plugin_home/installer/geo_kit_installer.php.

#!/usr/bin/env php
<?php
 
array_shift($argv);
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
 
$task = empty($argv) ? false : array_shift($argv);
$task = !in_array($task,get_class_methods('Makelos')) ? 'help' : $task;
 
include(dirname(__FILE__).str_repeat(DS.'..', 4).DS.'config'.DS.'config.php');
 
class Makelos
{
    var $repository = 'http://svn.akelos.org/plugins/geo_kit';
 
    function help()
    {
        echo "\nValid commands are ".join(', ', get_class_methods('Makelos'))."\n";
    }
 
    function test($options = array())
    {
        system('/usr/bin/env php '.dirname(__FILE__).'/test/geo_kit_tests.php');
    }
 
    function install()
    {
        $Installer =& $this->_getInstaller();
        $Installer->install();
    }
 
    function uninstall()
    {
        $Installer =& $this->_getInstaller();
        $Installer->uninstall();
    }
 
    function &_getInstaller()
    {
        $plugin_dir = AK_BASE_DIR.DS.'app'.DS.'vendor'.DS.'plugins'.'geo_kit';
        $installer_file = $plugin_dir.DS.'installer'.DS.'geo_kit_installer.php';
        require_once($installer_file);
        $Installer =& new GeoKitInstaller();
        return $Installer;
    }
 
    function connectToDatabase($database_settings)
    {
        $this->_includeDependencies();
        Ak::db($database_settings[AK_ENVIRONMENT]);
    }
 
    function _includeDependencies()
    {
        require_once(AK_LIB_DIR.DS.'Ak.php');
        require_once(AK_LIB_DIR.DS.'AkObject.php');
        require_once(AK_LIB_DIR.DS.'AkInflector.php');
        require_once(AK_LIB_DIR.DS.'AkPlugin.php');
        require_once(AK_LIB_DIR.DS.'AkPlugin/AkPluginManager.php');
        require_once(AK_LIB_DIR.DS.'AkInstaller.php');
        require_once(AK_LIB_DIR.DS.'utils'.DS.'generators'.DS.'AkelosGenerator.php');
    }
}
 
$Makelos = new Makelos();
$Makelos->connectToDatabase($database_settings);
$Makelos->$task(@$argv);

init.php

Contains code that is executed each time the user's project is started. In some cases, it may run the plugin.

<?php
 
class GeoKitPlugin extends AkPlugin
{
    function load() # Executed when project is started
    {
    }
} // class GeoKitPlugin
 
?>

geo_kit_installer.php

This script will perform the install and uninstall of the plugin. You will need to modify it for your plugin.

If you have a neat piece of code for a plugin installer that you've written, please modify this entry to include your well-documented code, even though it doesn't apply to the geo_kit plugin.

The installer is stored in plugin_home/installer/ and is executed at a command line:

cd project/app/vendor/plugins/geo_kit
makelos install
    or
makelos uninstall

Following is a listing of plugin_dir/installer/geo_kit_installer.php. When writing your plugin installer, you may copy, rename and modify this script. Make sure that your makelos script points to your installer file.

<?php
# This class is accessed by the makelos script
class GeoKitInstaller
{
    function install()
    {
        $config_file = AK_BASE_DIR.DS.'config'.DS.'config.php';
        $backup = str_replace('config.php','BEFORE_geo_kit-config.php',$config_file);
        if(file_exists($backup)) {
            echo "\ngeo_kit is already installed\n";
            return;
        }
 
        #Back up app_home/config/config.php.
        if(!copy($config_file,$backup)) {
            echo "\ngeo_kit installation failed.  Backup of $config_file failed\n";
            return;
        }
        $config = file_get_contents($config_file);
 
        #Insert a require_once statement for the plugins/geo_kit/config/config.php in
        #    app_home/config/config.php just before the end.
        $plugin_dir = AK_BASE_DIR.DS.'app'.DS.'vendor'.DS.'plugins'.DS.'geo_kit';
        $plugin_config_file = $plugin_dir.DS.'config'.DS.'config.php';
        $require_stmt = "require_once ($plugin_config_file)";
        $config = str_replace("\n?>",$geo_kit_config."\n?>",$config);
 
        if(!file_put_contents($config_file,$config)) {
            echo "\ngeo_kit installation failed.  Creation of new $config_file failed\n";
            return;
        }
 
        # Copy the plugin program files from plugins/geo_kit/lib to app_home/lib.
        $plugin_lib = $plugin_dir.DS."lib".DS;
        $cmd = "cp -R $plugin_lib ".AK_BASE_DIR;
        exec($cmd);
        if(!file_exists(AK_BASE_DIR.DS.'lib')) {
            if(!mkdir(AK_BASE_DIR.DS.'lib',775)) {
                echo "\ngeo_kit installation failed during attempt to copy ";
                echo "\"lib\" directory files\n";
                return;
            }
        echo "\ngeo_kit is now installed\n";
    } // function install
 
    function uninstall()
    {
        # Restore <project>/config/config.php to what it was before geo_kit
        # was installed.
        $config_file = AK_BASE_DIR.DS.'config'.DS.'config.php';
        $backup = str_replace('config.php','BEFORE_geo_kit-config.php',$config_file);
        $config = file_get_contents($config_file);
        if(!file_exists($backup)) {
            echo "\ngeo_kit is not installed\n";
            return;
        }
        if(!rename($backup,$config_file)) {
            echo "geo_kit uninstallation failed.  Attempt to rename $backup to $config_file failed\n";
            return;
        }
 
        # Delete app_home/lib/geo_kit and the files in it.
        $lib_dir = AK_BASE_DIR.DS.'lib'.DS.'geo_kit';
        exec("rm -rf $lib_dir");
        echo "\ngeo_kit has been uninstalled\n";
    }
}
?>

Return

 
plugin-specific-files.txt · Last modified: 2008/09/18 14:07 by 82.103.221.224
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki