Install Multiple Joomla Extensions in a Single Package

Posted in Joomla!
2009-10-24 19:47:38 +0000 UTC

Lately in my spare time, I've been working on a new Extension collection for my new site, I Hate My Neighbors. I'm planning on releasing this one as a commercial component soon, and as such I wanted to make sure the install process was as simple as possible. Since the component has some plugins and modules that go along with it, I decided it should go ahead and install everything from a single package. Here's how I did it.

First, I created a directory in the administrator section of the component package named "extensions" and copied the installers for the modules and plugins into it. I also created an install file for my component in component.install.php. I then made sure to add these files to the component's xml install file under the administrator files section.

	<files folder="admin">

What this will do is copy the install packages for the helper extensions to the server, but it won't actually install the extensions. To handle the install, I added code to component.install.php to handle this after the main component was finished installing. The first thing I did was import Joomla's install helper and create a new instance of JInstaller:

$installer = new JInstaller();
$installer->_overwrite = true;

Next, I set up an array of each extension I wanted installed.

$pkg_path = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_component'.DS.'extensions'.DS;
$pkgs = array( ''=>'Component Extra Module',
               ''=>'Component Extra Plugin'

Finally, I ran this array through a loop to install each item, as well as output status to the user:

foreach( $pkgs as $pkg => $pkgname ):
	$package = JInstallerHelper::unpack( $pkg_path.$pkg );
	if( $installer->install( $package['dir'] ) )
		$msgcolor = "#E0FFE0";
		$msgtext  = "$pkgname successfully installed.";
		$msgcolor = "#FFD0D0";
		$msgtext  = "ERROR: Could not install the $pkgname. Please install manually.";
	<table bgcolor="<?php echo $msgcolor; ?>" width ="100%">
		<tr style="height:30px">
			<td width="50px"><img src="/administrator/images/tick.png" height="20px" width="20px"></td>
			<td><font size="2"><b><?php echo $msgtext; ?></b></font></td>
JInstallerHelper::cleanupInstall( $pkg_path.$pkg, $package['dir'] );