function postflight($type, $parent) { if (version_compare(JVERSION, '3.0.0', '>')) { $messages = array(); // Import required modules jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); jimport('joomla.filesystem.file'); //$db = JFactory::getDBO(); //$query = "ALTER TABLE #__k2_items ADD FULLTEXT(extra_fields)"; //$db->setQuery($query); //$db->query(); // Get packages $p_dir = JPath::clean(JPATH_SITE . DS . 'components' . DS . 'com_jak2filter' . DS . 'packages'); // Did you give us a valid directory? if (!is_dir($p_dir)) { $messages[] = JText::_('Package directory(Related modules, plugins) is missing'); } else { $subpackages = JFolder::files($p_dir); $result = true; $installer = new JInstaller(); if ($subpackages) { $app = JFactory::getApplication(); $templateDir = 'templates/' . $app->getTemplate(); foreach ($subpackages as $zpackage) { if (JFile::getExt($p_dir . DS . $zpackage) != "zip") { continue; } $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage); if ($subpackage) { $type = JInstallerHelper::detectType($subpackage['dir']); if (!$type) { $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>'; $result = false; } if (!$installer->install($subpackage['dir'])) { // There was an error installing the package $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>'; } else { $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" /> <span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>'; } if (!is_file($subpackage['packagefile'])) { $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile']; } if (is_dir($subpackage['extractdir'])) { JFolder::delete($subpackage['extractdir']); } if (is_file($subpackage['packagefile'])) { JFile::delete($subpackage['packagefile']); } } } } JFolder::delete($p_dir); } } }
function com_install() { JAVoiceHelpers::Install_Db(); $messages = array(); // Import required modules jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); jimport('joomla.filesystem.file'); // Get packages $p_dir = JPath::clean(JPATH_SITE . '/components/com_javoice/packages'); // Did you give us a valid directory? if (!is_dir($p_dir)) { $messages[] = JText::_('Package directory(Related modules, plugins) is missing'); } else { $subpackages = JFolder::files($p_dir); $result = true; $installer = new JInstaller(); if ($subpackages) { $app = JFactory::getApplication(); $templateDir = 'templates/' . $app->getTemplate(); foreach ($subpackages as $zpackage) { if (JFile::getExt($p_dir . DS . $zpackage) != "zip") { continue; } $subpackage = JInstallerHelper::unpack($p_dir . DS . $zpackage); if ($subpackage) { $type = JInstallerHelper::detectType($subpackage['dir']); if (!$type) { $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::_($zpackage . " Not valid package") . '</span>'; $result = false; } if (!$installer->install($subpackage['dir'])) { // There was an error installing the package $messages[] = '<img src="' . $templateDir . '/images/admin/publish_x.png" alt="" width="16" height="16" /> <span style="color:#FF0000;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Error')) . '</span>'; } else { $messages[] = '<img src="' . $templateDir . '/images/admin/tick.png" alt="" width="16" height="16" /> <span style="color:#00FF00;">' . JText::sprintf('Install %s: %s', $type . " " . JFile::getName($zpackage), JText::_('Success')) . '</span>'; } if (!is_file($subpackage['packagefile'])) { $subpackage['packagefile'] = $p_dir . DS . $subpackage['packagefile']; } if (is_dir($subpackage['extractdir'])) { JFolder::delete($subpackage['extractdir']); } if (is_file($subpackage['packagefile'])) { JFile::delete($subpackage['packagefile']); } } } } JFolder::delete($p_dir); } }
public function getSRPURL($return = '') { $session = JFactory::getSession(); $tempdir = $session->get('tempdir', '', 'liveupdate'); jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); jimport('joomla.filesystem.file'); $instModelFile = JPATH_ADMINISTRATOR . '/components/com_akeeba/models/installer.php'; if (!JFile::exists($instModelFile)) { return false; } require_once JPATH_ADMINISTRATOR . '/components/com_akeeba/models/installer.php'; $model = JModel::getInstance('Installer', 'AkeebaModel'); $packageType = JInstallerHelper::detectType($tempdir); $name = $model->getExtensionName($tempdir); $url = 'index.php?option=com_akeeba&view=backup&tag=restorepoint&type=' . $packageType . '&name=' . urlencode($name['name']); switch ($type) { case 'module': case 'template': $url .= '&group=' . $name['client']; break; case 'plugin': $url .= '&group=' . $name['group']; break; } if (!empty($return)) { $url .= '&returnurl=' . urlencode($return); } return $url; }
public function _getPackageFromFolder() { $p_dir = JRequest::getString('install_directory'); $p_dir = JPath::clean($p_dir); // Did you give us a valid directory? if (!is_dir($p_dir)) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_REDSHOP_PLEASE_ENTER_A_PACKAGE_DIRECTORY')); return false; } // Detect the package type $type = JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_REDSHOP_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE')); return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
/** * 取得zip的安装包的相关信息 * */ function getPackageFromFolder($p_dir) { // 如果目录不正确,出错 if (!is_dir($p_dir)) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a package directory')); return false; } // 取得包的类型 $type = JInstallerHelper::detectType($p_dir); // 如果不能取得,出错 if (!$type) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Path does not have a valid package')); return false; } // 设置相关的包的信息 $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
/** * Method to copy the extension's base files from the `<files>` tag(s) and the manifest file * * @return void * * @since 3.4 * @throws RuntimeException */ protected function copyBaseFiles() { $folder = (string) $this->getManifest()->files->attributes()->folder; $source = $this->parent->getPath('source'); if ($folder) { $source .= '/' . $folder; } // Install all necessary files if (!count($this->getManifest()->files->children())) { throw new RuntimeException(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); } foreach ($this->getManifest()->files->children() as $child) { $file = $source . '/' . (string) $child; if (is_dir($file)) { // If it's actually a directory then fill it up $package = array(); $package['dir'] = $file; $package['type'] = JInstallerHelper::detectType($file); } else { // If it's an archive $package = JInstallerHelper::unpack($file); } $tmpInstaller = new JInstaller(); $installResult = $tmpInstaller->{$this->route}($package['dir']); if (!$installResult) { throw new RuntimeException(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file))); } $this->results[] = array('name' => (string) $tmpInstaller->manifest->name, 'result' => $installResult); } }
/** * Unpacks a file and verifies it as a Joomla element package * Supports .gz .tar .tar.gz and .zip * * @static * @param string $p_filename The uploaded package filename or install directory * @return Array Two elements - extractdir and packagefile * @since 1.5 */ function unpack($p_filename) { // Path to the archive $archivename = $p_filename; // Temporary folder to extract the archive into $tmpdir = uniqid('install_'); // Clean the paths to use for archive extraction $extractdir = JPath::clean(dirname($p_filename) . DS . $tmpdir); $archivename = JPath::clean($archivename); // do the unpacking of the archive $result = JArchive::extract($archivename, $extractdir); if ($result === false) { return false; } /* * Lets set the extraction directory and package file in the result array so we can * cleanup everything properly later on. */ $retval['extractdir'] = $extractdir; $retval['packagefile'] = $archivename; /* * Try to find the correct install directory. In case the package is inside a * subdirectory detect this and set the install directory to the correct path. * * List all the items in the installation directory. If there is only one, and * it is a folder, then we will set that folder to be the installation folder. */ $dirList = array_merge(JFolder::files($extractdir, ''), JFolder::folders($extractdir, '')); if (count($dirList) == 1) { if (JFolder::exists($extractdir . DS . $dirList[0])) { $extractdir = JPath::clean($extractdir . DS . $dirList[0]); } } /* * We have found the install directory so lets set it and then move on * to detecting the extension type. */ $retval['dir'] = $extractdir; /* * Get the extension type and return the directory/type array on success or * false on fail. */ if ($retval['type'] = JInstallerHelper::detectType($extractdir)) { return $retval; } else { return false; } }
/** * Get the install package or folder * @return Array $package */ function _getPackage() { $config = JFactory::getConfig(); jimport('joomla.filesystem.file'); // set standard method $upload = true; $package = null; // Get the uploaded file information $file = JRequest::getVar('install', null, 'files', 'array'); // get the file path information $path = JRequest::getString('install_input'); if (!(bool) ini_get('file_uploads') || !is_array($file)) { $upload = false; // no path either! if (!$path) { JError::raiseWarning('SOME_ERROR_CODE', WFText::_('WARNINSTALLFILE')); return false; } } // Install failed if (!$file['tmp_name'] && !$file['name'] || ($file['error'] || $file['size'] < 1)) { $upload = false; if (!$path) { JError::raiseWarning('SOME_ERROR_CODE', WFText::_('WF_INSTALLER_NO_FILE')); return false; } } // uploaded file if ($upload && $file['tmp_name'] && $file['name']) { $dest = $config->getValue('config.tmp_path') . DS . $file['name']; $src = $file['tmp_name']; // upload file JFile::upload($src, $dest); // path to file } else { $dest = JPath::clean($path); } // Unpack the package file if (preg_match('/\\.(zip|tar|gz|gzip|tgz|tbz2|bz2|bzip2)/i', $dest)) { // Make sure that zlib is loaded so that the package can be unpacked if (!extension_loaded('zlib')) { JError::raiseWarning('SOME_ERROR_CODE', WFText::_('WARNINSTALLZLIB')); return false; } $package = JInstallerHelper::unpack($dest); // might be a directory } else { if (!is_dir($dest)) { JError::raiseWarning('SOME_ERROR_CODE', WFText::_('WF_INSTALLER_INVALID_SRC')); return false; } // Detect the package type $type = @JInstallerHelper::detectType($dest); $package = array('packagefile' => null, 'extractdir' => null, 'dir' => $dest, 'type' => $type); } $package['manifest'] = null; // set install method JRequest::setVar('install_method', 'install'); return $package; }
/** * Custom install method * * @access public * @return boolean True on success * @since 1.5 */ function install() { // Get the extension manifest object $this->manifest = $this->parent->getManifest(); /** * --------------------------------------------------------------------------------------------- * Manifest Document Setup Section * --------------------------------------------------------------------------------------------- */ // Set the extensions name $name = (string) $this->manifest->packagename; $name = JFilterInput::getInstance()->clean($name, 'cmd'); $this->set('name', $name); // Get the component description $description = (string) $this->manifest->description; if ($description) { $this->parent->set('message', $description); } else { $this->parent->set('message', ''); } // Set the installation path $group = (string) $this->manifest->packagename; if (!empty($group)) { // TODO: Remark this location $this->parent->setPath('extension_root', JPATH_ROOT . DS . 'libraries' . DS . implode(DS, explode('/', $group))); } else { $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . JText::_('No package file specified')); return false; } /** * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ // If the plugin directory does not exist, lets create it $created = false; if (!file_exists($this->parent->getPath('extension_root'))) { if (!($created = JFolder::create($this->parent->getPath('extension_root')))) { $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . JText::_('FAILED_TO_CREATE_DIRECTORY') . ': "' . $this->parent->getPath('extension_root') . '"'); return false; } } /* * 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'))); } if ($folder = (string) $this->manifest->files->attributes()->folder) { $source = $this->parent->getPath('source') . DS . $folder; } else { $source = $this->parent->getPath('source'); } // Install all necessary files if (count($this->manifest->files->children())) { foreach ($this->manifest->files->children() as $child) { $file = $source . DS . $child; jimport('joomla.installer.helper'); if (is_dir($file)) { // if its actually a directory then fill it up $package = array(); $package['dir'] = $file; $package['type'] = JInstallerHelper::detectType($file); } else { // if its an archive $package = JInstallerHelper::unpack($file); } $tmpInstaller = new JInstaller(); if (!$tmpInstaller->install($package['dir'])) { $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . JText::_('There was an error installing an extension:') . basename($file)); return false; } } } else { $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . JText::_('There were no files to install!') . print_r($this->manifest->files->children(), true)); return false; } /** * --------------------------------------------------------------------------------------------- * Extension Registration * --------------------------------------------------------------------------------------------- */ $row =& JTable::getInstance('extension'); $row->name = $this->get('name'); $row->type = 'package'; $row->element = $this->get('element'); $row->folder = ''; // There is no folder for modules $row->enabled = 1; $row->protected = 0; $row->access = 1; $row->client_id = 0; $row->params = $this->parent->getParams(); $row->custom_data = ''; // custom data $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . $db->stderr(true)); return false; } /** * --------------------------------------------------------------------------------------------- * Finalization and Cleanup Section * --------------------------------------------------------------------------------------------- */ // Lastly, we will copy the manifest file to its appropriate place. $manifest = array(); $manifest['src'] = $this->parent->getPath('manifest'); $manifest['dest'] = JPATH_MANIFESTS . DS . 'packages' . DS . basename($this->parent->getPath('manifest')); if (!$this->parent->copyFiles(array($manifest), true)) { // Install failed, rollback changes $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ': ' . JText::_('COULD_NOT_COPY_SETUP_FILE')); return false; } return true; }
public function install() { // Anti-CSRF token check if ($this->csrfProtection) { $this->_csrfProtection(); } /** @var AkeebaModelUpdates $model */ $model = $this->getThisModel(); // Get the downloaded package path $session = JFactory::getSession(); $updatePackagePath = $session->get('downloadedPackage', null, 'com_akeeba.update'); $installationDirectory = $session->get('installationDirectory', null, 'com_akeeba.update'); // Registers FTP credentials from the session $needsFTP = $model->needsFTPCredentials(); try { if (!is_dir($installationDirectory)) { throw new RuntimeException(JText::_('UPDATE_ERROR_CANTEXTRACT')); } jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); $installer = JInstaller::getInstance(); $packageType = JInstallerHelper::detectType($installationDirectory); if (!$packageType) { throw new RuntimeException(JText::_('COM_AKEEBA_UPDATE_ERR_WRONGPACKAGETYPE')); } if (!$installer->install($installationDirectory)) { $model->setState('name', $installer->get('name')); $model->setState('message', $installer->message); $model->setState('extmessage', $installer->get('extension_message')); throw new RuntimeException(JText::_('COM_AKEEBA_UPDATE_ERR_CANTINSTALLUPDATE')); } $model->setState('name', $installer->get('name')); $model->setState('message', $installer->message); $model->setState('extmessage', $installer->get('extension_message')); } catch (Exception $e) { // Remove the downloaded update file jimport('jooomla.filesystem.file'); jimport('jooomla.filesystem.folder'); if (is_file($updatePackagePath)) { if (!@unlink($updatePackagePath)) { JFile::delete($updatePackagePath); } } if (is_dir($installationDirectory)) { JFolder::delete($installationDirectory); } // Clear the stale session information with Joomla! 1.x way $session->set('downloadedPackage', null, 'com_akeeba.update'); $session->set('installationDirectory', null, 'com_akeeba.update'); // ... and with Joomla! 2.x+ way if (method_exists($session, 'clear')) { $session->clear('downloadedPackage', 'com_akeeba.update'); $session->clear('installationDirectory', 'com_akeeba.update'); } // Redirect to the error page $url = 'index.php?option=' . $this->input->getCmd('option', '') . '&view=update'; $this->setRedirect($url, $e->getMessage(), 'error'); return true; } // Show the page where the user is informed the update installation is complete $this->display(false); }
protected function _getPackageFromFolder() { // @TODO find a better way to filter the data $directory = KRequest::get('post.directory', 'path', $this->getModel()->getState()->directory); // Detect the package type $type = JInstallerHelper::detectType($directory); // Did you give us a valid package? if (!$type) { JError::raiseWarning(0, JText::_('Path does not have a valid package')); return false; } return array('packagefile' => null, 'extractdir' => null, 'dir' => $directory, 'type' => $type); }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ $app = JFactory::getApplication(); $plugins = array('search_otrsgateway', 'authentication_otrsgateway'); $db = JFactory::getDBO(); foreach ($plugins as $plugin) { $p_dir = $this->parent->getPath('source') . DS . 'plugins' . DS . $plugin; $package = array(); $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = JInstallerHelper::detectType($p_dir); $installer = new JInstaller(); // Install the package if (!$installer->install($package['dir'])) { // There was an error installing the package $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error')); $app->enqueueMessage($msg); $result = false; } else { // Package installed sucessfully $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success')); $app->enqueueMessage($msg); $result = true; // Enable the installed plugin $plgParts = explode("_", $plugin); $query = "UPDATE #__plugins SET published = 1 WHERE folder = '" . $plgParts[0] . "' AND element = '" . $plgParts[1] . "'";
function _getPackageFromFolder() { // Get the path to the package to install $p_dir = JRequest::getString('install_directory'); $p_dir = JPath::clean($p_dir); // Did you give us a valid directory? if (!is_dir($p_dir)) { JError::raiseWarning(100, JText::_('COM_SEF_ENTER_PACKAGE_DIRECTORY')); return false; } // Detect the package type $type = JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type || $type != 'sef_ext') { JError::raiseWarning(100, JText::_('COM_SEF_ERROR_NO_VALID_PACKAGE')); return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
function fromDirectory() { // Get the path to the package to install $p_dir = JRequest::getString('install_directory'); $p_dir = JPath::clean( $p_dir ); // Did you give us a valid directory? if (!is_dir($p_dir)) { if(version_compare(JVERSION, '1.6.0', 'ge')) { JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_PLEASE_ENTER_A_PACKAGE_DIRECTORY')); } else { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a package directory')); } return false; } // Detect the package type $type = JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type) { if(version_compare(JVERSION, '1.6.0', 'ge')) { JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE')); } else { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Path does not have a valid package')); } return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; $session = JFactory::getSession(); $session->set('package', $package, 'akeeba'); return true; }
/** * Install an extension from a directory * * @static * @return boolean True on success * @since 1.0 */ function _getPackageFromFolder() { // Get the path to the package to install $p_dir = JRequest::getString('install_directory'); $p_dir = JPath::clean($p_dir); // Did you give us a valid directory? if (!is_dir($p_dir)) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a package directory')); return false; } // Detect the package type $type = JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Path does not have a valid package')); return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
public function install($parent) { $this->cleanBogusError(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $retval = true; $buffer = ''; $install_html_file = dirname(__FILE__) . '/install.html'; $install_css_file = dirname(__FILE__) . '/install.css'; $tmp_path = JPATH_ROOT . '/tmp'; // Drop out Style if (file_exists($install_css_file)) { $buffer .= JFile::read($install_html_file); } if (JFolder::exists($tmp_path)) { // Copy install.css to tmp dir for inclusion JFile::copy($install_css_file, $tmp_path . '/install.css'); } // Opening HTML ob_start(); ?> <div id="rokinstall-logo"> <ul id="rokinstall-status"> <?php $buffer .= ob_get_clean(); $run_installer = true; if (is_file(dirname(__FILE__) . '/requirements.php')) { // check to see if requierments are met if (($loaderrors = (require_once dirname(__FILE__) . '/requirements.php')) !== true) { $package['name'] = ''; $msg = "Requirements check failed.<br />" . implode('<br />', $loaderrors); $buffer .= $this->printerror($package, $msg); $run_installer = false; } } // Cycle through cogs and install each if ($run_installer) { if (count($this->manifest->cogs->children())) { require_once $this->installerdir . DS . 'RokInstaller.php'; foreach ($this->manifest->cogs->children() as $cog) { $folder = $this->sourcedir . DS . trim($cog); jimport('joomla.installer.helper'); if (is_dir($folder)) { // if its actually a directory then fill it up $package = array(); $package['dir'] = $folder; $package['type'] = JInstallerHelper::detectType($folder); $package['installer'] = new RokInstaller(); $package['name'] = (string) $cog->name; $package['state'] = 'Success'; $package['description'] = (string) $cog->description; $package['msg'] = ''; $package['type'] = ucfirst((string) $cog['type']); $package['installer']->setCogInfo($cog); // add installer to static for possible rollback $this->packages[] = $package; if (!@$package['installer']->install($package['dir'])) { while ($error = JError::getError(true)) { $package['msg'] .= $error; } $buffer .= $this->printerror($package, $package['msg']); //$this->abort(); break; } if ($package['installer']->getInstallType() == 'install') { $buffer .= $this->printInstall($package); } else { $buffer .= $this->printUpdate($package); } } else { $package = array(); $package['dir'] = $folder; $package['name'] = (string) $cog->name; $package['state'] = 'Failed'; $package['description'] = (string) $cog->description; $package['msg'] = ''; $package['type'] = ucfirst((string) $cog['type']); $buffer .= $this->printerror($package, JText::_('JLIB_INSTALLER_ABORT_NOINSTALLPATH')); //$this->abort(); break; } } } else { $parent->getParent()->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); } } // Closing HTML ob_start(); ?> </ul> </div> <?php $buffer .= ob_get_clean(); // Return stuff echo $buffer; return $retval; }
/** * Custom install method * * @access public * @return boolean True on success * @since 1.5 */ function install() { // Get the extension manifest object $this->manifest = $this->parent->getManifest(); /** * --------------------------------------------------------------------------------------------- * Manifest Document Setup Section * --------------------------------------------------------------------------------------------- */ // Set the extensions name $filter = JFilterInput::getInstance(); $name = (string) $this->manifest->packagename; $name = $filter->clean($name, 'cmd'); $this->set('name', $name); $element = 'pkg_' . $filter->clean($this->manifest->packagename, 'cmd'); $this->set('element', $element); // Get the component description $description = (string) $this->manifest->description; if ($description) { $this->parent->set('message', JText::_($description)); } else { $this->parent->set('message', ''); } // Set the installation path $files = $this->manifest->files; $group = (string) $this->manifest->packagename; if (!empty($group)) { // TODO: Remark this location $this->parent->setPath('extension_root', JPATH_ROOT . DS . 'packages' . DS . implode(DS, explode('/', $group))); } else { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_PACK', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); return false; } /** * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ if ($folder = $files->attributes()->folder) { $source = $this->parent->getPath('source') . DS . $folder; } else { $source = $this->parent->getPath('source'); } // Install all necessary files if (count($this->manifest->files->children())) { foreach ($this->manifest->files->children() as $child) { $file = $source . DS . $child; jimport('joomla.installer.helper'); if (is_dir($file)) { // if its actually a directory then fill it up $package = array(); $package['dir'] = $file; $package['type'] = JInstallerHelper::detectType($file); } else { // if its an archive $package = JInstallerHelper::unpack($file); } $tmpInstaller = new JInstaller(); if (!$tmpInstaller->install($package['dir'])) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file))); return false; } } } else { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); return false; } // Parse optional tags $this->parent->parseLanguages($this->manifest->languages); /** * --------------------------------------------------------------------------------------------- * Extension Registration * --------------------------------------------------------------------------------------------- */ $row = JTable::getInstance('extension'); $eid = $row->find(array('element' => strtolower($this->get('element')), 'type' => 'package')); if ($eid) { $row->load($eid); } else { $row->name = $this->get('name'); $row->type = 'package'; $row->element = $this->get('element'); $row->folder = ''; // There is no folder for modules $row->enabled = 1; $row->protected = 0; $row->access = 1; $row->client_id = 0; $row->custom_data = ''; // custom data $row->params = $this->parent->getParams(); } // update the manifest cache for the entry $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ROLLBACK', $row->getError())); return false; } /** * --------------------------------------------------------------------------------------------- * Finalization and Cleanup Section * --------------------------------------------------------------------------------------------- */ // Lastly, we will copy the manifest file to its appropriate place. $manifest = array(); $manifest['src'] = $this->parent->getPath('manifest'); $manifest['dest'] = JPATH_MANIFESTS . DS . 'packages' . DS . basename($this->parent->getPath('manifest')); if (!$this->parent->copyFiles(array($manifest), true)) { // Install failed, rollback changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_COPY_SETUP', JText::_('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES'))); return false; } return true; }
/** * @param DOMDocument $def * @param string $dir * @return array | string */ protected function installExt($def, $dir) { $this->checkRequirements($def); jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); $installer = JInstaller::getInstance(); $type = JInstallerHelper::detectType($dir); $xp = new DOMXPath($def); try { $installer->install($dir); // it was core update - break now if ($type == 'component') { SPFactory::cache()->cleanAll(); return array('msg' => Sobi::Txt('CMS_SOBIPRO_UPDATE_INSTALLED', $def->getElementsByTagName('version')->item(0)->nodeValue), 'msgtype' => SPC::SUCCESS_MSG); } $msg = Sobi::Txt('CMSEX_INSTALLED', $type, $def->getElementsByTagName('name')->item(0)->nodeValue); $this->id = SPLang::nid($def->getElementsByTagName('name')->item(0)->nodeValue); $id = $xp->query('//filename[@module|@plugin]')->item(0); $this->id = strlen($id->getAttribute('module')) ? $id->getAttribute('module') : $id->getAttribute('plugin'); if (strlen($def->documentElement->getAttribute('group'))) { $this->id = $def->documentElement->getAttribute('group') . '_' . $this->id; } if ($this->id) { $this->definition = new DOMDocument(); $this->definition->formatOutput = true; $this->definition->preserveWhiteSpace = false; $this->definition->appendChild($this->definition->createElement('SobiProApp')); $root = $this->definition->getElementsByTagName('SobiProApp')->item(0); $root->appendChild($this->definition->createElement('id', $this->id)); $root->appendChild($this->definition->createElement('type', $type)); $root->appendChild($this->definition->createElement('name', $def->getElementsByTagName('name')->item(0)->nodeValue)); $root->appendChild($this->definition->createElement('uninstall', 'cms.base.installer:remove')); $this->definition->appendChild($root); $dir = SPLoader::dirPath('etc.installed.' . $type . 's', 'front', false); if (!SPFs::exists($dir)) { SPFs::mkdir($dir); } $path = $dir . '/' . $this->id . '.xml'; $file = SPFactory::Instance('base.fs.file', $path); $this->definition->normalizeDocument(); $file->content($this->definition->saveXML()); $file->save(); $this->storeData($type, $def); } return array('msg' => $msg, 'msgtype' => SPC::SUCCESS_MSG); } catch (Exception $x) { $this->error = Sobi::Txt('CMS_EXT_NOT_INSTALLED') . ' ' . $x->getMessage(); $this->errorType = SPC::ERROR_MSG; return array('msg' => $this->error, 'msgtype' => SPC::ERROR_MSG); } }
/** * Install an extension from a directory * * @return array Package details or false on failure * * @since 1.5 */ protected function _getPackageFromFolder() { $input = JFactory::getApplication()->input; // Get the path to the package to install $p_dir = $input->getString('install_directory'); $p_dir = JPath::clean($p_dir); // Did you give us a valid directory? if (!is_dir($p_dir)) { JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_PLEASE_ENTER_A_PACKAGE_DIRECTORY')); return false; } // Detect the package type $type = JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type) { JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE')); return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
/** * Install an extension from a directory * * @return Package details or false on failure * @since 1.5 */ protected function _getPackageFromFolder() { // Get the path to the package to install $p_dir = Request::getString('install_directory'); $p_dir = Filesystem::cleanPath($p_dir); // Did you give us a valid directory? if (!is_dir($p_dir)) { Notify::warning(Lang::txt('COM_INSTALLER_MSG_INSTALL_PLEASE_ENTER_A_PACKAGE_DIRECTORY')); return false; } // Detect the package type $type = \JInstallerHelper::detectType($p_dir); // Did you give us a valid package? if (!$type) { Notify::warning(Lang::txt('COM_INSTALLER_MSG_INSTALL_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE')); return false; } $package['packagefile'] = null; $package['extractdir'] = null; $package['dir'] = $p_dir; $package['type'] = $type; return $package; }
/** * Custom install method * * @return int The extension id * * @since 3.1 */ public function install() { // Get the extension manifest object $this->manifest = $this->parent->getManifest(); /* * --------------------------------------------------------------------------------------------- * Manifest Document Setup Section * --------------------------------------------------------------------------------------------- */ // Set the extensions name $filter = JFilterInput::getInstance(); $name = (string) $this->manifest->packagename; $name = $filter->clean($name, 'cmd'); $this->set('name', $name); $element = 'pkg_' . $filter->clean($this->manifest->packagename, 'cmd'); $this->set('element', $element); // Get the component description $description = (string) $this->manifest->description; if ($description) { $this->parent->set('message', JText::_($description)); } else { $this->parent->set('message', ''); } // Set the installation path $files = $this->manifest->files; $group = (string) $this->manifest->packagename; if (!empty($group)) { $this->parent->setPath('extension_root', JPATH_MANIFESTS . '/packages/' . implode(DIRECTORY_SEPARATOR, explode('/', $group))); } else { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_PACK', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); return false; } /* * If the package manifest already exists, then we will assume that the package is already * installed. */ if (file_exists(JPATH_MANIFESTS . '/packages/' . basename($this->parent->getPath('manifest')))) { // Look for an update function or update tag $updateElement = $this->manifest->update; // If $this->upgrade has already been set, or an update property exists in the manifest, update the extensions if ($this->parent->isUpgrade() || $updateElement) { // Use the update route for all packaged extensions $this->route = 'update'; } } /** * --------------------------------------------------------------------------------------------- * 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; if ($manifestScript) { $manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript; if (is_file($manifestScriptFile)) { // Load the file include_once $manifestScriptFile; } // Set the class name $classname = $element . 'InstallerScript'; if (class_exists($classname)) { // Create a new instance $this->parent->manifestClass = new $classname($this); // And set this so we can copy it later $this->set('manifest_script', $manifestScript); } } // 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')) { if ($this->parent->manifestClass->preflight($this->route, $this) === false) { // Preflight failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_CUSTOM_INSTALL_FAILURE')); return false; } } // Create msg object; first use here $msg = ob_get_contents(); ob_end_clean(); /* * --------------------------------------------------------------------------------------------- * Filesystem Processing Section * --------------------------------------------------------------------------------------------- */ if ($folder = $files->attributes()->folder) { $source = $this->parent->getPath('source') . '/' . $folder; } else { $source = $this->parent->getPath('source'); } // Install all necessary files if (count($this->manifest->files->children())) { $i = 0; foreach ($this->manifest->files->children() as $child) { $file = $source . '/' . $child; if (is_dir($file)) { // If it's actually a directory then fill it up $package = array(); $package['dir'] = $file; $package['type'] = JInstallerHelper::detectType($file); } else { // If it's an archive $package = JInstallerHelper::unpack($file); } $tmpInstaller = new JInstaller(); $installResult = $tmpInstaller->{$this->route}($package['dir']); if (!$installResult) { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file))); return false; } else { $results[$i] = array('name' => $tmpInstaller->manifest->name, 'result' => $installResult); } $i++; } } else { $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route)))); return false; } // Parse optional tags $this->parent->parseLanguages($this->manifest->languages); /* * --------------------------------------------------------------------------------------------- * Extension Registration * --------------------------------------------------------------------------------------------- */ $row = JTable::getInstance('extension'); $eid = $row->find(array('element' => strtolower($this->get('element')), 'type' => 'package')); if ($eid) { $row->load($eid); } else { $row->name = $this->get('name'); $row->type = 'package'; $row->element = $this->get('element'); // There is no folder for modules $row->folder = ''; $row->enabled = 1; $row->protected = 0; $row->access = 1; $row->client_id = 0; // Custom data $row->custom_data = ''; $row->params = $this->parent->getParams(); } // Update the manifest cache for the entry $row->manifest_cache = $this->parent->generateManifestCache(); if (!$row->store()) { // Install failed, roll back changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ROLLBACK', $row->getError())); return false; } /* * --------------------------------------------------------------------------------------------- * Finalization and Cleanup Section * --------------------------------------------------------------------------------------------- */ // Run the custom method based on the route ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $this->route)) { if ($this->parent->manifestClass->{$this->route}($this) === false) { // Install failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_FILE_INSTALL_CUSTOM_INSTALL_FAILURE')); return false; } } // Append messages $msg .= ob_get_contents(); ob_end_clean(); // Lastly, we will copy the manifest file to its appropriate place. $manifest = array(); $manifest['src'] = $this->parent->getPath('manifest'); $manifest['dest'] = JPATH_MANIFESTS . '/packages/' . basename($this->parent->getPath('manifest')); if (!$this->parent->copyFiles(array($manifest), true)) { // Install failed, rollback changes $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_COPY_SETUP', JText::_('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES'))); return false; } // If there is a manifest script, let's copy it. if ($this->get('manifest_script')) { // First, we have to create a folder for the script if one isn't present if (!file_exists($this->parent->getPath('extension_root'))) { JFolder::create($this->parent->getPath('extension_root')); } $path['src'] = $this->parent->getPath('source') . '/' . $this->get('manifest_script'); $path['dest'] = $this->parent->getPath('extension_root') . '/' . $this->get('manifest_script'); if (!file_exists($path['dest']) || $this->parent->isOverwrite()) { if (!$this->parent->copyFiles(array($path))) { // Install failed, rollback changes $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_PACKAGE_INSTALL_MANIFEST')); return false; } } } // And now we run the postflight ob_start(); ob_implicit_flush(false); if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'postflight')) { $this->parent->manifestClass->postflight($this->route, $this, $results); } // Append messages $msg .= ob_get_contents(); ob_end_clean(); if ($msg != '') { $this->parent->set('extension_message', $msg); } return $row->extension_id; }
/** * Installs an extension with the standard Joomla! installer. * * @throws EcrExceptionBuilder * @return EcrProjectBuilder */ private function install() { if ($this->testMode) { //-- Exiting in test mode $this->logger->log('TEST MODE - not installing'); return $this; } if ('cliapp' == $this->project->type || 'webapp' == $this->project->type) { $src = $this->buildDir . '/site'; $dest = $this->project->getExtensionPath(); if (false == JFolder::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy the JApplication from %s to %s', $src, $dest)); } $this->logger->log(sprintf('JApplication files copied from %s to %s', $src, $dest)); $src = $this->buildDir . DS . $this->project->getJoomlaManifestName(); $dest = $this->project->getJoomlaManifestPath() . DS . $this->project->getJoomlaManifestName(); if (false == JFile::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy package manifest xml from %s to %s', $src, $dest)); } return $this; } if ('package' == $this->project->type) { //-- J! 1.6 package - only copy the manifest xml $src = $this->buildDir . DS . $this->project->getJoomlaManifestName(); $dest = $this->project->getJoomlaManifestPath() . DS . $this->project->getJoomlaManifestName(); if (false == JFile::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy package manifest xml from %s to %s', $src, $dest)); } $this->logger->log(sprintf('Package manifest xml has been copied from %s to %s', $src, $dest)); return $this; } jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); $this->logger->log('Starting Install'); //-- Did you give us a valid package ? $type = JInstallerHelper::detectType($this->buildDir); if (false == $type) { throw new EcrExceptionBuilder(jgettext('Path does not have a valid package')); } //-- Get an installer instance $installer = JInstaller::getInstance(); //-- Install the package $result = $installer->install($this->buildDir); $this->logger->log('Installer Message: ' . $installer->message); $this->logger->log('Extension Message: ' . $installer->get('extension.message')); //-- Clean up the install directory. If we are not debugging. ECR_DEBUG ? null : JInstallerHelper::cleanupInstall('', $this->buildDir); //-- There was an error installing the package if (false == $result) { throw new EcrExceptionBuilder(sprintf(jgettext('An error happened while installing your %s'), jgettext($type))); } return $this; }