Source code for file /joomla/installer/adapters/module.php
Documentation is available at module.php
* @version $Id: module.php 6138 2007-01-02 03:44:18Z eddiea $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* @package Joomla.Framework
* @param object $parent Parent object [JInstaller instance]
$this->parent =
& $parent;
* @return boolean True on success
// Get a database connector object
$db =
& $this->parent->getDBO();
// Get the extension manifest object
$manifest =
& $this->parent->getManifest();
$this->manifest =
& $manifest->document;
* ---------------------------------------------------------------------------------------------
* Manifest Document Setup Section
* ---------------------------------------------------------------------------------------------
// Set the component name
$name =
& $this->manifest->getElementByPath('name');
$this->set('name', $name->data());
// Get the component description
$description =
& $this->manifest->getElementByPath('description');
if (is_a($description, 'JSimpleXMLElement')) {
$this->parent->set('message', $this->get('name').
'<p>'.
$description->data().
'</p>');
$this->parent->set('message', $this->get('name'));
* ---------------------------------------------------------------------------------------------
* Target Application Section
* ---------------------------------------------------------------------------------------------
// Get the target application
if ($cname =
$this->manifest->attributes('client')) {
// Attempt to map the client to a base path
jimport('joomla.application.helper');
$this->parent->abort('Module Install: '.
JText::_('Unknown client type').
' ['.
$client->name.
']');
$basePath =
$client->path;
// No client attribute was found so we assume the site as the client
// Set the installation path
$element =
& $this->manifest->getElementByPath('files');
if (is_a($element, 'JSimpleXMLElement') &&
count($element->children())) {
$files =
& $element->children();
foreach ($files as $file) {
if ($file->attributes('module')) {
$mname =
$file->attributes('module');
$this->parent->setPath('extension_root', $basePath.
DS.
'modules'.
DS.
$mname);
$this->parent->abort('Module Install: '.
JText::_('No module file specified'));
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
* If the module directory already exists, then we will assume that the
* module is already installed or another module is using that
if (file_exists($this->parent->getPath('extension_root'))) {
$this->parent->abort('Module Install: '.
JText::_('Another module is already using directory').
': "'.
$this->parent->getPath('extension_root').
'"');
// If the module directory does not exist, lets create it
if (!file_exists($this->parent->getPath('extension_root'))) {
if (!$created =
JFolder::create($this->parent->getPath('extension_root'))) {
$this->parent->abort('Module Install: '.
JText::_('Failed to create directory').
': "'.
$this->parent->getPath('extension_root').
'"');
* Since we created the module directory and will want to remove it if
* we have to roll back the installation, lets add it to the
* installation step stack
$this->parent->pushStep(array ('type' =>
'folder', 'path' =>
$this->parent->getPath('extension_root')));
// Copy all necessary files
if ($this->parent->parseFiles($element, -
1) ===
false) {
// Install failed, roll back changes
$this->parent->parseMedia($this->manifest->getElementByPath('media'), $clientId);
$this->parent->parseLanguages($this->manifest->getElementByPath('languages'), $clientId);
$this->parent->parseFiles($this->manifest->getElementByPath('images'), -
1);
* ---------------------------------------------------------------------------------------------
* Database Processing Section
* ---------------------------------------------------------------------------------------------
// Check to see if a module by the same name is already installed
' WHERE module = '.
$db->Quote($mname) .
' AND client_id = '.(int)
$clientId;
// Install failed, roll back changes
$this->parent->abort('Module Install: '.
$db->stderr(true));
// Was there a module already installed with the same name?
// Install failed, roll back changes
$this->parent->abort('Module Install: '.
JText::_('Module').
' "'.
$mname.
'" '.
JText::_('already exists!'));
$row->title =
$this->get('name');
$row->ordering =
$row->getNextOrder( "position='left'" );
$row->access =
$clientId ==
1 ?
2 :
0;
$row->client_id =
$clientId;
$row->params =
$this->parent->getParams();
// Install failed, roll back changes
$this->parent->abort('Module Install: '.
$db->stderr(true));
// Since we have created a module item, we add it to the installation step stack
// so that if we have to rollback the changes we can undo it.
$this->parent->pushStep(array ('type' =>
'module', 'id' =>
$row->id));
// Clean up possible garbage first
$query =
'DELETE FROM #__modules_menu WHERE moduleid = '.(int)
$row->id;
// Install failed, roll back changes
$this->parent->abort('Module Install: '.
$db->stderr(true));
// Time to create a menu entry for the module
$query =
'INSERT INTO `#__modules_menu` ' .
' VALUES ('.(int)
$row->id.
', 0 )';
// Install failed, roll back changes
$this->parent->abort('Module Install: '.
$db->stderr(true));
* Since we have created a menu item, we add it to the installation step stack
* so that if we have to rollback the changes we can undo it.
$this->parent->pushStep(array ('type' =>
'menu', 'id' =>
$db->insertid()));
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
// Lastly, we will copy the manifest file to its appropriate place.
if (!$this->parent->copyManifest(-
1)) {
// Install failed, rollback changes
$this->parent->abort('Module Install: '.
JText::_('Could not copy setup file'));
* Custom uninstall method
* @param int $id The id of the module to uninstall
* @param int $clientId The id of the client (unused)
* @return boolean True on success
$db =
& $this->parent->getDBO();
// First order of business will be to load the module object table from the database.
// This should give us the necessary information to proceed.
// Is the module we are trying to uninstall a core one?
// Because that is not a good idea...
// Get the extension root path
jimport('joomla.application.helper');
$this->parent->abort('Module Uninstall: '.
JText::_('Unknown client type').
' ['.
$row->client_id.
']');
$this->parent->setPath('extension_root', $client->path.
DS.
'modules'.
DS.
$row->module);
// Get the package manifest objecct
$this->parent->setPath('source', $this->parent->getPath('extension_root'));
$manifest =
& $this->parent->getManifest();
if (!is_a($manifest, 'JSimpleXML')) {
// Make sure we delete the folders
JError::raiseWarning(100, 'Module Uninstall: Package manifest file invalid or not found');
$root =
& $manifest->document;
$this->parent->removeFiles($root->getElementByPath('media'));
$this->parent->removeFiles($root->getElementByPath('administration/media'), 1);
$this->parent->removeFiles($root->getElementByPath('languages'));
$this->parent->removeFiles($root->getElementByPath('administration/languages'), 1);
// Lets delete all the module copies for the type we are uninstalling
' WHERE module = '.
$db->Quote($row->module) .
' AND client_id = '.(int)
$row->client_id;
$modules =
$db->loadResultArray();
// Do we have any module copies?
' FROM #__modules_menu' .
' WHERE moduleid IN ("'.
$modID.
'")';
// Now we will no longer need the module object, so lets delete it and free up memory
// Remove the installation folder
if (!JFolder::delete($this->parent->getPath('extension_root'))) {
// JFolder should raise an error
* - Roll back the menu item
* @param array $arg Installation step to rollback
* @return boolean True on success
// Get database connector object
$db =
& $this->parent->getDBO();
// Remove the entry from the #__modules_menu table
' FROM `#__modules_menu`' .
' WHERE moduleid='.(int)
$arg['id'];
return ($db->query() !==
false);
* - Roll back the module item
* @param array $arg Installation step to rollback
* @return boolean True on success
// Get database connector object
$db =
& $this->parent->getDBO();
// Remove the entry from the #__modules table
' WHERE id='.(int)
$arg['id'];
return ($db->query() !==
false);