📄 installer.php
字号:
{
if (!isset($this->_adapters[$type]) || !is_object($this->_adapters[$type])) {
if (!$this->setAdapter($type)) {
return false;
}
}
if (is_object($this->_adapters[$type])) {
return $this->_adapters[$type]->uninstall($identifier, $cid);
}
return false;
}
/**
* Prepare for installation: this method sets the installation directory, finds
* and checks the installation file and verifies the installation type
*
* @access public
* @return boolean True on success
* @since 1.0
*/
function setupInstall()
{
// We need to find the installation manifest file
if (!$this->_findManifest()) {
return false;
}
// Load the adapter(s) for the install manifest
$root =& $this->_manifest->document;
$type = $root->attributes('type');
// Needed for legacy reasons ... to be deprecated in next minor release
if ($type == 'mambot') {
$type = 'plugin';
}
// Lazy load the adapter
if (!isset($this->_adapters[$type]) || !is_object($this->_adapters[$type])) {
if (!$this->setAdapter($type)) {
return false;
}
}
return true;
}
/**
* Backward compatible Method to parse through a queries element of the
* installation manifest file and take appropriate action.
*
* @access public
* @param object $element The xml node to process
* @return mixed Number of queries processed or False on error
* @since 1.5
*/
function parseQueries($element)
{
// Get the database connector object
$db = & $this->_db;
if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return 0;
}
// Get the array of query nodes to process
$queries = $element->children();
if (count($queries) == 0) {
// No queries to process
return 0;
}
// Process each query in the $queries array (children of $tagName).
foreach ($queries as $query)
{
$db->setQuery($query->data());
if (!$db->query()) {
JError::raiseWarning(1, 'JInstaller::install: '.JText::_('SQL Error')." ".$db->stderr(true));
return false;
}
}
return (int) count($queries);
}
/**
* 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
* @param string $version The database connector to use
* @return mixed Number of queries processed or False on error
* @since 1.5
*/
function parseSQLFiles($element)
{
// Initialize variables
$queries = array();
$db = & $this->_db;
$dbDriver = strtolower($db->get('name'));
if ($dbDriver == 'mysqli') {
$dbDriver = 'mysql';
}
$dbCharset = ($db->hasUTF()) ? 'utf8' : '';
if (!is_a($element, 'JSimpleXMLElement')) {
// The tag does not exist.
return 0;
}
// Get the array of file nodes to process
$files = $element->children();
if (count($files) == 0) {
// No files to process
return 0;
}
// Get the name of the sql file to process
$sqlfile = '';
foreach ($files as $file)
{
$fCharset = (strtolower($file->attributes('charset')) == 'utf8') ? 'utf8' : '';
$fDriver = strtolower($file->attributes('driver'));
if ($fDriver == 'mysqli') {
$fDriver = 'mysql';
}
if( $fCharset == $dbCharset && $fDriver == $dbDriver) {
$sqlfile = $file->data();
// Check that sql files exists before reading. Otherwise raise error for rollback
if ( !file_exists( $this->getPath('extension_administrator').DS.$sqlfile ) ) {
return false;
}
$buffer = file_get_contents($this->getPath('extension_administrator').DS.$sqlfile);
// Graceful exit and rollback if read not successful
if ( $buffer === false ) {
return false;
}
// Create an array of queries from the sql file
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) == 0) {
// No queries to process
return 0;
}
// Process each query in the $queries array (split out of sql file).
foreach ($queries as $query)
{
$query = trim($query);
if ($query != '' && $query{0} != '#') {
$db->setQuery($query);
if (!$db->query()) {
JError::raiseWarning(1, 'JInstaller::install: '.JText::_('SQL Error')." ".$db->stderr(true));
return false;
}
}
}
}
}
return (int) count($queries);
}
/**
* Method to parse through a files element of the installation manifest and take appropriate
* action.
*
* @access public
* @param object $element The xml node to process
* @param int $cid Application ID of application to install to
* @return boolean True on success
* @since 1.5
*/
function parseFiles($element, $cid=0)
{
// Initialize variables
$copyfiles = array ();
// Get the client info
jimport('joomla.application.helper');
$client =& JApplicationHelper::getClientInfo($cid);
if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return 0;
}
// Get the array of file nodes to process
$files = $element->children();
if (count($files) == 0) {
// No files to process
return 0;
}
/*
* Here we set the folder we are going to remove the files from.
*/
if ($client) {
$pathname = 'extension_'.$client->name;
$destination = $this->getPath($pathname);
} else {
$pathname = 'extension_root';
$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.
*/
if ($folder = $element->attributes('folder')) {
$source = $this->getPath('source').DS.$folder;
} else {
$source = $this->getPath('source');
}
// Process each file in the $files array (children of $tagName).
foreach ($files as $file)
{
$path['src'] = $source.DS.$file->data();
$path['dest'] = $destination.DS.$file->data();
// Is this path a file or folder?
$path['type'] = ( $file->name() == '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.
*/
if (basename($path['dest']) != $path['dest']) {
$newdir = dirname($path['dest']);
if (!JFolder::create($newdir)) {
JError::raiseWarning(1, 'JInstaller::install: '.JText::_('Failed to create directory').' "'.$newdir.'"');
return false;
}
}
// Add the file to the copyfiles array
$copyfiles[] = $path;
}
return $this->copyFiles($copyfiles);
}
/**
* Method to parse through a languages element of the installation manifest and take appropriate
* action.
*
* @access public
* @param object $element The xml node to process
* @param int $cid Application ID of application to install to
* @return boolean True on success
* @since 1.5
*/
function parseLanguages($element, $cid=0)
{
// Initialize variables
$copyfiles = array ();
// Get the client info
jimport('joomla.application.helper');
$client =& JApplicationHelper::getClientInfo($cid);
if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return 0;
}
// Get the array of file nodes to process
$files = $element->children();
if (count($files) == 0) {
// No files to process
return 0;
}
/*
* 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.
*/
if ($folder = $element->attributes('folder')) {
$source = $this->getPath('source').DS.$folder;
} else {
$source = $this->getPath('source');
}
// Process each file in the $files array (children of $tagName).
foreach ($files as $file)
{
/*
* Language files go in a subfolder based on the language code, ie.
*
* <language tag="en-US">en-US.mycomponent.ini</language>
*
* 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 ($file->attributes('tag') != '') {
$path['src'] = $source.DS.$file->data();
$path['dest'] = $destination.DS.$file->attributes('tag').DS.basename($file->data());
// If the language folder is not present, then the core pack hasn't been installed... ignore
if (!JFolder::exists(dirname($path['dest']))) {
$appl = &JFactory::getApplication();
$name = JText::_($appl->getName());
$warning = JText::sprintf('INSTALLER LANG NOT INSTALLED', $file->data(), $name, $file->attributes('tag') );
JError::raiseNotice(200, 'JInstaller::install: '.$warning);
continue;
}
} else {
$path['src'] = $source.DS.$file->data();
$path['dest'] = $destination.DS.$file->data();
}
/*
* 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']);
if (!JFolder::create($newdir)) {
JError::raiseWarning(1, 'JInstaller::install: '.JText::_('Failed to create directory').' "'.$newdir.'"');
return false;
}
}
// Add the file to the copyfiles array
$copyfiles[] = $path;
}
return $this->copyFiles($copyfiles);
}
/**
* Method to parse through a media element of the installation manifest and take appropriate
* action.
*
* @access public
* @param object $element The xml node to process
* @param int $cid Application ID of application to install to
* @return boolean True on success
* @since 1.5
*/
function parseMedia($element, $cid=0)
{
// Initialize variables
$copyfiles = array ();
// Get the client info
jimport('joomla.application.helper');
$client =& JApplicationHelper::getClientInfo($cid);
if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return 0;
}
// Get the array of file nodes to process
$files = $element->children();
if (count($files) == 0) {
// No files to process
return 0;
}
/*
* Here we set the folder we are going to copy the files to.
* Default 'media' Files are copied to the JPATH_BASE/images folder
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -