From af38731f3cbe569cbd0668211096ddb7cea4dbdb Mon Sep 17 00:00:00 2001 From: elin Date: Wed, 20 Apr 2011 07:56:04 -0400 Subject: [PATCH] installer --- .../joomla/installer/adapters/component.php | 73 ++-- libraries/joomla/installer/adapters/file.php | 81 ++--- .../joomla/installer/adapters/language.php | 54 +-- .../joomla/installer/adapters/library.php | 77 ++--- .../joomla/installer/adapters/module.php | 139 ++++---- .../joomla/installer/adapters/package.php | 60 ++-- .../joomla/installer/adapters/plugin.php | 194 +++++------ .../joomla/installer/adapters/template.php | 55 ++-- libraries/joomla/installer/extension.php | 50 ++- libraries/joomla/installer/helper.php | 14 +- libraries/joomla/installer/installer.php | 311 +++++++++--------- .../joomla/installer/librarymanifest.php | 60 +++- .../joomla/installer/packagemanifest.php | 41 ++- 13 files changed, 587 insertions(+), 622 deletions(-) diff --git a/libraries/joomla/installer/adapters/component.php b/libraries/joomla/installer/adapters/component.php index ced4008534..5c113b7abd 100644 --- a/libraries/joomla/installer/adapters/component.php +++ b/libraries/joomla/installer/adapters/component.php @@ -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')); @@ -119,11 +115,8 @@ 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) { @@ -131,45 +124,39 @@ public function install() 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; @@ -177,7 +164,7 @@ public function install() $manifestScriptFile = $this->parent->getPath('source').DS.$manifestScript; if (is_file($manifestScriptFile)) { - // load the file + // Load the file include_once $manifestScriptFile; } @@ -185,15 +172,15 @@ public function install() $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); @@ -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'))) { @@ -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'))) { diff --git a/libraries/joomla/installer/adapters/file.php b/libraries/joomla/installer/adapters/file.php index c682d5ec40..72b315f7a5 100644 --- a/libraries/joomla/installer/adapters/file.php +++ b/libraries/joomla/installer/adapters/file.php @@ -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 */ @@ -45,7 +44,6 @@ public function loadLanguage($path) /** * Custom install method * - * @access public * @return boolean True on success * @since 11.1 */ @@ -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); @@ -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)) @@ -117,15 +106,14 @@ 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)); } @@ -133,17 +121,13 @@ public function install() } - //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(); @@ -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))); @@ -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); @@ -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 @@ -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'; @@ -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 */ @@ -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; @@ -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') { @@ -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; } @@ -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 */ @@ -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 */ @@ -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 @@ -455,7 +440,7 @@ 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; } @@ -463,7 +448,7 @@ private function populateFilesAndFolderList() // 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; diff --git a/libraries/joomla/installer/adapters/language.php b/libraries/joomla/installer/adapters/language.php index 560653add5..f19c58c277 100644 --- a/libraries/joomla/installer/adapters/language.php +++ b/libraries/joomla/installer/adapters/language.php @@ -22,7 +22,6 @@ class JInstallerLanguage extends JAdapterInstance { /** * Core language pack flag - * @access private * @var boolean */ protected $_core = false; @@ -33,7 +32,6 @@ class JInstallerLanguage extends JAdapterInstance * the ability to install multiple distinct packs in one install. The * preferred method is to use a package to install multiple language packs. * - * @access public * @return boolean True on success * @since 11.1 */ @@ -137,7 +135,7 @@ protected function _install($cname, $basePath, $clientId, &$element) } } - // If the language directory does not exist, lets create it + // If the language directory does not exist, let's create it $created = false; if (!file_exists($this->parent->getPath('extension_site'))) { @@ -149,22 +147,24 @@ protected function _install($cname, $basePath, $clientId, &$element) } else { - // 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 or + // Update function available or + // Update tag detected if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || is_a($updateElement, 'JXMLElement')) { 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_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_site')))); } - else { // if the admin exists say that + else { + // If the admin exists say so. JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ABORT', JText::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_administrator')))); } return false; @@ -172,8 +172,8 @@ protected function _install($cname, $basePath, $clientId, &$element) } /* - * If we created the language directory and will want to remove it if we - * have to roll back the installation, lets add it to the installation + * If we created the language directory we will want to remove it if we + * have to roll back the installation, so let's add it to the installation * step stack */ if ($created) { @@ -216,7 +216,8 @@ protected function _install($cname, $basePath, $clientId, &$element) $row->set('name', $this->get('name')); $row->set('type', 'language'); $row->set('element', $this->get('tag')); - $row->set('folder', ''); // There is no folder for languages + // There is no folder for languages + $row->set('folder', ''); $row->set('enabled', 1); $row->set('protected', 0); $row->set('access', 0); @@ -339,11 +340,8 @@ public function update() // Get the language description and set it as message $this->parent->set('message', (string)$xml->description); - /** - * --------------------------------------------------------------------------------------------- - * Finalization and Cleanup Section - * --------------------------------------------------------------------------------------------- - */ + // Finalization and Cleanup Section + // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(Array('element'=>$this->get('tag'), @@ -409,13 +407,13 @@ public function update() */ public function uninstall($eid) { - // load up the extension details + // Load up the extension details $extension = JTable::getInstance('extension'); $extension->load($eid); - // grab a copy of the client details + // Grab a copy of the client details $client = JApplicationHelper::getClientInfo($extension->get('client_id')); - // check the element isn't blank to prevent nuking the languages directory...just in case + // Check the element isn't blank to prevent nuking the languages directory...just in case $element = $extension->get('element'); if (empty($element)) { @@ -423,14 +421,14 @@ public function uninstall($eid) return false; } - // verify that it's not the default language for that client + // Verify that it's not the default language for that client $params = JComponentHelper::getParams('com_languages'); if ($params->get($client->name)==$element) { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DEFAULT')); return false; } - // construct the path from the client, the language and the extension element name + // Construct the path from the client, the language and the extension element name $path = $client->path.DS.'language'.DS.$element; // Get the package manifest object and remove media @@ -440,10 +438,10 @@ public function uninstall($eid) $this->manifest = $this->parent->getManifest(); $this->parent->removeFiles($this->manifest->media); - // check it exists + // Check it exists if (!JFolder::exists($path)) { - // if the folder doesn't exist lets just nuke the row as well and presume the user killed it for us + // If the folder doesn't exist lets just nuke the row as well and presume the user killed it for us $extension->delete(); JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PATH_EMPTY')); return false; @@ -451,7 +449,7 @@ public function uninstall($eid) if (!JFolder::delete($path)) { - // if deleting failed we'll leave the extension entry in tact just in case + // If deleting failed we'll leave the extension entry in tact just in case JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DIRECTORY')); return false; } @@ -570,6 +568,7 @@ public function discover_install() /** * Refreshes the extension table cache + * * @return boolean result of operation, true if updated, false on failure * @since 11.1 */ @@ -584,6 +583,7 @@ public function refreshManifestCache() $this->parent->extension->name = $manifest_details['name']; if ($this->parent->extension->store()) { + return true; } else { diff --git a/libraries/joomla/installer/adapters/library.php b/libraries/joomla/installer/adapters/library.php index 785b4dbea2..36ed8a6e06 100644 --- a/libraries/joomla/installer/adapters/library.php +++ b/libraries/joomla/installer/adapters/library.php @@ -24,7 +24,6 @@ class JInstallerLibrary extends JAdapterInstance /** * Custom loadLanguage method * - * @access public * @param string $path the path where to find language files * @since 11.1 */ @@ -47,8 +46,7 @@ public function loadLanguage($path=null) /** * Custom install method - * - * @access public + * * @return boolean True on success * @since 11.1 */ @@ -57,11 +55,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 = JFilterInput::getInstance()->clean((string)$this->manifest->name, 'string'); @@ -74,16 +68,16 @@ public function install() $result = $db->loadResult(); if ($result) { - // already installed, can we upgrade? + // Already installed, can we upgrade? if ($this->parent->getOverwrite() || $this->parent->getUpgrade()) { - // we can upgrade, so uninstall the old one + // We can upgrade, so uninstall the old one $installer = new JInstaller(); // we don't want to compromise this instance! $installer->uninstall('library', $result); } else { - // abort the install, no upgrade possible + // Abort the install, no upgrade possible $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_LIB_INSTALL_ALREADY_INSTALLED')); return false; } @@ -110,13 +104,9 @@ public function install() $this->parent->setPath('extension_root', JPATH_PLATFORM.DS.implode(DS,explode('/',$group))); } - /** - * --------------------------------------------------------------------------------------------- - * Filesystem Processing Section - * --------------------------------------------------------------------------------------------- - */ + // Filesystem Processing Section - // If the plugin directory does not exist, lets create it + // If the plugin directory does not exist, let's create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { @@ -127,11 +117,10 @@ public function install() } } - /* - * If we created the plugin directory and will want to remove it if we - * have to roll back the installation, lets add it to the installation - * step stack - */ + // If we created the plugin directory and will want to remove it if we + // have to roll back the installation, lets add it to the installation + // step stack + if ($created) { $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } @@ -148,11 +137,7 @@ public function install() $this->parent->parseLanguages($this->manifest->languages); $this->parent->parseMedia($this->manifest->media); - /** - * --------------------------------------------------------------------------------------------- - * Extension Registration - * --------------------------------------------------------------------------------------------- - */ + // Extension Registration $row = JTable::getInstance('extension'); $row->name = $this->get('name'); $row->type = 'library'; @@ -172,11 +157,7 @@ public function install() return false; } - /** - * --------------------------------------------------------------------------------------------- - * Finalization and Cleanup Section - * --------------------------------------------------------------------------------------------- - */ + // Finalization and Cleanup Section // Lastly, we will copy the manifest file to its appropriate place. $manifest = Array(); @@ -193,21 +174,17 @@ public function install() /** * Custom update method - * @access public + * * @return boolean True on success * @since 11.1 */ public function update() { - // since this is just files, an update removes old files + // Since this is just files, an update removes old files // Get the extension manifest object $this->manifest = $this->parent->getManifest(); - /** - * --------------------------------------------------------------------------------------------- - * Manifest Document Setup Section - * --------------------------------------------------------------------------------------------- - */ + // Manifest Document Setup Section // Set the extensions name $name = (string)$this->manifest->name; @@ -220,18 +197,18 @@ public function update() $db->setQuery('SELECT extension_id FROM #__extensions WHERE type="library" AND element = "'. $element .'"'); $result = $db->loadResult(); if ($result) { - // already installed, which would make sense + // Already installed, which would make sense $installer->uninstall('library', $result); } - // now create the new files + // Now create the new files return $this->install(); } /** * Custom uninstall method * - * @access public * @param string $id The id of the library to uninstall + * * @return boolean True on success * @since 11.1 */ @@ -275,11 +252,10 @@ public function uninstall($id) return false; } - /* - * Check for a valid XML root tag. - * @todo: Remove backwards compatability in a future version - * Should be 'extension', but for backward compatability we will accept 'install'. - */ + // Check for a valid XML root tag. + // TODO: Remove backwards compatability in a future version + // Should be 'extension', but for backward compatability we will accept 'install'. + if ($xml->getName() != 'install' && $xml->getName() != 'extension') { JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LIB_UNINSTALL_INVALID_MANIFEST')); @@ -292,7 +268,7 @@ public function uninstall($id) } else { - // remove this row entry since its invalid + // Remove this row entry since its invalid $row->delete($row->extension_id); unset($row); JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_LIB_UNINSTALL_INVALID_NOTFOUND_MANIFEST')); @@ -323,7 +299,6 @@ public function uninstall($id) /** * Custom discover method * - * @access public * @return array(JExtension) list of extensions available * @since 11.1 */ @@ -350,8 +325,8 @@ public function discover() /** * Custom discover_install method * - * @access public - * @param int $id The id of the extension to install (from #__discoveredextensions) + * @param int $id The id of the extension to install + * * @return void * @since 11.1 */ diff --git a/libraries/joomla/installer/adapters/module.php b/libraries/joomla/installer/adapters/module.php index 5cecb988ce..6b414cf9db 100644 --- a/libraries/joomla/installer/adapters/module.php +++ b/libraries/joomla/installer/adapters/module.php @@ -94,11 +94,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 = (string)$this->manifest->name; @@ -114,11 +110,7 @@ public function install() $this->parent->set('message', ''); } - /** - * --------------------------------------------------------------------------------------------- - * Target Application Section - * --------------------------------------------------------------------------------------------- - */ + // Target Application Section // Get the target application if ($cname = (string)$this->manifest->attributes()->client) { // Attempt to map the client to a base path @@ -186,42 +178,40 @@ public function install() $id = $db->loadResult(); - /* - * If the module directory already exists, then we will assume that the - * module is already installed or another module is using that - * directory. - * Check that this is either an issue where its not overwriting or it is - * set to upgrade anyway - */ + + // If the module directory already exists, then we will assume that the + // module is already installed or another module is using that + // directory. + // Check that this is either an issue where its not overwriting or it is + // set to upgrade anyway + if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade())) { - // 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 or + // Update function available or + // Update tag detected if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || is_a($updateElement, 'JXMLElement')) { - // force these one + // Force this one $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); - if ($id) { // if there is a matching extension mark this as an update; semantics really + if ($id) { + // If there is a matching extension mark this as an update; semantics really $this->route = 'Update'; } } else if (!$this->parent->getOverwrite()) { - // overwrite is set - // we didn't have overwrite set, find an udpate function or find an update tag so lets call it safe + // Overwrite is set + // We didn't have overwrite set, find an udpate function or find an update tag so lets call it safe $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_MOD_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_'.$this->route), $this->parent->getPath('extension_root'))); 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) $this->scriptElement = $this->manifest->scriptfile; $manifestScript = (string)$this->manifest->scriptfile; @@ -230,7 +220,7 @@ public function install() $manifestScriptFile = $this->parent->getPath('source').DS.$manifestScript; if (is_file($manifestScriptFile)) { - // load the file + // Load the file include_once $manifestScriptFile; } @@ -238,7 +228,7 @@ public function install() $classname = $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 $this->set('manifest_script', $manifestScript); @@ -259,14 +249,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(); - /** - * --------------------------------------------------------------------------------------------- - * Filesystem Processing Section - * --------------------------------------------------------------------------------------------- - */ + // Filesystem Processing Section // If the module directory does not exist, lets create it $created = false; @@ -279,11 +266,10 @@ public function install() } } - /* - * 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 - */ + // 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 + if ($created) { $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } @@ -303,17 +289,13 @@ public function install() // Parse deprecated tags $this->parent->parseFiles($this->manifest->images, -1); - /** - * --------------------------------------------------------------------------------------------- - * Database Processing Section - * --------------------------------------------------------------------------------------------- - */ + // Database Processing Section $row = JTable::getInstance('extension'); // Was there a module already installed with the same name? if ($id) { - // load the entry and update the manifest_cache + // Load the entry and update the manifest_cache $row->load($id); $row->name = $this->get('name'); // update name $row->manifest_cache = $this->parent->generateManifestCache(); // update manifest @@ -344,7 +326,7 @@ public function install() return false; } - // set the insert id + // Set the insert id $row->extension_id = $db->insertid(); // Since we have created a module item, we add it to the installation step stack @@ -363,13 +345,13 @@ public function install() $module->store(); } - /* - * Let's run the queries for the module - * If Joomla 1.5 compatible, with discreet sql files - execute appropriate - * file for utf-8 support or non-utf-8 support - */ - // try for Joomla 1.5 type queries - // second argument is the utf compatible version attribute + + // Let's run the queries for the module + // If Joomla 1.5 compatible, with discreet sql files - execute appropriate + // file for utf-8 support or non-utf-8 support + + // Try for Joomla 1.5 type queries + // Second argument is the utf compatible version attribute if (strtolower($this->route) == 'install') { $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql); @@ -409,14 +391,11 @@ public function install() } } - $msg .= ob_get_contents(); // append messages + // Append messages + $msg .= ob_get_contents(); ob_end_clean(); - /** - * --------------------------------------------------------------------------------------------- - * Finalization and Cleanup Section - * --------------------------------------------------------------------------------------------- - */ + // Finalization and Cleanup Section // Lastly, we will copy the manifest file to its appropriate place. if (!$this->parent->copyManifest(-1)) { @@ -434,7 +413,8 @@ public function install() $this->parent->manifestClass->postflight($this->route, $this); } - $msg .= ob_get_contents(); // append messages + // Append messages + $msg .= ob_get_contents(); ob_end_clean(); if ($msg != '') { @@ -453,20 +433,20 @@ public function install() */ function update() { - // set the overwrite setting + // Set the overwrite setting $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); - // set the route for the install + // Set the route for the install $this->route = 'Update'; - // go to install which handles updates properly + // Go to install which handles updates properly return $this->install(); } /** * Custom discover method * - * @return array(JExtension) list of extensions available + * @return array JExtension list of extensions available * @since 11.1 */ public function discover() @@ -507,7 +487,7 @@ public function discover() /** * Custom discover_install method * - * @param int $id The id of the extension to install (from #__discoveredextensions) + * @param int $id The id of the extension to install * * @return void * @since 11.1 @@ -616,14 +596,14 @@ public function uninstall($id) $this->parent->setPath('source', $this->parent->getPath('extension_root')); // Get the package manifest objecct - // We do findManifest to avoid problem when uninstalling a list of extension: getManifest cache its manifest file + // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file $this->parent->findManifest(); $this->manifest = $this->parent->getManifest(); // Attempt to load the language file; might have uninstall strings $this->loadLanguage(($row->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/'.$element); - // If there is an manifest class file, lets load it + // If there is an manifest class file, let's load it $this->scriptElement = $this->manifest->scriptfile; $manifestScript = (string)$this->manifest->scriptfile; @@ -631,7 +611,7 @@ public function uninstall($id) $manifestScriptFile = $this->parent->getPath('extension_root').DS.$manifestScript; if (is_file($manifestScriptFile)) { - // load the file + // Load the file include_once $manifestScriptFile; } @@ -639,9 +619,9 @@ public function uninstall($id) $classname = $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 } @@ -650,7 +630,7 @@ public function uninstall($id) ob_start(); ob_implicit_flush(false); - // run uninstall if possible + // Run uninstall if possible if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'uninstall')) { $this->parent->manifestClass->uninstall($this); } @@ -671,8 +651,8 @@ public function uninstall($id) * If Joomla 1.5 compatible, with discreet sql files - execute appropriate * file for utf-8 support or non-utf support */ - // try for Joomla 1.5 type queries - // second argument is the utf compatible version attribute + // Try for Joomla 1.5 type queries + // Second argument is the utf compatible version attribute $utfresult = $this->parent->parseSQLFiles($this->manifest->uninstall->sql); if ($utfresult === false) { @@ -691,7 +671,7 @@ public function uninstall($id) $this->parent->removeFiles($this->manifest->media); $this->parent->removeFiles($this->manifest->languages, $row->client_id); - // Lets delete all the module copies for the type we are uninstalling + // Let's delete all the module copies for the type we are uninstalling $query = 'SELECT `id`' . ' FROM `#__modules`' . ' WHERE module = '.$db->Quote($row->element) . @@ -753,7 +733,8 @@ public function uninstall($id) try { - $db->Query(); // clean up any other ones that might exist as well + // clean up any other ones that might exist as well + $db->Query(); } catch(JException $e) { diff --git a/libraries/joomla/installer/adapters/package.php b/libraries/joomla/installer/adapters/package.php index 8bec635eab..40900351ed 100644 --- a/libraries/joomla/installer/adapters/package.php +++ b/libraries/joomla/installer/adapters/package.php @@ -23,7 +23,9 @@ */ class JInstallerPackage extends JAdapterInstance { - /** @var string method of system */ + /** + * @var string method of system + */ protected $route = 'install'; public function loadLanguage($path) @@ -40,20 +42,15 @@ public function loadLanguage($path) /** * Custom install method * - * @access public * @return boolean True on success * @since 11.1 */ - function install() + 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 $filter = JFilterInput::getInstance(); @@ -87,12 +84,7 @@ function install() return false; } - /** - * --------------------------------------------------------------------------------------------- - * Filesystem Processing Section - * --------------------------------------------------------------------------------------------- - */ - + // Filesystem Processing Section if ($folder = $files->attributes()->folder) { @@ -112,12 +104,13 @@ function install() jimport('joomla.installer.helper'); if (is_dir($file)) { - // if its actually a directory then fill it up + // If it's actually a directory then fill it up $package = Array(); $package['dir'] = $file; $package['type'] = JInstallerHelper::detectType($file); } - else { // if its an archive + else { + // If it's an archive $package = JInstallerHelper::unpack($file); } $tmpInstaller = new JInstaller(); @@ -137,11 +130,8 @@ function install() // Parse optional tags $this->parent->parseLanguages($this->manifest->languages); - /** - * --------------------------------------------------------------------------------------------- - * Extension Registration - * --------------------------------------------------------------------------------------------- - */ + // Extension Registration + $row = JTable::getInstance('extension'); $eid = $row->find(Array('element'=>strtolower($this->get('element')), 'type'=>'package')); @@ -151,15 +141,17 @@ function install() $row->name = $this->get('name'); $row->type = 'package'; $row->element = $this->get('element'); - $row->folder = ''; // There is no folder for modules + // There is no folder for modules + $row->folder = ''; $row->enabled = 1; $row->protected = 0; $row->access = 1; $row->client_id = 0; - $row->custom_data = ''; // custom data + // custom data + $row->custom_data = ''; $row->params = $this->parent->getParams(); } - // update the manifest cache for the entry + // Update the manifest cache for the entry $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) @@ -169,11 +161,7 @@ function install() return false; } - /** - * --------------------------------------------------------------------------------------------- - * Finalization and Cleanup Section - * --------------------------------------------------------------------------------------------- - */ + // Finalization and Cleanup Section // Lastly, we will copy the manifest file to its appropriate place. $manifest = Array(); @@ -202,8 +190,8 @@ public function update() { /** * Custom uninstall method * - * @access public * @param int $id The id of the package to uninstall + * * @return boolean True on success * @since 11.1 */ @@ -282,7 +270,7 @@ function uninstall($id) JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_PACK_UNINSTALL_MANIFEST_NOT_REMOVED')); } - // return the result up the line + // Return the result up the line return $retval; } @@ -307,14 +295,14 @@ private function _getExtensionID($type, $id, $client, $group) case 'library': case 'package': case 'component': - // components, packages and libraries don't have a folder or client - // included for completeness + // Components, packages and libraries don't have a folder or client. + // Included for completeness. break; case 'language': case 'module': case 'template': - // languages, modules and templates have a client but not a folder + // Languages, modules and templates have a client but not a folder $client = JApplicationHelper::getClientInfo($client, true); $query->where('client_id = '. (int)$client->id); break; @@ -323,8 +311,8 @@ private function _getExtensionID($type, $id, $client, $group) $db->setQuery($query); $result = $db->loadResult(); - // note: for templates, libraries and packages their unique name is their key - // this means they come out the same way they came in + // Note: For templates, libraries and packages their unique name is their key. + // This means they come out the same way they came in. return $result; } diff --git a/libraries/joomla/installer/adapters/plugin.php b/libraries/joomla/installer/adapters/plugin.php index 10fe3afffc..97f94241c7 100644 --- a/libraries/joomla/installer/adapters/plugin.php +++ b/libraries/joomla/installer/adapters/plugin.php @@ -20,7 +20,9 @@ */ class JInstallerPlugin extends JAdapterInstance { - /** @var string install function routing */ + /** + * @var string install function routing + * */ var $route = 'install'; protected $manifest = null; @@ -32,7 +34,6 @@ class JInstallerPlugin extends JAdapterInstance /** * Custom loadLanguage method * - * @access public * @param string $path the path where to find language files * @since 11.1 */ @@ -73,13 +74,12 @@ public function loadLanguage($path=null) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false); - } -} + } + } } /** * Custom install method * - * @access public * @return boolean True on success * @since 11.1 */ @@ -93,13 +93,9 @@ public function install() $xml = $this->manifest; - /** - * --------------------------------------------------------------------------------------------- - * Manifest Document Setup Section - * --------------------------------------------------------------------------------------------- - */ + // Manifest Document Setup Section - // Set the extensions name + // Set the extension name $name = (string)$xml->name; $name = JFilterInput::getInstance()->clean($name, 'string'); $this->set('name', $name); @@ -142,9 +138,8 @@ public function install() } - /* - * Check if we should enable overwrite settings - */ + // Check if we should enable overwrite settings + // Check to see if a plugin by the same name is already installed $query = 'SELECT `extension_id`' . ' FROM `#__extensions`' . @@ -162,59 +157,58 @@ public function install() } $id = $db->loadResult(); - // if its on the fs... + // If it's on the fs... if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade())) { $updateElement = $xml->update; - // upgrade manually set - // update function available - // update tag detected + // Upgrade manually set or + // Update function available or + // Update tag detected if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || is_a($updateElement, 'JXMLElement')) { - // force these one + // Force this one $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); - if ($id) { // if there is a matching extension mark this as an update; semantics really + if ($id) { + // If there is a matching extension mark this as an update; semantics really $this->route = 'update'; } } else if (!$this->parent->getOverwrite()) { - // overwrite is set - // we didn't have overwrite set, find an udpate function or find an update tag so lets call it safe + // Overwrite is set + // We didn't have overwrite set, find an udpate function or find an update tag so lets call it safe $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_'.$this->route), $this->parent->getPath('extension_root'))); return false; } } - /** - * --------------------------------------------------------------------------------------------- - * Installer Trigger Loading - * --------------------------------------------------------------------------------------------- - */ - // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet) + // Installer Trigger Loading + + // If there is an manifest class file, let's load it; we'll copy it later (don't have destination yet). + if ((string)$xml->scriptfile) { $manifestScript = (string)$xml->scriptfile; $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 = 'plg'.$group.$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); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'preflight')) @@ -229,11 +223,7 @@ public function install() $msg = ob_get_contents(); // create msg object; first use here ob_end_clean(); - /** - * --------------------------------------------------------------------------------------------- - * Filesystem Processing Section - * --------------------------------------------------------------------------------------------- - */ + // Filesystem Processing Section // If the plugin directory does not exist, lets create it $created = false; @@ -246,13 +236,13 @@ public function install() } } - // if we're updating at this point when there is always going to be an extension_root find the old xml files + // If we're updating at this point when there is always going to be an extension_root find the old xml files if($this->route == 'update') { // Hunt for the original XML file $old_manifest = null; $tmpInstaller = new JInstaller(); // create a new installer because findManifest sets stuff; side effects! - // look in the extension root + // Look in the extension root $tmpInstaller->setPath('source', $this->parent->getPath('extension_root')); if ($tmpInstaller->findManifest()) { @@ -261,11 +251,10 @@ public function install() } } - /* - * If we created the plugin directory and will want to remove it if we - * have to roll back the installation, lets add it to the installation - * step stack - */ + // If we created the plugin 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_root'))); } @@ -299,13 +288,10 @@ public function install() } } - /** - * --------------------------------------------------------------------------------------------- - * Database Processing Section - * --------------------------------------------------------------------------------------------- - */ + // Database Processing Section + $row = JTable::getInstance('extension'); - // Was there a plugin already installed with the same name? + // Was there a plugin with the same name already installed? if ($id) { if (!$this->parent->getOverwrite()) @@ -332,8 +318,10 @@ public function install() $row->access = 1; $row->client_id = 0; $row->params = $this->parent->getParams(); - $row->custom_data = ''; // custom data - $row->system_data = ''; // system data + // Custom data + $row->custom_data = ''; + // System data + $row->system_data = ''; $row->manifest_cache = $this->parent->generateManifestCache(); // Editor plugins are published by default @@ -354,13 +342,12 @@ public function install() $id = $row->extension_id; } - /* - * Let's run the queries for the module - * If Joomla 1.5 compatible, with discreet sql files - execute appropriate - * file for utf-8 support or non-utf-8 support - */ - // try for Joomla 1.5 type queries - // second argument is the utf compatible version attribute + // Let's run the queries for the module + // If Joomla 1.5 compatible, with discreet sql files - execute appropriate + // file for utf-8 support or non-utf-8 support + + // Try for Joomla 1.5 type queries + // Second argument is the utf compatible version attribute if(strtolower($this->route) == 'install') { $utfresult = $this->parent->parseSQLFiles($this->manifest->install->sql); if ($utfresult === false) @@ -399,14 +386,11 @@ public function install() return false; } } - $msg .= ob_get_contents(); // append messages + // Append messages + $msg .= ob_get_contents(); ob_end_clean(); - /** - * --------------------------------------------------------------------------------------------- - * Finalization and Cleanup Section - * --------------------------------------------------------------------------------------------- - */ + // Finalization and Cleanup Section // Lastly, we will copy the manifest file to its appropriate place. if (!$this->parent->copyManifest(-1)) @@ -422,7 +406,8 @@ public function install() { $this->parent->manifestClass->postflight($this->route, $this); } - $msg .= ob_get_contents(); // append messages + // Append messages + $msg .= ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension_message', $msg); @@ -432,28 +417,25 @@ public function install() /** * Custom update method - * - * @access public + * * @return boolean True on success * @since 11.1 */ function update() { - // set the overwrite setting + // Set the overwrite setting $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); - // set the route for the install + // Set the route for the install $this->route = 'update'; - // go to install which handles updates properly + // Go to install which handles updates properly return $this->install(); } /** * Custom uninstall method - * - * @access public - * @param int $cid The id of the plugin to uninstall - * @param int $clientId The id of the client (unused) + * @param int $id The id of the plugin to uninstall + * @return boolean True on success * @since 11.1 */ @@ -464,7 +446,7 @@ public function uninstall($id) $retval = true; $db = $this->parent->getDbo(); - // First order of business will be to load the module object table from the database. + // First order of business will be to load the plugin object table from the database. // This should give us the necessary information to proceed. $row = JTable::getInstance('extension'); if (!$row->load((int) $id)) @@ -498,9 +480,9 @@ public function uninstall($id) $this->parent->setPath('extension_root', JPATH_PLUGINS.DS.$row->folder); } - // Because plugins don't have their own folders we cannot use the standard method of finding an installation manifest - // Since 1.6 they do, however until we move to 1.7 and remove 1.6 legacy we still need to use this method - // when we get there it'll be something like "$this->parent->findManifest();$manifest = $this->parent->getManifest();" + // Because 1.5 plugins don't have their own folders we cannot use the standard method of finding an installation manifest + // Since 1.6 they do, however until we move to 1.7 and remove 1.6 legacy we still need to use this method. + // When we get there it'll be something like "$this->parent->findManifest();$manifest = $this->parent->getManifest();" $manifestFile = $this->parent->getPath('extension_root').DS.$row->element.'.xml'; if ( ! file_exists($manifestFile)) @@ -535,33 +517,30 @@ public function uninstall($id) $this->parent->setPath('source', JPATH_PLUGINS .'/'.$row->folder.'/'.$row->element); $this->loadLanguage(JPATH_PLUGINS .'/'.$row->folder.'/'.$row->element); - /** - * --------------------------------------------------------------------------------------------- - * Installer Trigger Loading - * --------------------------------------------------------------------------------------------- - */ - // If there is an manifest class file, lets load it; we'll copy it later (don't have dest yet) + // Installer Trigger Loading + + // If there is an manifest class file, let's load it; we'll copy it later (don't have dest yet) $manifestScript = (string)$xml->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 = 'plg'.$row->folder.$row->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); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'preflight')) @@ -573,16 +552,16 @@ public function uninstall($id) return false; } } - $msg = ob_get_contents(); // create msg object; first use here + // Create msg object; first use here + $msg = ob_get_contents(); ob_end_clean(); - /* - * Let's run the queries for the module - * If Joomla 1.5 compatible, with discreet sql files - execute appropriate - * file for utf-8 support or non-utf-8 support - */ - // try for Joomla 1.5 type queries - // second argument is the utf compatible version attribute + // Let's run the queries for the module + // If Joomla 1.5 compatible, with discreet sql files - execute appropriate + // file for utf-8 support or non-utf-8 support + + // Try for Joomla 1.5 type queries + // Second argument is the utf compatible version attribute $utfresult = $this->parent->parseSQLFiles($xml->{strtolower($this->route)}->sql); if ($utfresult === false) { @@ -598,7 +577,8 @@ public function uninstall($id) { $this->parent->manifestClass->uninstall($this); } - $msg = ob_get_contents(); // append messages + // Append messages + $msg = ob_get_contents(); ob_end_clean(); @@ -617,7 +597,7 @@ public function uninstall($id) $db->setQuery($query); $db->Query(); - // Now we will no longer need the plugin object, so lets delete it + // Now we will no longer need the plugin object, so let's delete it $row->delete($row->extension_id); unset ($row); @@ -636,7 +616,6 @@ public function uninstall($id) /** * Custom discover method * - * @access public * @return array(JExtension) list of extensions available * @since 11.1 */ @@ -652,7 +631,8 @@ function discover() { $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE.'/plugins/'.$folder.'/'.$file); $file = JFile::stripExt($file); - if ($file == 'example') continue; // ignore example plugins + // Ignore example plugins + if ($file == 'example') continue; $extension = JTable::getInstance('extension'); $extension->set('type', 'plugin'); $extension->set('client_id', 0); @@ -690,16 +670,16 @@ function discover() /** * Custom discover_install method * - * @access public - * @param int $id The id of the extension to install (from #__discoveredextensions) - * @return void + * @param int $id The id of the extension to install + * + * @return mixed * @since 11.1 */ - function discover_install() + public function discover_install() { // Plugins use the extensions table as their primary store // Similar to modules and templates, rather easy - // If its not in the extensions table we just add it + // If it's not in the extensions table we just add it $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); if (is_dir($client->path . DS . 'plugins'. DS . $this->parent->extension->folder . DS . $this->parent->extension->element)) { $manifestPath = $client->path . DS . 'plugins'. DS . $this->parent->extension->folder . DS . $this->parent->extension->element . DS . $this->parent->extension->element . '.xml'; @@ -741,7 +721,7 @@ public function refreshManifestCache() { // Plugins use the extensions table as their primary store // Similar to modules and templates, rather easy - // If its not in the extensions table we just add it + // If it's not in the extensions table we just add it $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); $manifestPath = $client->path . '/plugins/'. $this->parent->extension->folder . '/' . $this->parent->extension->element . '/' . $this->parent->extension->element . '.xml'; $this->parent->manifest = $this->parent->isManifest($manifestPath); diff --git a/libraries/joomla/installer/adapters/template.php b/libraries/joomla/installer/adapters/template.php index 8dfaf1177d..00499b68ce 100644 --- a/libraries/joomla/installer/adapters/template.php +++ b/libraries/joomla/installer/adapters/template.php @@ -89,7 +89,7 @@ public function install() $clientId = 0; } - // Set the extensions name + // Set the extension's name $name = JFilterInput::getInstance()->clean((string)$xml->name, 'cmd'); $element = strtolower(str_replace(" ", "_", $name)); @@ -104,16 +104,16 @@ public function install() $this->parent->setPath('extension_root', $basePath.DS.'templates'.DS.$element); - // if its on the fs... + // if it's on the fs... if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade())) { $updateElement = $xml->update; - // upgrade manually set - // update function available - // update tag detected + // Upgrade manually set or + // Update function available or + // Update tag detected if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'update')) || is_a($updateElement, 'JXMLElement')) { - // force these one + // Force this one $this->parent->setOverwrite(true); $this->parent->setUpgrade(true); if ($id) { // if there is a matching extension mark this as an update; semantics really @@ -122,8 +122,8 @@ public function install() } else if (!$this->parent->getOverwrite()) { - // overwrite is set - // we didn't have overwrite set, find an udpate function or find an update tag so lets call it safe + // Overwrite is not set + // If we didn't have overwrite set, find an udpate function or find an update tag so let's call it safe $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PLG_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_'.$this->route), $this->parent->getPath('extension_root'))); return false; } @@ -138,7 +138,7 @@ public function install() return false; } - // If the template directory does not exist, lets create it + // If the template directory does not exist, let's create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { if (!$created = JFolder::create($this->parent->getPath('extension_root'))) { @@ -149,7 +149,7 @@ public function install() } // If we created the template directory and will want to remove it if we have to roll back - // the installation, lets add it to the installation step stack + // the installation, let's add it to the installation step stack if ($created) { $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root'))); } @@ -191,11 +191,8 @@ public function install() return false; } - /** - * --------------------------------------------------------------------------------------------- - * Extension Registration - * --------------------------------------------------------------------------------------------- - */ + // Extension Registration + $row = JTable::getInstance('extension'); if($this->route == 'update' && $id) @@ -206,7 +203,8 @@ public function install() { $row->type = 'template'; $row->element = $this->get('element'); - $row->folder = ''; // There is no folder for templates + // There is no folder for templates + $row->folder = ''; $row->enabled = 1; $row->protected = 0; $row->access = 1; @@ -237,7 +235,8 @@ public function install() $lang->setDebug($debug); $query->set('params='.$db->Quote($row->params)); $db->setQuery($query); - $db->query(); // There is a chance this could fail but we don't care... + // There is a chance this could fail but we don't care... + $db->query(); } return $row->get('extension_id'); @@ -267,7 +266,7 @@ public function uninstall($id) // Initialise variables. $retval = true; - // First order of business will be to load the module object table from the database. + // First order of business will be to load the template object table from the database. // This should give us the necessary information to proceed. $row = JTable::getInstance('extension'); @@ -316,11 +315,11 @@ public function uninstall($id) $this->parent->setPath('extension_root', $client->path.DS.'templates'.DS.strtolower($name)); $this->parent->setPath('source', $this->parent->getPath('extension_root')); - // We do findManifest to avoid problem when uninstalling a list of extension: getManifest cache its manifest file + // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file $this->parent->findManifest(); $manifest = $this->parent->getManifest(); if (!($manifest instanceof JXMLElement)) { - // kill the extension entry + // Kill the extension entry $row->delete($row->extension_id); unset($row); // Make sure we delete the folders @@ -343,7 +342,7 @@ public function uninstall($id) $retval = false; } - //Set menu that assigned to the template back to default template + // Set menu that assigned to the template back to default template $query = 'UPDATE #__menu INNER JOIN #__template_styles'. ' ON #__template_styles.id = #__menu.template_style_id'. ' SET #__menu.template_style_id = 0'. @@ -381,7 +380,7 @@ function discover() { if ($template == 'system') { continue; - // ignore special system template + // Ignore special system template } $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE."/templates/$template/templateDetails.xml"); $extension = JTable::getInstance('extension'); @@ -398,7 +397,7 @@ function discover() { if ($template == 'system') { continue; - // ignore special system template + // Ignore special system template } $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_ADMINISTRATOR."/templates/$template/templateDetails.xml"); @@ -416,7 +415,11 @@ function discover() } /** - * Perform an install from a discovered extension + * Discover_install + * Perform an install for a discovered extension + * + * @return boolean + * @since 11.1 */ function discover_install() { @@ -480,7 +483,7 @@ function discover_install() */ public function refreshManifestCache() { - // Need to find to find where the XML file is since we don't store this normally + // Need to find to find where the XML file is since we don't store this normally. $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id); $manifestPath = $client->path.DS.'templates'. DS.$this->parent->extension->element.DS.'templateDetails.xml'; $this->parent->manifest = $this->parent->isManifest($manifestPath); @@ -498,4 +501,4 @@ public function refreshManifestCache() return false; } } -} +} \ No newline at end of file diff --git a/libraries/joomla/installer/extension.php b/libraries/joomla/installer/extension.php index 44750b4142..f94e501ac4 100644 --- a/libraries/joomla/installer/extension.php +++ b/libraries/joomla/installer/extension.php @@ -18,22 +18,40 @@ */ class JExtension extends JObject { - /** @var string $filename Filename of the extension */ + /** + * @var string $filename Filename of the extension + */ var $filename = ''; - /** @var string $type Type of the extension */ + /** + * @var string $type Type of the extension + */ var $type = ''; - /** @var string $id Unique Identifier for the extension */ + /** + * @var string $id Unique Identifier for the extension + * */ var $id = ''; - /** @var boolean $published The status of the extension */ - var $published = false; // published status - /** @var string $client String representation of client. Valid for modules, templates and languages */ - var $client = 'site'; // valid for modules, templates and languages; set by default - /** @var string $group The group name of the plugin. Not used for other known extension types */ - var $group = ''; // valid for plugins - /** @var Object $manifest_cache An object representation of the manifest file */ - var $manifest_cache = null; // manifest cache; stored metadata - /** @var Object $params An object representation of the extension params */ - var $params = null; // extension params + /** + * @var boolean $published The status of the extension + * */ + var $published = false; + /** + * @var string $client String representation of client. Valid for modules, templates and languages. + * set by default to site + */ + var $client = 'site'; + /** + * @var string $group The group name of the plugin. Not used for other known extension types (only plugins) + */ + var $group = ''; + /** + * @var Object $manifest_cache An object representation of the manifest file + * Stored metadata + */ + var $manifest_cache = null; + /** + * @var Object $params An object representation of the extension params + */ + var $params = null; /** * Constructor @@ -49,7 +67,7 @@ function __construct(JXMLElement $element = null) switch($this->type) { case 'component': - // by default a component doesn't have anything + // By default a component doesn't have anything break; case 'module': @@ -69,8 +87,8 @@ function __construct(JXMLElement $element = null) break; default: - // catch all - // get and set client and group if we don't recognise the extension + // Catch all + // Get and set client and group if we don't recognise the extension if ($client = (string)$element->attributes()->client) { $this->client_id = JApplicationHelper::getClientInfo($this->client, 1); diff --git a/libraries/joomla/installer/helper.php b/libraries/joomla/installer/helper.php index 393eb5625e..c74553139e 100644 --- a/libraries/joomla/installer/helper.php +++ b/libraries/joomla/installer/helper.php @@ -30,6 +30,7 @@ abstract class JInstallerHelper * @static * @param string URL of file to download * @param string Download target filename [optional] + * * @return mixed Path to downloaded package or boolean false on failure * @since 11.1 */ @@ -92,7 +93,7 @@ public static function downloadPackage($url, $target = false) // Close file pointer resource fclose($inputHandle); - // restore error tracking to what it was before + // Restore error tracking to what it was before ini_set('track_errors',$track_errors); // Return the name of the downloaded package @@ -105,6 +106,7 @@ public static function downloadPackage($url, $target = false) * * @static * @param string $p_filename The uploaded package filename or install directory + * * @return Array Two elements - extractdir and packagefile * @since 11.1 */ @@ -120,7 +122,7 @@ public static function unpack($p_filename) $extractdir = JPath::clean(dirname($p_filename).DS.$tmpdir); $archivename = JPath::clean($archivename); - // do the unpacking of the archive + // Do the unpacking of the archive $result = JArchive::extract($archivename, $extractdir); if ($result === false) { @@ -129,7 +131,7 @@ public static function unpack($p_filename) /* - * Lets set the extraction directory and package file in the result array so we can + * Let's set the extraction directory and package file in the result array so we can * cleanup everything properly later on. */ $retval['extractdir'] = $extractdir; @@ -175,6 +177,7 @@ public static function unpack($p_filename) * * @static * @param string $p_dir Path to package directory + * * @return mixed Extension type string or boolean false on fail * @since 11.1 */ @@ -219,6 +222,7 @@ public static function detectType($p_dir) * * @static * @param string $url URL to get name from + * * @return mixed String filename or boolean false if failed * @since 11.1 */ @@ -238,6 +242,7 @@ public static function getFilenameFromURL($url) * @static * @param string $package Path to the uploaded package file * @param string $resultdir Path to the unpacked extension + * * @return boolean True on success * @since 11.1 */ @@ -262,9 +267,12 @@ public static function cleanupInstall($package, $resultdir) } /** + * Splitsql + * * Splits contents of a sql file into array of discreet queries * queries need to be delimited with end of statement marker ';' * @param string + * * @return array */ public static function splitSql($sql) diff --git a/libraries/joomla/installer/installer.php b/libraries/joomla/installer/installer.php index f7bf8aa81c..2fa23c7e98 100644 --- a/libraries/joomla/installer/installer.php +++ b/libraries/joomla/installer/installer.php @@ -89,7 +89,6 @@ class JInstaller extends JAdapter /** * Constructor * - * @access protected */ public function __construct() { @@ -101,6 +100,7 @@ public function __construct() * if it doesn't already exist. * * @static + * * @return object An installer object * @since 11.1 */ @@ -116,8 +116,7 @@ public static function getInstance() /** * Get the allow overwrite switch - * - * @access public + * * @return boolean Allow overwrite switch * @since 11.1 */ @@ -129,8 +128,8 @@ public function getOverwrite() /** * Set the allow overwrite switch * - * @access public * @param boolean $state Overwrite switch state + * * @return boolean Previous value * @since 11.1 */ @@ -149,7 +148,6 @@ public function setOverwrite($state=false) /** * Get the redirect location * - * @access public * @return string Redirect location (or null) * @since 11.1 */ @@ -161,7 +159,6 @@ public function getRedirectURL() /** * Set the redirct location * - * @access public * @param string New redirect location * @since 11.1 */ @@ -172,11 +169,10 @@ public function setRedirectURL($newurl) { /** * Get the allow overwrite switch * - * @access public * @return boolean Allow overwrite switch * @since 11.1 */ - function getUpgrade() + public function getUpgrade() { return $this->_upgrade; } @@ -184,12 +180,11 @@ function getUpgrade() /** * Set the allow overwrite switch * - * @access public * @param boolean $state Overwrite switch state * @return boolean Previous value * @since 11.1 */ - function setUpgrade($state=false) + public function setUpgrade($state=false) { $tmp = $this->_upgrade; if ($state) { @@ -204,7 +199,6 @@ function setUpgrade($state=false) /** * Get the installation manifest object * - * @access public * @return object Manifest object * @since 11.1 */ @@ -219,9 +213,9 @@ public function getManifest() /** * Get an installer path by name * - * @access public * @param string $name Path name * @param string $default Default value + * * @return string Path * @since 11.1 */ @@ -233,9 +227,9 @@ public function getPath($name, $default=null) /** * Sets an installer path by name * - * @access public * @param string $name Path name * @param string $value Path + * * @return void * @since 11.1 */ @@ -247,9 +241,9 @@ public function setPath($name, $value) /** * Pushes a step onto the installer stack for rolling back steps * - * @access public * @param array $step Installer step * @return void + * * @since 11.1 */ public function pushStep($step) @@ -260,9 +254,9 @@ public function pushStep($step) /** * Installation abort method * - * @access public * @param string $msg Abort message from the installer * @param string $type Package type if defined + * * @return boolean True if successful * @since 11.1 */ @@ -282,17 +276,17 @@ public function abort($msg=null, $type=null) switch ($step['type']) { case 'file' : - // remove the file + // Remove the file $stepval = JFile::delete($step['path']); break; case 'folder' : - // remove the folder + // Remove the folder $stepval = JFolder::delete($step['path']); break; case 'query' : - // placeholder in case this is necessary in the future + // Placeholder in case this is necessary in the future // $stepval is always false because if this step was called it invariably failed $stepval = false; break; @@ -343,15 +337,13 @@ public function abort($msg=null, $type=null) return $retval; } - // ----------------------- // Adapter functions - // ----------------------- /** * Package installation method * - * @access public * @param string $path Path to package source folder + * * @return boolean True if successful * @since 11.1 */ @@ -405,12 +397,11 @@ public function install($path=null) /* * Discovered package installation method * - * @access public * @param int $eid Extension ID * @return boolean True if successful * @since 11.1 */ - function discover_install($eid=null) + public function discover_install($eid=null) { if ($eid) { @@ -474,10 +465,9 @@ function discover_install($eid=null) * Extension discover method * Asks each adapter to find extensions * - * @access public * @return Array JExtension */ - function discover() + public function discover() { $this->loadAllAdapters(); $results = Array(); @@ -501,8 +491,8 @@ function discover() /** * Package update method * - * @access public * @param string $path Path to package source folder + * * @return boolean True if successful * @since 11.1 */ @@ -553,10 +543,10 @@ public function update($path=null) /** * Package uninstallation method * - * @access public * @param string $type Package type * @param mixed $identifier Package identifier for adapter * @param int $cid Application ID; deprecated in 1.6 + * * @return boolean True if successful * @since 11.1 */ @@ -565,7 +555,7 @@ public function uninstall($type, $identifier, $cid=0) if (!isset($this->_adapters[$type]) || !is_object($this->_adapters[$type])) { if (!$this->setAdapter($type)) { - return false; // we failed to get the right adapter + return false; // We failed to get the right adapter } } if (is_object($this->_adapters[$type])) @@ -588,6 +578,7 @@ public function uninstall($type, $identifier, $cid=0) * Refreshes the manifest cache stored in #__extensions * * @param int $eid Extension ID + * * @return mixed void on success | false on error @todo missing return value ? */ function refreshManifestCache($eid) @@ -640,15 +631,12 @@ function refreshManifestCache($eid) } } - // ----------------------- // Utility functions - // ----------------------- /** * Prepare for installation: this method sets the installation directory, finds - * and checks the installation file and verifies the installation type - * - * @access public + * and checks the installation file and verifies the installation type. + * * @return boolean True on success * @since 1.0 */ @@ -674,11 +662,11 @@ public function setupInstall() } /** - * Backward compatible Method to parse through a queries element of the + * Backward compatible method to parse through a queries element of the * installation manifest file and take appropriate action. * - * @access public * @param JXMLElement $element The xml node to process + * * @return mixed Number of queries processed or False on error * @since 11.1 */ @@ -717,8 +705,8 @@ public function parseQueries($element) /** * Method to extract the name of a discreet installation sql file from the installation manifest file. * - * @access public * @param object $element The xml node to process + * * @return mixed Number of queries processed or False on error * @since 11.1 */ @@ -799,6 +787,7 @@ public function parseSQLFiles($element) * Set the schema version for an extension by looking at its latest update * @param JXMLElement $schema Schema Tag * @param int $eid Extension ID + * * @return void */ public function setSchemaVersion($schema, $eid) @@ -851,9 +840,9 @@ public function setSchemaVersion($schema, $eid) /** * Method to process the updates for an item * - * @access public * @param JXMLElement $schema The xml node to process * @param int $eid Extension Identifier + * * @return boolean Result of the operations * @since 11.1 */ @@ -861,7 +850,7 @@ public function parseSchemaUpdates($schema, $eid) { $files = Array(); $update_count = 0; - // ensure we have an xml element and a valid extension id + // Ensure we have an xml element and a valid extension id if($eid && $schema) { $db = JFactory::getDBO(); @@ -966,17 +955,17 @@ public function parseSchemaUpdates($schema, $eid) * Method to parse through a files element of the installation manifest and take appropriate * action. * - * @access public * @param JXMLElement $element The xml node to process * @param int $cid Application ID of application to install to * @param Array $oldFiles List of old files (JXMLElement's) * @param Array $oldMD5 List of old MD5 sums (indexed by filename with value as MD5) + * * @return boolean True on success * @since 11.1 */ public function parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null) { - // Get the array of file nodes to process; we checked this had children above + // Get the array of file nodes to process; we checked whether this had children above. if ( ! $element || ! count($element->children())) { // Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed. @@ -1004,15 +993,15 @@ public function parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null) $destination = $this->getPath($pathname); } - /* - * Here we set the folder we are going to copy the files from. - * - * Does the element have a folder attribute? - * - * If so this indicates that the files are in a subdirectory of the source - * folder and we should append the folder attribute to the source path when - * copying files. - */ + + // Here we set the folder we are going to copy the files from. + + // Does the element have a folder attribute? + // + // If so this indicates that the files are in a subdirectory of the source + // folder and we should append the folder attribute to the source path when + // copying files. + $folder = (string)$element->attributes()->folder; if ($folder && file_exists($this->getPath('source').DS.$folder)) { @@ -1056,11 +1045,11 @@ public function parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null) // Is this path a file or folder? $path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file'; - /* - * Before we can add a file to the copyfiles array we need to ensure - * that the folder we are copying our file to exits and if it doesn't, - * we need to create it. - */ + + // Before we can add a file to the copyfiles array we need to ensure + // that the folder we are copying our file to exits and if it doesn't, + // we need to create it. + if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); @@ -1083,9 +1072,9 @@ public function parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null) * Method to parse through a languages element of the installation manifest and take appropriate * action. * - * @access public * @param JXMLElement $element The xml node to process * @param int $cid Application ID of application to install to + * * @return boolean True on success * @since 11.1 */ @@ -1105,22 +1094,20 @@ public function parseLanguages($element, $cid=0) jimport('joomla.application.helper'); $client = JApplicationHelper::getClientInfo($cid); - /* - * Here we set the folder we are going to copy the files to. - * - * 'languages' Files are copied to JPATH_BASE/language/ folder - */ + + // Here we set the folder we are going to copy the files to. + // 'languages' Files are copied to JPATH_BASE/language/ folder + $destination = $client->path.DS.'language'; - /* - * Here we set the folder we are going to copy the files from. - * - * Does the element have a folder attribute? - * - * If so this indicates that the files are in a subdirectory of the source - * folder and we should append the folder attribute to the source path when - * copying files. - */ + // Here we set the folder we are going to copy the files from. + + // Does the element have a folder attribute? + + // If so this indicates that the files are in a subdirectory of the source + // folder and we should append the folder attribute to the source path when + // copying files. + $folder = (string)$element->attributes()->folder; if ($folder && file_exists($this->getPath('source').DS.$folder)) { $source = $this->getPath('source').DS.$folder; @@ -1132,28 +1119,25 @@ public function parseLanguages($element, $cid=0) // Process each file in the $files array (children of $tagName). foreach ($element->children() as $file) { - /* - * Language files go in a subfolder based on the language code, ie. - * - * en-US.mycomponent.ini - * - * would go in the en-US subdirectory of the language folder. - * - * We will only install language files where a core language pack - * already exists. - */ + // Language files go in a subfolder based on the language code, ie. + // en-US.mycomponent.ini + // would go in the en-US subdirectory of the language folder. + + // We will only install language files where a core language pack + // already exists. + if ((string)$file->attributes()->tag != '') { $path['src'] = $source.DS.$file; if ((string)$file->attributes()->client != '') { - // override the client + // Override the client $langclient = JApplicationHelper::getClientInfo((string)$file->attributes()->client, true); $path['dest'] = $langclient->path.DS.'language'.DS.$file->attributes()->tag.DS.basename((string)$file); } else { - // use the default client + // Use the default client $path['dest'] = $destination.DS.$file->attributes()->tag.DS.basename((string)$file); } @@ -1168,11 +1152,11 @@ public function parseLanguages($element, $cid=0) $path['dest'] = $destination.DS.$file; } - /* - * Before we can add a file to the copyfiles array we need to ensure - * that the folder we are copying our file to exits and if it doesn't, - * we need to create it. - */ + // + // Before we can add a file to the copyfiles array we need to ensure + // that the folder we are copying our file to exits and if it doesn't, + // we need to create it. + if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); @@ -1195,9 +1179,9 @@ public function parseLanguages($element, $cid=0) * Method to parse through a media element of the installation manifest and take appropriate * action. * - * @access public * @param JXMLElement $element The xml node to process * @param int $cid Application ID of application to install to + * * @return boolean True on success * @since 11.1 */ @@ -1216,22 +1200,20 @@ public function parseMedia($element, $cid=0) jimport('joomla.application.helper'); $client = JApplicationHelper::getClientInfo($cid); - /* - * Here we set the folder we are going to copy the files to. - * Default 'media' Files are copied to the JPATH_BASE/media folder - */ + + // Here we set the folder we are going to copy the files to. + // Default 'media' Files are copied to the JPATH_BASE/media folder + $folder = ((string)$element->attributes()->destination) ? DS.$element->attributes()->destination : null; $destination = JPath::clean(JPATH_ROOT.DS.'media'.$folder); - /* - * Here we set the folder we are going to copy the files from. - * - * Does the element have a folder attribute? - * - * If so this indicates that the files are in a subdirectory of the source - * folder and we should append the folder attribute to the source path when - * copying files. - */ + // Here we set the folder we are going to copy the files from. + + // Does the element have a folder attribute? + // If so this indicates that the files are in a subdirectory of the source + // folder and we should append the folder attribute to the source path when + // copying files. + $folder = (string)$element->attributes()->folder; if ($folder && file_exists($this->getPath('source').DS.$folder)) { $source = $this->getPath('source').DS.$folder; @@ -1249,11 +1231,11 @@ public function parseMedia($element, $cid=0) // Is this path a file or folder? $path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file'; - /* - * Before we can add a file to the copyfiles array we need to ensure - * that the folder we are copying our file to exits and if it doesn't, - * we need to create it. - */ + + // Before we can add a file to the copyfiles array we need to ensure + // that the folder we are copying our file to exits and if it doesn't, + // we need to create it. + if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); @@ -1274,10 +1256,10 @@ public function parseMedia($element, $cid=0) /** * Method to parse the parameters of an extension, build the INI - * string for it's default parameters, and return the INI string. + * string for its default parameters, and return the INI string. * - * @access public * @return string INI string of parameter values + * * @since 11.1 */ public function getParams() @@ -1302,9 +1284,9 @@ public function getParams() // Iterating through the fields and collecting the name/default values: foreach ($fieldset as $field) { - // Modified the below if statements to check against the - // null value since default values like "0" were casuing - // entire parameters to be skipped. + // Check against the null value since otherwise default values like "0" + // cause entire parameters to be skipped. + if (($name = $field->attributes()->name) === null) { continue; } @@ -1321,21 +1303,23 @@ public function getParams() } /** + * Copyfiles + * * Copy files from source directory to the target directory * - * @access public * @param array $files array with filenames * @param boolean $overwrite True if existing files can be replaced + * * @return boolean True on success * @since 11.1 */ public function copyFiles($files, $overwrite=null) { - /* - * To allow for manual override on the overwriting flag, we check to see if - * the $overwrite flag was set and is a boolean value. If not, use the object - * allowOverwrite flag. - */ + + // To allow for manual override on the overwriting flag, we check to see if + // the $overwrite flag was set and is a boolean value. If not, use the object + // allowOverwrite flag. + if (is_null($overwrite) || !is_bool($overwrite)) { $overwrite = $this->_overwrite; } @@ -1364,17 +1348,15 @@ public function copyFiles($files, $overwrite=null) } elseif (file_exists($filedest) && !$overwrite) { - /* - * It's okay if the manifest already exists - */ + + // It's okay if the manifest already exists if ($this->getPath('manifest') == $filesource) { continue; } - /* - * The destination file already exists and the overwrite flag is false. - * Set an error and return false. - */ + // The destination file already exists and the overwrite flag is false. + // Set an error and return false. + JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_FILE_EXISTS', $filedest)); return false; } @@ -1412,9 +1394,9 @@ public function copyFiles($files, $overwrite=null) } else { - /* - * The $files variable was either not an array or an empty array - */ + + // The $files variable was either not an array or an empty array + return false; } return count($files); @@ -1424,9 +1406,9 @@ public function copyFiles($files, $overwrite=null) * Method to parse through a files element of the installation manifest and remove * the files that were installed * - * @access public * @param object $element The xml node to process * @param int $cid Application ID of application to remove from + * * @return boolean True on success * @since 11.1 */ @@ -1513,14 +1495,12 @@ public function removeFiles($element, $cid=0) // Process each file in the $files array (children of $tagName). foreach ($files as $file) { - /* - * If the file is a language, we must handle it differently. Language files - * go in a subdirectory based on the language code, ie. - * - * en_US.mycomponent.ini - * - * would go in the en_US subdirectory of the languages directory. - */ + + // If the file is a language, we must handle it differently. Language files + // go in a subdirectory based on the language code, ie. + // en_US.mycomponent.ini + // would go in the en_US subdirectory of the languages directory. + if ($file->getName() == 'language' && (string)$file->attributes()->tag != '') { if ($source) { @@ -1542,9 +1522,8 @@ public function removeFiles($element, $cid=0) $path = $source.DS.$file; } - /* - * Actually delete the files/folders - */ + // Actually delete the files/folders + if (is_dir($path)) { $val = JFolder::delete($path); } @@ -1569,8 +1548,8 @@ public function removeFiles($element, $cid=0) /** * Copies the installation manifest file to the extension folder in the given client * - * @access public * @param int $cid Where to copy the installfile [optional: defaults to 1 (admin)] + * * @return boolean True on success, False on error * @since 11.1 */ @@ -1598,7 +1577,6 @@ public function copyManifest($cid=1) /** * Tries to find the package manifest file * - * @access private * @return boolean True on success, False on error * @since 1.0 */ @@ -1611,7 +1589,7 @@ public function findManifest() { foreach ($xmlfiles as $file) { - // Is it a valid joomla installation manifest file? + // Is it a valid Joomla installation manifest file? $manifest = $this->isManifest($file); if (!is_null($manifest)) { @@ -1652,8 +1630,8 @@ public function findManifest() /** * Is the xml file a valid Joomla installation manifest file * - * @access private * @param string $file An xmlfile path to check + * * @return mixed A JXMLElement, or null if the file failed to parse * @since 11.1 */ @@ -1668,11 +1646,9 @@ public function isManifest($file) return null; } - /* - * Check for a valid XML root tag. - * @todo: Remove backwards compatability in a future version - * Should be 'extension', but for backward compatability we will accept 'extension' or 'install'. - */ + // Check for a valid XML root tag. + // @todo: Remove backwards compatability in a future version + // Should be 'extension', but for backward compatability we will accept 'extension' or 'install'. // 1.5 uses 'install' // 1.6 uses 'extension' @@ -1687,6 +1663,7 @@ public function isManifest($file) /** * Generates a manifest cache + * * @return string serialised manifest data */ public function generateManifestCache() @@ -1714,16 +1691,22 @@ public function cleanDiscoveredExtension($type, $element, $folder='', $client=0) * Compares two "files" entries to find deleted files/folders * @param array $old_files An array of JXMLElement objects that are the old files * @param array $new_files An array of JXMLElement objects that are the new files + * * @return array An array with the delete files and folders in findDeletedFiles[files] and findDeletedFiles[folders] resepctively */ public function findDeletedFiles($old_files, $new_files) { // The magic find deleted files function! - $files = Array(); // the files that are new - $folders = Array(); // the folders that are new - $containers = Array(); // the folders of the files that are new - $files_deleted = Array(); // a list of files to delete - $folders_deleted = Array(); // a list of folders to delete + // The files that are new + $files = Array(); + // The folders that are new + $folders = Array(); + // The folders of the files that are new + $containers = Array(); + // A list of files to delete + $files_deleted = Array(); + // A list of folders to delete + $folders_deleted = Array(); foreach ($new_files as $file) { @@ -1735,14 +1718,18 @@ public function findDeletedFiles($old_files, $new_files) case 'file': default: - $files[] = (string)$file; // add any files to the list - // now handle the folder part of the file to ensure we get any containers - $container_parts = explode('/',dirname((string)$file)); // break up the parts of the directory - $container = ''; // make sure this is clean and empty + // Add any files to the list + $files[] = (string)$file; + // Now handle the folder part of the file to ensure we get any containers + // Break up the parts of the directory + $container_parts = explode('/',dirname((string)$file)); + // Make sure this is clean and empty + $container = ''; foreach ($container_parts as $part) { - // iterate through each part - if (!empty($container)) $container .= '/'; // add a slash if its not empty + // Iterate through each part + // Add a slash if its not empty + if (!empty($container)) $container .= '/'; $container .= $part; // append the folder part if (!in_array($container, $containers)) $containers[] = $container; // add the container if it doesn't already exist } @@ -1757,9 +1744,11 @@ public function findDeletedFiles($old_files, $new_files) case 'folder': if (!in_array((string)$file, $folders)) { - // look if the folder exists in the new list - if (!in_array((string)$file, $containers)) { // check if the folder exists as a container in the new list - $folders_deleted[] = (string)$file; // if its not in the new list or a container then delete it + // See whether the folder exists in the new list + if (!in_array((string)$file, $containers)) { + // Check if the folder exists as a container in the new list + // If it's not in the new list or a container then delete it + $folders_deleted[] = (string)$file; } } break; diff --git a/libraries/joomla/installer/librarymanifest.php b/libraries/joomla/installer/librarymanifest.php index ed9dae28ab..81d5c32855 100644 --- a/libraries/joomla/installer/librarymanifest.php +++ b/libraries/joomla/installer/librarymanifest.php @@ -20,35 +20,65 @@ */ class JLibraryManifest extends JObject { - /** @var string name Name of Library */ + /** + * @var string name Name of Library + */ var $name = ''; - /** @var string libraryname File system name of the library */ + /** + * @var string libraryname File system name of the library + */ var $libraryname = ''; - /** @var string version Version of the library */ + /** + * @var string version Version of the library + */ var $version = ''; - /** @var string description Description of the library */ + /** + * @var string description Description of the library + */ var $description = ''; - /** @var date creationDate Creation Date of the extension */ + /** + * @var date creationDate Creation Date of the extension + */ var $creationDate = ''; - /** @var string copyright Copyright notice for the extension */ + /** + * @var string copyright Copyright notice for the extension + */ var $copyright = ''; - /** @var string license License for the extension */ + /** + * @var string license License for the extension + */ var $license = ''; - /** @var string author Author for the extension */ + /** + * @var string author Author for the extension + */ var $author = ''; - /** @var string authoremail Author email for the extension */ + /** + * @var string authoremail Author email for the extension + */ var $authoremail = ''; - /** @var string authorurl Author url for the extension */ + /** + * @var string authorurl Author url for the extension + */ var $authorurl = ''; - /** @var string packager Name of the packager for the library (may also be porter) */ + /** + * @var string packager Name of the packager for the library (may also be porter) + */ var $packager = ''; - /** @var string packagerurl URL of the packager for the library (may also be porter) */ + /** + * @var string packagerurl URL of the packager for the library (may also be porter) + */ var $packagerurl = ''; - /** @var string update URL of the update site */ + /** + * @var string update URL of the update site + */ var $update = ''; - /** @var string[] filelist List of files in the library */ + /** + * @var string[] filelist List of files in the library + */ var $filelist = Array(); - /** @var string manifest_file Path to manifest file */ + /** + * @var string manifest_file Path to manifest file + */ var $manifest_file = ''; /** diff --git a/libraries/joomla/installer/packagemanifest.php b/libraries/joomla/installer/packagemanifest.php index 0ff83cdcc4..2bb70b59ae 100644 --- a/libraries/joomla/installer/packagemanifest.php +++ b/libraries/joomla/installer/packagemanifest.php @@ -21,34 +21,55 @@ */ class JPackageManifest extends JObject { - /** @var string name Name of the package */ + /** + * @var string name Name of the package + */ var $name = ''; - /** @var string packagename Unique name of the package */ + /** + * @var string packagename Unique name of the package + */ var $packagename = ''; - /** @var string url Website for the package */ + /** + * @var string url Website for the package + */ var $url = ''; - /** @var string description Description for the package */ + /** + * @var string description Description for the package + */ var $description = ''; - /** @var string packager Packager of the package */ + /** + * @var string packager Packager of the package + */ var $packager = ''; - /** @var string packagerurl Packager's URL of the package */ + /** + * @var string packagerurl Packager's URL of the package + */ var $packagerurl = ''; - /** @var string update Update site for the package */ + /** + * @var string update Update site for the package + */ var $update = ''; - /** @var string version Version of the package */ + /** + * @var string version Version of the package + */ var $version = ''; - /** @var JExtension[] filelist List of files in this package */ + /** + * + * @var JExtension[] filelist List of files in this package + */ var $filelist = Array(); - /** @var string manifest_file Path to the manifest file */ + /** + * @var string manifest_file Path to the manifest file + */ var $manifest_file = ''; /**