Name of the file: script.php
The file script.php
is a common file called by Joomla during the installation of an extension.
It hepls to manage and to personalize et It allows you to manage and customize the various events that can occur during the installation, the update or the uninstallation of a module, a plugin, a library or a component.
As events, we can mention: installation, uninstallation, update, "pre flight" and "post flight" which is called at the end of execution regardless of the mode used.
First, let's start with the first statement.
To ensure that the file will only be executed by the site Joomla application, we need to check that the `_JEXEC` constant is set before any operation.
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;
Name of the class: Mod_[module name]InstallerScript
Here the module name chosen is XtrmExample
(without the brackets of course) but it's up to you to define a name that must be unique and definitive.
We will therefore define the following PHP class:
/**
* Script file of XtrmAddons component.
*
* @category example
* @package Joomla
* @subpackage mod_xtrmexample
* @author example <example@example.com>
* @copyright Copyright 2019-2019 example.com. All rights reserved.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
* @version 4.0.01.03.1391229
* @link https://www.example.com/
*
* @access public
* @since 4.0.00.01.190425
*/
class Mod_XtrmExampleInstallerScript
{
// Declare here the methods of events.
}
This class will be instantiated whatever the mode used: installation, update or uninstallation.
The method install($parent)
is the method that will be called during the installation of the module, $parent
being the calling class of the script which makes it possible to access its information or public methods.
/**
* Method to install the extension.
*
* @param Joomla\CMS\Installer\Adapter\ModuleAdapter $parent is the class calling this method.
*
* @access public
* @since 4.0.00.01.190425
* @version 4.0.01.03.1391229
*
* @return void
*/
public function install($parent)
{
echo '<p class="alert alert-info">'
. 'Method: Install<br />'
. 'Parent: ' . get_class($parent)
. '</p><p class="alert alert-success">'
. JText::_('MOD_XTRMEXAMPLE_INSTALL_SUCCESS')
. '</p>';
}
The method uninstall($parent)
is the method that will be called during the uninstallation of the module, $parent
being the calling class of the script which makes it possible to access its information or public methods.
/**
* Method to uninstall the component.
*
* @param Joomla\CMS\Installer\Adapter\ModuleAdapter $parent is the class calling this method.
*
* @access public
* @since 4.0.00.01.190425
* @version 4.0.01.03.1391229
*
* @return void
*/
public function uninstall($parent)
{
echo '<p class="alert alert-info">'
. 'Method: uninstall<br />'
. 'Parent: ' . get_class($parent)
. '</p><p class="alert alert-success">'
. JText::_('MOD_XTRMEXAMPLE_UNINSTALL_SUCCESS')
. '</p>';
}
The method update($parent)
is the method that will be called during the update of the module, $parent
being the calling class of the script which makes it possible to access its information or public methods.
/**
* Method to update the component.
*
* @param Joomla\CMS\Installer\Adapter\ModuleAdapter $parent is the class calling this method.
*
* @access public
* @since 4.0.00.01.190425
* @version 4.0.01.03.1391229
*
* @return void
*/
public function update($parent)
{
$this->cleanUpdatesSites();
echo '<p class="alert alert-info">'
. 'Method: update<br />'
. 'Parent: ' . get_class($parent)
. '</p><p class="alert alert-success">'
. JText::_('MOD_XTRMEXAMPLE_UPDATE_SUCCESS')
. '</p>';
}
The method preflight($parent)
is a method that will be called at the beginning of the execution of the script whatever the mode, installation, uninstallation or update of the module, $parent
being the calling class of the script which makes it possible to access its information or public methods.
/**
* Method run before an install/update/uninstall method.
*
* @param string $type is the type of change (install, update or discover_install)
* @param Joomla\CMS\Installer\Adapter\ModuleAdapter $parent is the class calling this method
*
* @access public
* @since 4.0.01.03.136
* @version 4.0.01.03.1391229
*
* @return void
*/
public function preflight($type, $parent)
{
echo '<p class="alert alert-warning">'
. 'Method: preflight<br />'
. 'Name: ' . $parent->getName()
. '<br />'
. 'Element: ' . $parent->getElement()
. '<br />'
. 'Version: ' . (string) $parent->getManifest()->version
. '<br /><br />'
. 'Type: ' . $type
. '<br />'
. 'Parent: ' . get_class($parent)
. '</p>';
}
The method postflight($parent)
is a method that will be called at the end of the execution of the script whatever the mode, installation, uninstallation or update of the module, $parent
being the calling class of the script which makes it possible to access its information or public methods.
/**
* Method run after an install/update/uninstall method.
*
* @param string $type is the type of change (install, update or discover_install)
* @param Joomla\CMS\Installer\Adapter\ModuleAdapter $parent is the class calling this method
*
* @access public
* @since 4.0.00.01.190425
* @version 4.0.01.03.1391229
*
* @return void
*/
public function postflight($type, $parent)
{
echo '<p class="alert alert-warning">'
. 'Method: postflight<br />'
. 'Type: ' . $type
. '<br />'
. 'Parent: ' . get_class($parent)
. '</p>';
$this->copyright($parent);
}