本文整理汇总了PHP中JInstallerHelper::splitSql方法的典型用法代码示例。如果您正苦于以下问题:PHP JInstallerHelper::splitSql方法的具体用法?PHP JInstallerHelper::splitSql怎么用?PHP JInstallerHelper::splitSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JInstallerHelper
的用法示例。
在下文中一共展示了JInstallerHelper::splitSql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runSQL
protected function runSQL($source, $file)
{
$db = JFactory::getDbo();
$driver = strtolower($db->name);
if ($driver == 'mysqli') {
$driver = 'mysql';
} elseif ($driver == 'sqlsrv') {
$driver = 'sqlazure';
}
$sqlfile = $source . '/sql/' . $driver . '/' . $file;
if (file_exists($sqlfile)) {
$buffer = file_get_contents($sqlfile);
if ($buffer !== false) {
$queries = JInstallerHelper::splitSql($buffer);
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
if (!$db->execute()) {
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
}
}
}
}
}
}
示例2: postflight
function postflight($type, $parent)
{
if ($type == 'update') {
$sqlfile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsform' . DS . 'install.rsform.utf8.sql';
$buffer = file_get_contents($sqlfile);
if ($buffer === false) {
JError::raiseWarning(1, JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'));
return false;
}
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) == 0) {
// No queries to process
return 0;
}
$db =& JFactory::getDBO();
// 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, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
return false;
}
}
}
}
}
示例3: update
function update($parent)
{
$db = JFactory::getDBO();
if (method_exists($parent, 'extension_root')) {
$sqlfile = $parent->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
} else {
$sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
// Don't modify below this line
$buffer = file_get_contents($sqlfile);
if ($buffer !== false) {
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) != 0) {
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
if (!$db->query()) {
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
return false;
}
}
}
}
}
echo '<p>' . JText::_('COM_COMMUNITYSURVEYS_UPDATE_TEXT') . '</p>';
$parent->getParent()->setRedirectURL('index.php?option=com_communitysurveys&view=dashboard');
}
示例4: update
function update($parent)
{
$db = JFactory::getDBO();
if (method_exists($parent, 'extension_root')) {
$sqlfile = $parent->getPath('extension_root') . '/sql/install.mysql.sql';
} else {
$sqlfile = $parent->getParent()->getPath('extension_root') . '/sql/install.mysql.sql';
}
// Don't modify below this line
$buffer = file_get_contents($sqlfile);
if ($buffer !== false) {
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) != 0) {
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
if (!$db->query()) {
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
return false;
}
}
}
}
}
}
示例5: installPluginTableByThemeName
function installPluginTableByThemeName($themeName)
{
jimport('joomla.filesystem.file');
$sqlFile = JPATH_PLUGINS . DS . $this->_pluginType . DS . $themeName . DS . $this->_installFile;
if (JFile::exists($sqlFile)) {
$objJNSUtils = JSNISFactory::getObj('classes.jsn_is_utils');
$buffer = $objJNSUtils->readFileToString($sqlFile);
if ($buffer === false) {
return false;
}
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) == 0) {
JError::raiseWarning(100, $sqlFile . JText::_(' not exits'));
return 0;
}
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$this->_db->setQuery($query);
if (!$this->_db->query()) {
JError::raiseWarning(100, 'JInstaller::install: ' . JText::_('SQL Error') . " " . $this->_db->stderr(true));
return false;
}
}
}
return true;
} else {
JError::raiseWarning(100, $sqlFile . JText::_(' not exits'));
return false;
}
}
示例6: querySQL
function querySQL($buffer)
{
$db =& JFactory::getDBO();
// 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 true;
}
示例7: update
function update($parent)
{
$db = JFactory::getDBO();
if (method_exists($parent, 'extension_root')) {
$sqlfile = $parent->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
} else {
$sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
// Don't modify below this line
$buffer = file_get_contents($sqlfile);
if ($buffer !== false) {
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) != 0) {
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
if (!$db->query()) {
CJFunctions::throw_error(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), 1);
return false;
}
}
}
}
}
echo '<p>' . JText::sprintf('COM_CJBLOG_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';
}
示例8: execute
/**
* Perform installation of SQL queries
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function execute()
{
// Get the temporary path from the server.
$tmpPath = $this->input->get('path', '', 'default');
// There should be a queries.zip archive in the archive.
$tmpQueriesPath = $tmpPath . '/queries.zip';
// Extract the queries
$path = $tmpPath . '/queries';
// If on development mode, skip this
if ($this->isDevelopment()) {
return $this->output($this->getResultObj('COM_EASYBLOG_INSTALLATION_DEVELOPER_MODE', true));
}
// Check if this folder exists.
if (JFolder::exists($path)) {
JFolder::delete($path);
}
// Extract the archive now
$state = JArchive::extract($tmpQueriesPath, $path);
if (!$state) {
$this->setInfo('COM_EASYBLOG_INSTALLATION_ERROR_UNABLE_EXTRACT_QUERIES', false);
return $this->output();
}
// Get the list of files in the folder.
$queryFiles = JFolder::files($path, '.', true, true);
// When there are no queries file, we should just display a proper warning instead of exit
if (!$queryFiles) {
$this->setInfo('COM_EASYBLOG_INSTALLATION_ERROR_EMPTY_QUERIES_FOLDER', false);
return $this->output();
}
$db = JFactory::getDBO();
$total = 0;
foreach ($queryFiles as $file) {
// Get the contents of the file
$contents = JFile::read($file);
$queries = JInstallerHelper::splitSql($contents);
foreach ($queries as $query) {
$query = trim($query);
if (!empty($query)) {
$db->setQuery($query);
$state = $db->execute();
}
}
$total += 1;
}
$this->setInfo(JText::sprintf('COM_EASYBLOG_INSTALLATION_SQL_EXECUTED_SUCCESS', $total), true);
return $this->output();
}
示例9: applyDump
public function applyDump($dump)
{
jimport("joomla.installer.helper");
jimport("joomla.version");
$version = new JVersion();
if ($version->RELEASE == "1.5") {
$helper = new JInstallerHelper();
$sql_statements = $helper->splitSql($dump);
} else {
//$helper = new JInstallerHelper();
$sql_statements = JInstallerHelper::splitSql($dump);
}
$db =& JFactory::getDBO();
$count = 0;
foreach ($sql_statements as $statement) {
if (trim($statement)) {
$db->setQuery($statement);
$db->query();
$count++;
}
}
return $count;
}
示例10: update
function update($parent)
{
$manifest = $parent->get('manifest');
$parent2 = $parent->getParent();
$source = $parent2->getPath('source');
$this->_installPlugins($manifest, $source, true);
// If a version prior to 0.5 has been installed, the database
// tables will not have the UUID fields set, so the tables must
// be rebuit
$hasUUID = false;
$db = JFactory::getDbo();
$blogFields = $db->getTableColumns('#__' . $this->component_base . '_blogs');
foreach ($blogFields['#__' . $this->component_base . '_blogs'] as $fieldname => $fieldtype) {
if ($fieldname == 'blog_uuid') {
$hasUUID = true;
break;
}
}
if (!$hasUUID) {
// All the database tables need to be rebuilt at this
// point
$sql = file_get_contents(dirname(__FILE__) . DS . 'admin' . DS . $manifest->install->sql->file);
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($sql);
if (count($queries) > 0) {
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
$db->execute();
}
}
}
echo '<p>' . JText::sprintf('COM_WORDBRIDGE_UPDATED_DB') . '123</p>';
}
echo '<p>' . JText::sprintf('COM_WORDBRIDGE_UPDATED_TO_VER', htmlspecialchars($manifest->version->data())) . '</p>';
}
示例11: runSQLFile
function runSQLFile($file)
{
jimport('joomla.filesystem.file');
if (JFile::exists($file)) {
$buffer = $this->readFileToString($file);
if ($buffer === false) {
return false;
}
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) == 0) {
JError::raiseWarning(100, $sqlFile . JText::_(' not exits'));
return 0;
}
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$this->_db->setQuery($query);
if (!$this->_db->query()) {
JError::raiseWarning(100, 'JInstaller::install: ' . JText::_('SQL Error') . " " . $this->_db->stderr(true));
return false;
}
}
}
return true;
} else {
JError::raiseWarning(100, $file . JText::_(' not exits'));
return false;
}
}
示例12: synchronizeDatabase
public function synchronizeDatabase()
{
$version = $this->input->getString('version');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
// Explicitly check for 1.0.0 since it is a flag to execute table creation
if ($version === '1.0.0') {
$path = SOCIAL_ADMIN . '/queries';
if (!JFolder::exists($path)) {
return $this->view->call(__FUNCTION__);
}
$files = JFolder::files($path, '.sql$', true, true);
$result = array();
$db = FD::db();
foreach ($files as $file) {
$contents = JFile::read($file);
$queries = JInstallerHelper::splitSql($contents);
foreach ($queries as $query) {
$query = trim($query);
if (!empty($query)) {
$db->setQuery($query);
$db->execute();
}
}
}
return $this->view->call(__FUNCTION__);
}
$path = SOCIAL_ADMIN . '/updates/' . $version;
$files = JFolder::files($path, '.json$', true, true);
$result = array();
foreach ($files as $file) {
$result = array_merge($result, FD::makeObject($file));
}
$tables = array();
$indexes = array();
$affected = 0;
$db = FD::db();
foreach ($result as $row) {
$columnExist = true;
$indexExist = true;
if (isset($row->column)) {
// Store the list of tables that needs to be queried
if (!isset($tables[$row->table])) {
$tables[$row->table] = $db->getTableColumns($row->table);
}
// Check if the column is in the fields or not
$columnExist = in_array($row->column, $tables[$row->table]);
}
if (isset($row->index)) {
if (!isset($indexes[$row->table])) {
$indexes[$row->table] = $db->getTableIndexes($row->table);
}
$indexExist = in_array($row->index, $indexes[$row->table]);
}
if (!$columnExist || !$indexExist) {
$sql = $db->sql();
$sql->raw($row->query);
$db->setQuery($sql);
$db->query();
$affected += 1;
}
}
return $this->view->call(__FUNCTION__);
}
示例13: doInstall
public static function doInstall(JInstallerComponent &$component)
{
// fix joomla 1.5 bug
$component->parent->getDBO = $component->parent->getDBO();
// initialize zoo framework
require_once $component->parent->getPath('source') . '/admin/config.php';
// sanatize table indexes
$index_sql_path = $component->parent->getPath('source') . '/admin/installation/index.sql';
if (JFile::exists($index_sql_path)) {
$db = YDatabase::getInstance();
// read index.sql
$buffer = JFile::read($index_sql_path);
// Create an array of queries from the sql file
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (!empty($queries)) {
foreach ($queries as $query) {
// replace table prefixes
$query = $db->replacePrefix($query);
// parse table name
preg_match('/ALTER\\s*TABLE\\s*`(.*)`/i', $query, $result);
if (count($result) < 2) {
continue;
}
$table = $result[1];
// get existing indexes
$indexes = $db->queryObjectList('SHOW INDEX FROM ' . $table);
// drop existing indexes
$removed = array();
foreach ($indexes as $index) {
if (in_array($index->Key_name, $removed)) {
continue;
}
if ($index->Key_name != 'PRIMARY') {
$db->query('DROP INDEX ' . $index->Key_name . ' ON ' . $table);
$removed[] = $index->Key_name;
}
}
// add new indexes
$db->query($query);
}
}
}
// applications
if (!JFolder::exists(ZOO_APPLICATION_PATH)) {
JFolder::create(ZOO_APPLICATION_PATH);
}
$applications = array();
foreach (JFolder::folders($component->parent->getPath('source') . '/applications', '.', false, true) as $folder) {
try {
if ($manifest = InstallHelper::findManifest($folder)) {
$name = InstallHelper::getName($manifest);
$status = InstallHelper::installApplicationFromFolder($folder);
$applications[] = compact('name', 'status');
}
} catch (YException $e) {
$name = basename($folder);
$status = false;
$applications[] = compact('name', 'status');
}
}
self::displayResults($applications, 'Applications', 'Application');
// additional extensions
// init vars
$error = false;
$extensions = array();
// get plugin files
$plugin_files = array();
foreach (YFile::readDirectoryFiles(JPATH_PLUGINS, JPATH_PLUGINS . '/', '/\\.php$/', true) as $file) {
$plugin_files[] = basename($file);
}
// get extensions
if (isset($component->manifest->additional[0])) {
$add = $component->manifest->additional[0];
if (count($add->children())) {
$exts = $add->children();
foreach ($exts as $ext) {
$installer = new JInstaller();
$installer->setOverwrite(true);
$update = false;
if ($ext->name() == 'module' && JFolder::exists(JPATH_ROOT . '/modules/' . $ext->attributes('name')) || $ext->name() == 'plugin' && in_array($ext->attributes('name') . '.php', $plugin_files)) {
$update = true;
}
$folder = $component->parent->getPath('source') . '/' . $ext->attributes('folder');
$folder = rtrim($folder, "\\/") . '/';
if (JFolder::exists($folder)) {
if ($update) {
foreach (YFile::readDirectoryFiles($folder, $folder, '/positions\\.config$/', true) as $file) {
JFile::delete($file);
}
}
$extensions[] = array('name' => $ext->data(), 'type' => $ext->name(), 'folder' => $folder, 'installer' => $installer, 'status' => false, 'update' => $update);
}
}
}
}
// install additional extensions
for ($i = 0; $i < count($extensions); $i++) {
if (is_dir($extensions[$i]['folder'])) {
if (@$extensions[$i]['installer']->install($extensions[$i]['folder'])) {
//.........这里部分代码省略.........
示例14: restore
/**
* Restores a backup from sql dump file
*
* @param array $file The sql dump file
*
* @return boolean true on success
*
* @since 2.0
*/
public function restore($file)
{
if (JFile::exists($file)) {
$db = $this->app->database;
// read index.sql
$buffer = file_get_contents($file);
// Create an array of queries from the sql file
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (!empty($queries)) {
foreach ($queries as $query) {
$query = trim($query);
if (!empty($query)) {
$db->query($query);
}
}
return true;
}
}
throw new RuntimeException("File not found ({$file})");
}
示例15: prepareAvailableFields
/**
* Prepare for available fields importing.
*
* 1. Set all tables to be indexed
* 2. Empty the available fields table
* 3. Import the extra availablefields sql file
* 4. Find what tables need to be imported and store them in the session
*
* @copyright
* @author RolandD
* @todo
* @see CsviModelSettings::save
* @access public
* @param
* @return
* @since 3.5
*/
public function prepareAvailableFields()
{
$db = JFactory::getDbo();
$jinput = JFactory::getApplication()->input;
// Load the session data
$session = JFactory::getSession();
$option = $jinput->get('option');
$csvilog = $jinput->get('csvilog', null, null);
// Clean the session
$session->set($option . '.csvilog', serialize('0'));
// Set all tables to be indexed
$query = $db->getQuery(true);
$query->update('#__csvi_template_tables');
$query->set('indexed = 0');
$db->setQuery($query);
$db->query();
// Empty the available fields first
$q = "TRUNCATE TABLE " . $db->qn('#__csvi_available_fields');
$db->setQuery($q);
if ($db->query()) {
$csvilog->AddStats('empty', JText::_('COM_CSVI_AVAILABLE_FIELDS_TABLE_EMPTIED'));
} else {
$csvilog->AddStats('error', JText::_('COM_CSVI_AVAILABLE_FIELDS_TABLE_COULD_NOT_BE_EMPTIED'));
}
// Do component specific updates
$override = new stdClass();
$override->value = 'override';
$components = CsviHelper::getComponents();
$components[] = $override;
jimport('joomla.filesystem.file');
foreach ($components as $component) {
switch ($component->value) {
case 'mod_vm_cherry_picker':
// Delete any existing entries
$query = $db->getQuery(true);
$query->delete('#__csvi_template_tables')->where($db->qn('component') . ' = ' . $db->q('mod_vm_cherry_picker'))->where($db->qn('template_table') . ' REGEXP ' . $db->q('vm_product_type_[0-9]'));
$db->setQuery($query);
$db->query();
// Add new entries
$name_tables = $db->getTableList();
$query = $db->getQuery(true);
$validq = false;
$query->insert('#__csvi_template_tables')->columns(array('template_type_name', 'template_table', 'component', 'indexed'));
foreach ($name_tables as $nkey => $name_table) {
if (strpos($name_table, $db->getPrefix() . 'vm_product_type') !== false) {
if (stristr('0123456789', substr($name_table, -1))) {
$validq = true;
$name = str_ireplace($db->getPrefix(), '', $name_table);
$query->values($db->q('producttypenamesexport') . ',' . $db->q($name) . ',' . $db->q('mod_vm_cherry_picker') . ',0');
$query->values($db->q('producttypenamesimport') . ',' . $db->q($name) . ',' . $db->q('mod_vm_cherry_picker') . ',0');
}
}
}
if ($validq) {
$db->setQuery($query);
$db->query();
}
break;
}
// Process all extra available fields
$filename = JPATH_COMPONENT_ADMINISTRATOR . '/install/availablefields/' . $component->value . '.sql';
if (JFile::exists($filename)) {
// Check if the component is installed
$ext_id = false;
$query = $db->getQuery(true)->select($db->qn('extension_id'))->from($db->qn('#__extensions'))->where($db->qn('element') . '=' . $db->q($component->value));
$db->setQuery($query);
$ext_id = $db->loadResult();
if ($ext_id) {
$queries = JInstallerHelper::splitSql(JFile::read($filename));
foreach ($queries as $q) {
$db->setQuery($q);
if ($db->query()) {
$result = true;
} else {
$result = false;
}
}
if ($result) {
$csvilog->AddStats('added', JText::sprintf('COM_CSVI_CUSTOM_AVAILABLE_FIELDS_HAVE_BEEN_ADDED', JText::_('COM_CSVI_' . $component->value)));
} else {
$csvilog->AddStats('error', JText::sprintf('COM_CSVI_CUSTOM_AVAILABLE_FIELDS_HAVE_NOT_BEEN_ADDED', JText::_('COM_CSVI_' . $component->value)));
}
}
//.........这里部分代码省略.........