/**
* Method to extract the name of a discreet installation sql file from the installation manifest file.
*
* @param object $element The XML node to process
*
* @return mixed Number of queries processed or False on error
*
* @since 3.1
*/
public function parseSQLFiles($element)
{
if (!$element || !\count($element->children())) {
// The tag does not exist.
return 0;
}
$db =& $this->_db;
$dbDriver = $db->getServerType();
$update_count = 0;
// Get the name of the sql file to process
foreach ($element->children() as $file) {
$fCharset = strtolower($file->attributes()->charset) === 'utf8' ? 'utf8' : '';
$fDriver = strtolower($file->attributes()->driver);
if ($fDriver === 'mysqli' || $fDriver === 'pdomysql') {
$fDriver = 'mysql';
} elseif ($fDriver === 'pgsql') {
$fDriver = 'postgresql';
}
if ($fCharset === 'utf8' && $fDriver == $dbDriver) {
$sqlfile = $this->getPath('extension_root') . '/' . trim($file);
// Check that sql files exists before reading. Otherwise raise error for rollback
if (!file_exists($sqlfile)) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_SQL_FILENOTFOUND', $sqlfile), Log::WARNING, 'jerror');
return false;
}
$buffer = file_get_contents($sqlfile);
// Graceful exit and rollback if read not successful
if ($buffer === false) {
Log::add(Text::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'), Log::WARNING, 'jerror');
return false;
}
// Create an array of queries from the sql file
$queries = DatabaseDriver::splitSql($buffer);
if (\count($queries) === 0) {
// No queries to process
continue;
}
// Process each query in the $queries array (split out of sql file).
foreach ($queries as $query) {
try {
$db->setQuery($query)->execute();
} catch (ExecutionFailureException $e) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $e->getMessage()), Log::WARNING, 'jerror');
return false;
}
$update_count++;
}
}
}
return $update_count;
}