Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Finally, my_plugin_plugin.php is a special class that must extend the Plugin class of /components/plugins/lib/plugin.php. This class is used for installing, upgrading, uninstalling, and branding the plugin.

...

Install Logic

If your plugin requires any code to execute when installed, place that logic in your plugin's install() method.

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
linenumberstrue
<?php
class MyPluginPlugin {

    ...

    public function install() {
        #
    //    # TODO: Place installation logic here
        #
    }
}
?>
Info
titleNeed access to the database?

See how you can use the Record component to manipulate the database in the Database Access section of this manual.

Uninstall Logic

If your plugin required code to install, it likely requires code to uninstall. Place that logic in your plugin's uninstall() method.

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
linenumberstrue
<?php 
class MyPluginPlugin { 

    ... 

    public function uninstall($plugin_id, $last_instance) {
        #
        # TODO: Place uninstallation logic here 
        #
    } 
} 
?>

There are two parameters passed to the uninstall() method. The first ($plugin_id) is the ID of the plugin being uninstalled. Because a plugin can be installed independently under different companies you may need to perform uninstall logic for a single plugin instance. The second parameter ($last_instance) identifies whether or not this is the last instance of this type of plugin in the system. If true, be sure to remove all any remnants of the plugin.

Upgrade Logic

When the version of your code differs from that recorded within Blesta a user may initiate an upgrade, which will invoke your plugin's upgrade() method.

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
linenumberstrue
<?php
class MyPluginPlugin {

    ...

    public function upgrade($current_version) {
        #
        # TODO: Place upgrade logic here
        #
    }

}
?>

The $current_version is the version currently installed. That is, the version that will be upgraded from.