Difference between revisions of "Hooks"

From Softaculous Wiki
Jump to: navigation, search
Line 23: Line 23:
 
So when ever a new installation of WordPress is done the code in the '''function __post_install()''' will be executed.
 
So when ever a new installation of WordPress is done the code in the '''function __post_install()''' will be executed.
 
* Similarly you can do this for any script for pre installation, post installation, pre upgrade and also post upgrade.
 
* Similarly you can do this for any script for pre installation, post installation, pre upgrade and also post upgrade.
 
+
<br />
 
===Define PHP Version===
 
===Define PHP Version===
 
You can also define the PHP version in the Pre Install Hook if you are using multiple PHP versions on your server.
 
You can also define the PHP version in the Pre Install Hook if you are using multiple PHP versions on your server.
Line 38: Line 38:
 
</pre>
 
</pre>
 
* Now if the PHP version is defined here then Softaculous will skip its process to detect the PHP version while installing a Script.
 
* Now if the PHP version is defined here then Softaculous will skip its process to detect the PHP version while installing a Script.
 
+
<br />
 
===Explanation of the Variables===
 
===Explanation of the Variables===
  

Revision as of 03:23, 2 January 2012

Overview

The following guide will show you how the Server Admin can configure hooks to customize the installations.

  • SSH to your server and go to the following path:
/path-to-softaculous/enduser/hooks/
  • You can see 4 files pre_install.txt, post_install.txt, pre_upgrade.txt and post_upgrade.txt
  • Choose the file you would like to execute depending upon your requirement and rename it to make it a PHP file.
  • Add the code in the function available in the file and save the file.
  • That's it you have configured the hook.
  • For eg: You would like to make some changes for WordPress and you want to apply this change after every installation of WordPress done on the server. For this you will have to rename the file post_install.txt to post_install.php because the change is to be done after installation and add the code in the function __post_install().
function __post_install($installation){
     global $soft, $software, $globals;
     // The id for WordPress is 26
     if($soft == 26){
         /* Do things only if its WordPress */	
     }
}

So when ever a new installation of WordPress is done the code in the function __post_install() will be executed.

  • Similarly you can do this for any script for pre installation, post installation, pre upgrade and also post upgrade.


Define PHP Version

You can also define the PHP version in the Pre Install Hook if you are using multiple PHP versions on your server.

  • Rename the pre_install.txt to pre_install.php in the Hooks folder
  • Add your code to Identify the PHP version in the function __pre_install()
function __pre_install(){	
	global $soft, $software, $globals;
	// Your Code to Identify the PHP version
	// E.g
	$version = phpversion();
	define('php_version', $version);
}
  • Now if the PHP version is defined here then Softaculous will skip its process to detect the PHP version while installing a Script.


Explanation of the Variables

  • $soft is a string which contains the Script id. The script id can be obtained from $scripts in scripts.php
/path-to-softaculous/enduser/scripts.php
  • $installation in an array which contains the details of the installation.
Array
(
    [0] => Array
          (
              [insid] => installation id
              [sid] => script id
              [ver] => installed version of script
              [itime] => installation time
              [softpath] => path to installation
              [softurl] => installation URL
              [softdb] => database name of installation
              [softdbuser] => database user of installation
              [softdbhost] => database host of installation
              [softdbpass] => database password of installation
          )
)
  • $software is an array which has the details of the software.
Array
(
    [name] => Name of the script being installed
    [softname] => softaculous name of script being installed
    [desc] => Description of the script
    [ins] => 1
    [cat] => Category under which the script falls
    [type] => Type of script(php,js,perl)
    [ver] => Current version of script
    [path] => path where the script package is available
    [spacereq] => Space required for the script to be installed in bytes
    [adminurl] => The admin url of the script
)