File : plugin_install.php

<?php
// This is an example of a third party plugin's database installation commands
 
if (!defined('JOMRES_INSTALLER')) exit;
 
// If the plugin requires some kind of functionality that can be run by the pseudocron handling, you can add it here.
 
/*
$cron = new jomres_cron($displayLog);
$cron->addJob("dummy_third_party_plugin","M","");
*/
 
/*
$query = "CREATE TABLE IF NOT EXISTS `#__jomres_thirdpartyplugin_dummy_third_party_plugin` (
  id int(10) NOT NULL auto_increment,
  PRIMARY KEY  (id)
)";
doInsertSql($query,"");
*/
 
 
/*
 
_______________________________________________________
Table creation and other installation functions
_______________________________________________________
 
To perform table creation you need another file in the same folder called plugin_install.php.
 
The pseudocon plugin_install.php file contains the following:
 
<?php
if (!defined('JOMRES_INSTALLER')) exit;
 
$query="
CREATE TABLE IF NOT EXISTS `#__jomcomp_cron` (
`id` INT NOT NULL AUTO_INCREMENT,
`job` char( 100 ) ,
`schedule` char(2) not null ,
`last_ran` int(12) not null ,
`parameters` varchar(255) null,
`locked` BOOL NOT NULL DEFAULT '0',
PRIMARY KEY ( `id` )
);
";
if (!doInsertSql($query))
echo "Failed to run query: ".$query."<br/>";
$query="
CREATE TABLE IF NOT EXISTS `#__jomcomp_cronlog` (
`id` int NOT NULL AUTO_INCREMENT ,
`log_details` text null,
PRIMARY KEY ( `id` )
);
";
if (!doInsertSql($query))
echo "Failed to run query: ".$query."<br/>";
?>
 
You must ensure that the file contains the if (!defined('JOMRES_INSTALLER')) exit; line. If not, then anybody could come along and run this file (eg by typing http://www.domain.com/jomres/remote_plugins/plugin_name/plugin_install.php into the browser. This is not a good thing. This line means that only the Jomres installer can run the script.
 
You can also do other things in this file to, for example, modify existing tables like so (example from invoices plugin)
 
if (!checkInvoiceSubscriptionIDColExists())
alterInvoiceSubscriptionIDCol();
 
function checkInvoiceSubscriptionIDColExists()
{
$query="SHOW COLUMNS FROM #__jomresportal_invoices LIKE 'subscription_id'";
$result=doSelectSql($query);
if (count($result)>0)
{
return true;
}
return false;
}
 
function alterInvoiceSubscriptionIDCol()
{
echo "Editing __jomresportal_invoices table adding apikey column<br>";
$query = "ALTER TABLE `#__jomresportal_invoices` ADD `subscription_id` int(11) NOT NULL ";
if (!doInsertSql($query,'') )
echo "<b>Error, unable to add __jomresportal_invoices subscription_id</b><br>";
}
 
You can use the plugin_install.php script to do other things, I'll leave the what to your imagination as here we're only describing the how.
_______________________________________________________
Dependancies and exclusions
_______________________________________________________
 
 
*** Dependancies ***
 
A plugin can be dependant on another plugin being installed, eg the invoices plugin depends on the pseudocron plugin being installed.
 
You can enforce a dependancy in your plugin by having a file in the same zip called plugin_dependencies_check.php
 
The invoice's plugin's dependancy check file consists of the following:
 
<?php
 
class plugin_check_dependencies
{
function plugin_check_dependencies()
{
$this->test_result = true;
$this->dependencies = array ( "pseudocron" );
foreach ($this->dependencies as $p)
{
if (!file_exists(JOMRESPATH_BASE."/remote_plugins/".$p."/plugin_info.php") )
$this->test_result = false;
}
}
}
 
?>
 
If you want to ensure that another plugin is installed before your plugin, you'd just need to edit this line:
 
$this->dependencies = array ( "pseudocron" );
 
 
*** Exclusions ***
 
You can exclude the plugin from being installed if another plugin is already installed and you know that the two are not compatible. An example situtation would be, both plugins contain a minicomponent file of the same name, eg if they both have a file j00017SRPavailabilitycalendar.class.php then you will cause a collision and Jomres' behaviour will become unpredictable).
 
You can enforce a dependancy in your plugin by having a file in the same zip called plugin_exclusions_check.php
 
An example exclusion check file consists of the following:
 
<?php
 
class plugin_check_exclusions
{
function plugin_check_exclusions()
{
$this->test_result = true;
$this->dependencies = array ( "slideshow_xfade" );
foreach ($this->dependencies as $p)
{
if (file_exists(JOMRESPATH_BASE."/remote_plugins/".$p."/plugin_info.php") )
$this->test_result = false;
}
}
}
 
?>
 
If you want to exclude installation if another plugin is installed before your plugin, you'd just need to edit this line:
 
$this->dependencies = array ( "slideshow_xfade" );
 
*/
 
?>
This document is copyright Vince Wooll/Woollyinwales IT, 2011. All rights reserved.