Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
installer
Browse files Browse the repository at this point in the history
  • Loading branch information
elinw committed Apr 20, 2011
1 parent ec45ca1 commit af38731
Show file tree
Hide file tree
Showing 13 changed files with 587 additions and 622 deletions.
73 changes: 30 additions & 43 deletions libraries/joomla/installer/adapters/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ public function install()
// Get the extension manifest object
$this->manifest = $this->parent->getManifest();

/**
* ---------------------------------------------------------------------------------------------
* Manifest Document Setup Section
* ---------------------------------------------------------------------------------------------
*/
// Manifest Document Setup Section

// Set the extensions name
$name = strtolower(JFilterInput::getInstance()->clean((string)$this->manifest->name, 'cmd'));
Expand All @@ -119,81 +115,72 @@ public function install()
$this->parent->setPath('extension_administrator', JPath::clean(JPATH_ADMINISTRATOR.DS.'components'.DS.$this->get('element')));
$this->parent->setPath('extension_root', $this->parent->getPath('extension_administrator')); // copy this as its used as a common base

/**
* ---------------------------------------------------------------------------------------------
* Basic Checks Section
* ---------------------------------------------------------------------------------------------
*/
// Basic Checks Section


// Make sure that we have an admin element
if (!$this->manifest->administration) {
JError::raiseWarning(1, JText::_('JLIB_INSTALLER_ERROR_COMP_INSTALL_ADMIN_ELEMENT'));
return false;
}

/**
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
*/
// Filesystem Processing Section

/*
* If the component site or admin directory already exists, then we will assume that the component is already
* installed or another component is using that directory.
*/

// If the component site or admin directory already exists, then we will assume that the component is already
// installed or another component is using that directory.

if (file_exists($this->parent->getPath('extension_site')) || file_exists($this->parent->getPath('extension_administrator'))) {
// look for an update function or update tag
// Look for an update function or update tag
$updateElement = $this->manifest->update;
// upgrade manually set
// update function available
// update tag detected
// Upgrade manually set
// Update function available
// Update tag detected

if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || $updateElement) {
return $this->update(); // transfer control to the update function
}
else if (!$this->parent->getOverwrite()) {
// overwrite is set
// we didn't have overwrite set, find an update function or find an update tag so lets call it safe
if (file_exists($this->parent->getPath('extension_site'))) { // if the site exists say that
// Overwrite is set
// We didn't have overwrite set, find an update function or find an update tag so lets call it safe
if (file_exists($this->parent->getPath('extension_site'))) {
// If the site exists say so
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_DIR_SITE', $this->parent->getPath('extension_site')));
}
else {
// if the admin exists say that
// If the admin exists say so
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_DIR_ADMIN', $this->parent->getPath('extension_administrator')));
}
return false;
}
}

/**
* ---------------------------------------------------------------------------------------------
* Installer Trigger Loading
* ---------------------------------------------------------------------------------------------
*/
// Installer Trigger Loading

// If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet)
$manifestScript = (string)$this->manifest->scriptfile;

if ($manifestScript) {
$manifestScriptFile = $this->parent->getPath('source').DS.$manifestScript;

if (is_file($manifestScriptFile)) {
// load the file
// Load the file
include_once $manifestScriptFile;
}

// Set the class name
$classname = $this->get('element').'InstallerScript';

if (class_exists($classname)) {
// create a new instance
// Create a new instance
$this->parent->manifestClass = new $classname($this);
// and set this so we can copy it later
// And set this so we can copy it later
$this->set('manifest_script', $manifestScript);
// Note: if we don't find the class, don't bother to copy the file
}
}

// run preflight if possible (since we know we're not an update)
// Run preflight if possible (since we know we're not an update)
ob_start();
ob_implicit_flush(false);

Expand All @@ -205,10 +192,11 @@ public function install()
}
}

$msg = ob_get_contents(); // create msg object; first use here
// Create msg object; first use here
$msg = ob_get_contents();
ob_end_clean();

// If the component directory does not exist, lets create it
// If the component directory does not exist, let's create it
$created = false;

if (!file_exists($this->parent->getPath('extension_site'))) {
Expand All @@ -218,15 +206,14 @@ public function install()
}
}

/*
* Since we created the component directory and will want to remove it if we have to roll back
* the installation, lets add it to the installation step stack
*/
// Since we created the component directory and will want to remove it if we have to roll back
// the installation, let's add it to the installation step stack

if ($created) {
$this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_site')));
}

// If the component admin directory does not exist, lets create it
// If the component admin directory does not exist, let's create it
$created = false;

if (!file_exists($this->parent->getPath('extension_administrator'))) {
Expand Down
81 changes: 33 additions & 48 deletions libraries/joomla/installer/adapters/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class JInstallerFile extends JAdapterInstance
/**
* Custom loadLanguage method
*
* @access public
* @param string $path the path where to find language files
* @since 11.1
*/
Expand All @@ -45,7 +44,6 @@ public function loadLanguage($path)
/**
* Custom install method
*
* @access public
* @return boolean True on success
* @since 11.1
*/
Expand All @@ -54,13 +52,9 @@ public function install()
// Get the extension manifest object
$this->manifest = $this->parent->getManifest();

/**
* ---------------------------------------------------------------------------------------------
* Manifest Document Setup Section
* ---------------------------------------------------------------------------------------------
*/
// Manifest Document Setup Section

// Set the extensions name
// Set the extension's name
$name = JFilterInput::getInstance()->clean((string)$this->manifest->name, 'string');
$this->set('name', $name);

Expand Down Expand Up @@ -98,17 +92,12 @@ public function install()
}


//Populate File and Folder List to copy
// Populate File and Folder List to copy
$this->populateFilesAndFolderList();

/**
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
*/
// Filesystem Processing Section


//Now that we have folder list, lets start creating them
// Now that we have folder list, lets start creating them
foreach ($this->folderList as $folder)
{
if (!JFolder::exists($folder))
Expand All @@ -117,33 +106,28 @@ public function install()
if (!$created = JFolder::create($folder))
{
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $folder));
// if installation fails, rollback
// If installation fails, rollback
$this->parent->abort();
return false;
}

/*
* Since we created a directory and will want to remove it if we have to roll back
* the installation due to some errors, lets add it to the installation step stack
*/
// Since we created a directory and will want to remove it if we have to roll back
// the installation due to some errors, lets add it to the installation step stack

if ($created) {
$this->parent->pushStep(array ('type' => 'folder', 'path' => $folder));
}
}

}

//Now that we have file list , lets start copying them
// Now that we have file list, let's start copying them
$this->parent->copyFiles($this->fileList);

// Parse optional tags
$this->parent->parseLanguages($this->manifest->languages);

/**
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
*/
// Finalization and Cleanup Section

// Get a database connector object
$db = $this->parent->getDbo();
Expand All @@ -170,10 +154,12 @@ public function install()

if ($id)
{
// load the entry and update the manifest_cache
// Load the entry and update the manifest_cache
$row->load($id);
$row->set('name', $this->get('name')); // update name
$row->manifest_cache = $this->parent->generateManifestCache(); // update manifest
// Update name
$row->set('name', $this->get('name'));
// Update manifest
$row->manifest_cache = $this->parent->generateManifestCache();
if (!$row->store()) {
// Install failed, roll back changes
$this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_FILE_ROLLBACK', JText::_('JLIB_INSTALLER_'.$this->route), $db->stderr(true)));
Expand All @@ -186,7 +172,8 @@ public function install()
$row->set('name', $this->get('name'));
$row->set('type', 'file');
$row->set('element', $this->get('element'));
$row->set('folder', ''); // There is no folder for files so leave it blank
// There is no folder for files so leave it blank
$row->set('folder', '');
$row->set('enabled', 1);
$row->set('protected', 0);
$row->set('access', 0);
Expand All @@ -202,7 +189,7 @@ public function install()
return false;
}

// set the insert id
// Set the insert id
$row->set('extension_id', $db->insertid());

// Since we have created a module item, we add it to the installation step stack
Expand Down Expand Up @@ -243,13 +230,13 @@ public function install()

/**
* Custom update method
* @access public
*
* @return boolean True on success
* @since 11.1
*/
public function update()
{
// set the overwrite setting
// Set the overwrite setting
$this->parent->setOverwrite(true);
$this->parent->setUpgrade(true);
$this->route = 'update';
Expand All @@ -261,9 +248,8 @@ public function update()
/**
* Custom uninstall method
*
* @access public
* @param string $id The id of the file to uninstall
* @param int $clientId The id of the client (unused; files are global)
*
* @return boolean True on success
* @since 11.1
*/
Expand Down Expand Up @@ -307,12 +293,12 @@ public function uninstall($id)
$packagePath = $this->parent->getPath('source');
$jRootPath = JPath::clean(JPATH_ROOT);

// loop through all elements and get list of files and folders
// Loop through all elements and get list of files and folders
foreach ($xml->fileset->files as $eFiles)
{
$folder = (string)$eFiles->attributes()->folder;
$target = (string)$eFiles->attributes()->target;
//Create folder path
// Create folder path
if(empty($target))
{
$targetFolder = JPATH_ROOT;
Expand All @@ -326,7 +312,7 @@ public function uninstall($id)
// Check if all children exists
if (count($eFiles->children()) > 0)
{
// loop through all filenames elements
// Loop through all filenames elements
foreach ($eFiles->children() as $eFileName)
{
if ($eFileName->getName() == 'folder') {
Expand All @@ -353,7 +339,7 @@ public function uninstall($id)

} else {
JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_FILE_UNINSTALL_INVALID_NOTFOUND_MANIFEST'));
// delete the row because its broken
// Delete the row because its broken
$row->delete();
return false;
}
Expand All @@ -366,10 +352,10 @@ public function uninstall($id)
}

/**
* function used to check if extension is already installed
* Function used to check if extension is already installed
*
* @access private
* @param string $element The element name of the extension to install
*
* @return boolean True if extension exists
* @since 11.1
*/
Expand Down Expand Up @@ -404,9 +390,8 @@ private function extensionExistsInSystem($extension = null)
}

/**
* function used to populate files and folder list
*
* @access private
* Function used to populate files and folder list
*
* @return boolean none
* @since 11.1
*/
Expand All @@ -424,7 +409,7 @@ private function populateFilesAndFolderList()
$packagePath = $this->parent->getPath('source');
$jRootPath = JPath::clean(JPATH_ROOT);

// loop through all elements and get list of files and folders
// Loop through all elements and get list of files and folders
foreach ($this->manifest->fileset->files as $eFiles)
{
// Check if the element is files element
Expand Down Expand Up @@ -455,15 +440,15 @@ private function populateFilesAndFolderList()
//Check if source folder exists
if (! JFolder::exists($sourceFolder)) {
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $sourceFolder));
// if installation fails, rollback
// If installation fails, rollback
$this->parent->abort();
return false;
}

// Check if all children exists
if (count($eFiles->children()))
{
// loop through all filenames elements
// Loop through all filenames elements
foreach ($eFiles->children() as $eFileName)
{
$path['src'] = $sourceFolder.DS.$eFileName;
Expand Down

0 comments on commit af38731

Please sign in to comment.