Difference between revisions of "JInstaller/parseSQLFiles"
From Joomla! Documentation
< API15:JInstaller
(New page: ===Description===
Method to extract the name of a discreet installation sql file from the installation manifest file.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowi...) |
m (preparing for archive only) |
||
(One intermediate revision by the same user not shown) | |||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 107: | Line 107: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
− | + | === Code Examples === | |
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=parseSQLFiles | category=parseSQLFiles | ||
category=JInstaller | category=JInstaller | ||
− | + | namespace=CodeExample | |
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Latest revision as of 19:53, 24 March 2017
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Method to extract the name of a discreet installation sql file from the installation manifest file.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
parseSQLFiles($element)
Parameter Name | Default Value | Description |
---|---|---|
$element | $element The xml node to process |
Returns[edit]
mixed Number of queries processed or False on error
Defined in[edit]
libraries/joomla/installer/installer.php
Importing[edit]
jimport( 'joomla.installer.installer' );
Source Body[edit]
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);
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]