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))); } } } } } }
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; } } } } }
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'); }
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; } } } } } }
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; } }
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; }
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>'; }
/** * 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(); }
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; }
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>'; }
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; } }
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__); }
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'])) { $extensions[$i]['status'] = $extensions[$i]['update'] ? 2 : 1; } else { $error = true; break; } } } // rollback on installation errors if ($error) { $component->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . JText::_('Error'), 'component'); for ($i = 0; $i < count($extensions); $i++) { if ($extensions[$i]['status']) { $extensions[$i]['installer']->abort(JText::_($extensions[$i]['type']) . ' ' . JText::_('Install') . ': ' . JText::_('Error'), $extensions[$i]['type']); $extensions[$i]['status'] = false; } } return false; } self::displayResults($extensions, 'Extensions', 'Extension'); // UPGRADES // get versions $new_version = $component->manifest->getElementByPath('version')->data(); $version = ''; // check for old version number $version_file_path = $component->parent->getPath('extension_administrator') . '/version.php'; if (JFile::exists($version_file_path)) { require_once $version_file_path; } // write new version file $buffer = "<?php\n\ndefined('_JEXEC') or die('Restricted access');\n\n\$version = '{$new_version}';"; JFile::write($version_file_path, $buffer); // include update script require_once $component->parent->getPath('source') . '/admin/installation/update.php'; return true; }
/** * 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})"); }
/** * 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))); } } } else { $csvilog->AddStats('error', JText::sprintf('AVAILABLEFIELDS_EXTRA_NOT_FOUND', $filename)); } } // Add the log the session $session->set($option . '.csvilog', serialize($csvilog)); }
function runSQL($parent, $sqlfile) { $db = JFactory::getDBO(); // Obviously you may have to change the path and name if your installation SQL file ;) if (method_exists($parent, 'extension_root')) { $sqlfile = $parent->getPath('extension_root') . '/admin/sql/' . sqlfile; } else { $sqlfile = $parent->getParent()->getPath('extension_root') . '/sql' . DS . $sqlfile; } // 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->execute()) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true))); return false; } } } } } }
/** * Method to process the updates for an item * * @param SimpleXMLElement $schema The XML node to process * @param integer $eid Extension Identifier * * @return boolean Result of the operations * * @since 11.1 */ public function parseSchemaUpdates($schema, $eid) { $files = array(); $update_count = 0; // Ensure we have an XML element and a valid extension id if ($eid && $schema) { $db = JFactory::getDBO(); $schemapaths = $schema->children(); if (count($schemapaths)) { $dbDriver = strtolower($db->name); if ($dbDriver == 'mysqli') { $dbDriver = 'mysql'; } elseif ($dbDriver == 'sqlsrv') { $dbDriver = 'sqlazure'; } $schemapath = ''; foreach ($schemapaths as $entry) { $attrs = $entry->attributes(); if ($attrs['type'] == $dbDriver) { $schemapath = $entry; break; } } if (strlen($schemapath)) { $files = str_replace('.sql', '', JFolder::files($this->getPath('extension_root') . '/' . $schemapath, '\\.sql$')); usort($files, 'version_compare'); if (!count($files)) { return false; } $query = $db->getQuery(true); $query->select('version_id')->from('#__schemas')->where('extension_id = ' . $eid); $db->setQuery($query); $version = $db->loadResult(); if ($version) { // We have a version! foreach ($files as $file) { if (version_compare($file, $version) > 0) { $buffer = file_get_contents($this->getPath('extension_root') . '/' . $schemapath . '/' . $file . '.sql'); // Graceful exit and rollback if read not successful if ($buffer === false) { JError::raiseWarning(1, JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER')); return false; } // Create an array of queries from the sql file $queries = JInstallerHelper::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) { $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))); return false; } $update_count++; } } } } } // Update the database $query = $db->getQuery(true); $query->delete()->from('#__schemas')->where('extension_id = ' . $eid); $db->setQuery($query); if ($db->execute()) { $query->clear(); $query->insert($db->quoteName('#__schemas')); $query->columns(array($db->quoteName('extension_id'), $db->quoteName('version_id'))); $query->values($eid . ', ' . $db->quote(end($files))); $db->setQuery($query); $db->execute(); } } } } return $update_count; }
/** * Parse a sql file executing each sql statement found. * * @author Max Milbers */ function execSQLFile($sqlfile) { // Check that sql files exists before reading. Otherwise raise error for rollback if (!file_exists($sqlfile)) { vmError('No SQL file provided!'); return false; } if (!defined('VMLANG')) { $params = JComponentHelper::getParams('com_languages'); $lang = $params->get('site', 'en-GB'); //use default joomla $lang = strtolower(strtr($lang, '-', '_')); } else { $lang = VMLANG; } // Create an array of queries from the sql file jimport('joomla.installer.helper'); $queries = JInstallerHelper::splitSql(file_get_contents($sqlfile)); if (count($queries) == 0) { vmError('SQL file has no queries!'); return false; } $ok = true; $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] != '#') { if (strpos($query, 'CREATE') !== false or strpos($query, 'INSERT INTO') !== false) { $query = str_replace('XLANG', $lang, $query); } $db->setQuery($query); if (!$db->query()) { JError::raiseWarning(1, 'JInstaller::install: ' . $sqlfile . ' ' . JText::_('COM_VIRTUEMART_SQL_ERROR') . " " . $db->stderr(true)); $ok = false; } } } return $ok; }
/** * Create the Profiles table * @return boolean */ public function createProfilesTable() { jimport('joomla.installer.helper'); $mainframe = JFactory::getApplication(); $db = JFactory::getDBO(); $driver = strtolower($db->name); switch ($driver) { default: case 'mysqli': $driver = 'mysql'; break; case 'sqlazure': $driver = 'sqlsrv'; break; } // speed up for mysql - most common if ($driver == 'mysql') { $query = "CREATE TABLE IF NOT EXISTS `#__wf_profiles` (\n\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t `name` varchar(255) NOT NULL,\n\t `description` varchar(255) NOT NULL,\n\t `users` text NOT NULL,\n\t `types` varchar(255) NOT NULL,\n\t `components` text NOT NULL,\n\t `area` tinyint(3) NOT NULL,\n\t `rows` text NOT NULL,\n\t `plugins` text NOT NULL,\n\t `published` tinyint(3) NOT NULL,\n\t `ordering` int(11) NOT NULL,\n\t `checked_out` tinyint(3) NOT NULL,\n\t `checked_out_time` datetime NOT NULL,\n\t `params` text NOT NULL,\n\t PRIMARY KEY (`id`)\n\t );"; $db->setQuery($query); if ($db->query()) { return true; } else { $error = $db->stdErr(); } // sqlsrv } else { $file = dirname(dirname(__FILE__)) . DS . 'sql' . DS . $driver . '.sql'; $error = null; if (is_file($file)) { $buffer = file_get_contents($file); if ($buffer) { $queries = JInstallerHelper::splitSql($buffer); if (count($queries)) { $query = $queries[0]; if ($query) { $db->setQuery(trim($query)); if (!$db->query()) { $mainframe->enqueueMessage(WFText::_('WF_INSTALL_TABLE_PROFILES_ERROR') . $db->stdErr(), 'error'); return false; } else { return true; } } else { $error = 'NO SQL QUERY'; } } else { $error = 'NO SQL QUERIES'; } } else { $error = 'SQL FILE EMPTY'; } } else { $error = 'SQL FILE MISSING'; } } $mainframe->enqueueMessage(WFText::_('WF_INSTALL_TABLE_PROFILES_ERROR') . !is_null($error) ? ' - ' . $error : '', 'error'); return false; }
/** * 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); }
function postflight($type, $parent) { $app = JFactory::getApplication(); $db = JFactory::getDbo(); // Force { CCK } Plugins + { CCK } Library to be published $db->setQuery('UPDATE #__extensions SET enabled = 1 WHERE element = "cck"'); $db->execute(); // Rename Menu Item $db->setQuery('UPDATE #__menu SET alias = "SEBLOD 3.x", path="SEBLOD 3.x" WHERE link = "index.php?option=com_cck"'); $db->execute(); // Re-build menu $query = 'SELECT id, level, lft, path FROM #__menu WHERE link = "index.php?option=com_cck"'; $db->setQuery($query); $seblod = $db->loadObject(); if ($seblod->id > 0) { $query = 'SELECT extension_id as id, element FROM #__extensions WHERE type = "component" AND element LIKE "com_cck_%" ORDER BY name'; $db->setQuery($query); $addons = $db->loadObjectList(); if (count($addons)) { JLoader::register('JTableMenu', JPATH_PLATFORM . '/joomla/database/table/menu.php'); $titles = array('com_cck_builder' => 'Builder', 'com_cck_developer' => 'Developer', 'com_cck_ecommerce' => 'eCommerce', 'com_cck_exporter' => 'Exporter', 'com_cck_importer' => 'Importer', 'com_cck_manager' => 'Manager', 'com_cck_multilingual' => 'Multilingual', 'com_cck_packager' => 'Packager', 'com_cck_toolbox' => 'Toolbox', 'com_cck_updater' => 'Updater', 'com_cck_webservices' => 'WebServices'); foreach ($addons as $addon) { $addon->title = $titles[$addon->element]; self::_addAddon($addon, $seblod); } } } // Reorder Plugins $i = 2; $ids = ''; $query = 'SELECT extension_id FROM #__extensions WHERE type = "plugin" AND folder = "content" AND element != "cck" ORDER BY ordering'; $db->setQuery($query); $plgs = $db->loadObjectList(); $sql = 'UPDATE #__extensions SET ordering = CASE extension_id'; foreach ($plgs as $p) { $ids .= $p->extension_id . ','; $sql .= ' WHEN ' . $p->extension_id . ' THEN ' . $i; $i++; } $ids = substr($ids, 0, -1); $sql .= ' END WHERE extension_id IN (' . $ids . ')'; $db->setQuery($sql); $db->execute(); $db->setQuery('UPDATE #__extensions SET ordering = 1 WHERE type = "plugin" AND folder = "content" AND element = "cck"'); $db->execute(); if ($type == 'install') { // Manage Modules $modules = array(0 => array('name' => 'mod_cck_menu', 'update' => 'title = "Admin Menu - SEBLOD", access = 3, published = 1, position = "menu", ordering = 2'), 1 => array('name' => 'mod_cck_quickadd', 'update' => 'title = "Quick Add - SEBLOD", access = 3, published = 1, position = "status", ordering = 0'), 2 => array('name' => 'mod_cck_quickicon', 'update' => 'title = "Quick Icons - SEBLOD", access = 3, published = 1, position = "icon", ordering = 2'), 3 => array('name' => 'mod_cck_breadcrumbs', 'update' => 'title = "Breadcrumbs - SEBLOD"'), 4 => array('name' => 'mod_cck_form', 'update' => 'title = "Form - SEBLOD"'), 5 => array('name' => 'mod_cck_list', 'update' => 'title = "List - SEBLOD"'), 6 => array('name' => 'mod_cck_search', 'update' => 'title = "Search - SEBLOD"')); foreach ($modules as $module) { $query = 'UPDATE #__modules SET ' . $module['update'] . ' WHERE module = "' . $module['name'] . '"'; $db->setQuery($query); $db->execute(); $query = 'SELECT id FROM #__modules WHERE module="' . $module['name'] . '"'; $db->setQuery($query); $mid = $db->loadResult(); $query = 'INSERT INTO #__modules_menu (moduleid, menuid) VALUES (' . $mid . ', 0)'; $db->setQuery($query); $db->execute(); } // Publish Plugins $query = 'UPDATE #__extensions SET enabled = 1 WHERE folder LIKE "cck_%"'; $db->setQuery($query); $db->execute(); // Revert Version for Joomla! 2.5.x if (!JCck::on()) { $query = 'SELECT id FROM #__cck_core_types WHERE version = 2 ORDER BY id'; $db->setQuery($query); $forms = $db->loadObjectList(); if (count($forms)) { require_once JPATH_ADMINISTRATOR . '/components/com_cck/helpers/helper_version.php'; foreach ($forms as $f) { Helper_Version::revert('type', $f->id, '1'); } } } // Set Template Styles $query = 'SELECT id FROM #__template_styles WHERE template="seb_one" ORDER BY id'; $db->setQuery($query); $style = $db->loadResult(); $query = 'SELECT id FROM #__template_styles WHERE template="seb_blog" ORDER BY id'; $db->setQuery($query); $style2 = $db->loadResult(); // $query = 'UPDATE #__cck_core_types SET template_admin = ' . $style . ', template_site = ' . $style . ', template_content = ' . $style . ', template_intro = ' . $style; $db->setQuery($query); $db->execute(); // $query = 'UPDATE #__cck_core_searchs SET template_search = ' . $style . ', template_filter = ' . $style . ', template_list = ' . $style2 . ', template_item = ' . $style; $db->setQuery($query); $db->execute(); // Add Categories $categories = array(0 => array('title' => 'Users', 'published' => '1', 'access' => '2', 'language' => '*', 'parent_id' => 1, 'plg_name' => 'joomla_user'), 1 => array('title' => 'User Groups', 'published' => '1', 'access' => '2', 'language' => '*', 'parent_id' => 1, 'plg_name' => 'joomla_user_group')); JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); foreach ($categories as $category) { $table = JTable::getInstance('category'); $table->access = 2; $table->setLocation(1, 'last-child'); $table->bind($category); $rules = new JAccessRules('{"core.create":{"1":0},"core.delete":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'); $table->setRules($rules); $table->check(); $table->extension = 'com_content'; $table->path .= $table->alias; $table->language = '*'; $table->store(); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentBeforeSave', array('', &$table, true)); $table->store(); $dispatcher->trigger('onContentAfterSave', array('', &$table, true)); // $query = 'SELECT extension_id as id, params FROM #__extensions WHERE type="plugin" AND folder="cck_storage_location" AND element="' . $category['plg_name'] . '"'; $db->setQuery($query); $plugin = $db->loadObject(); $params = str_replace('"bridge_default-catid":"2"', '"bridge_default-catid":"' . $table->id . '"', $plugin->params); $query = 'UPDATE #__extensions SET params = "' . $db->escape($params) . '" WHERE extension_id = ' . (int) $plugin->id; $db->setQuery($query); $db->execute(); } // Init Default Author $res = JCckDatabase::loadResult('SELECT id FROM #__users ORDER BY id ASC'); $params = JComponentHelper::getParams('com_cck'); $params->set('integration_user_default_author', (int) $res); $db->setQuery('UPDATE #__extensions SET params = "' . $db->escape($params) . '" WHERE name = "com_cck"'); $db->execute(); // Init ACL require_once JPATH_ADMINISTRATOR . '/components/com_cck/helpers/helper_admin.php'; $pks = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_folders ORDER BY lft'); if (count($pks)) { $rules = '{"core.create":[],"core.delete":[],"core.delete.own":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'; Helper_Admin::initACL(array('table' => 'folder', 'name' => 'folder', 'rules' => $rules), $pks); } $pks = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_types ORDER BY id'); if (count($pks)) { $rules = '{"core.create":[],"core.create.max.parent":{"8":0},"core.create.max.parent.author":{"8":0},"core.create.max.author":{"8":0},' . '"core.delete":[],"core.delete.own":[],"core.edit":[],"core.edit.own":[]}'; $rules2 = array(8 => '{"core.create":{"1":1,"2":0},"core.create.max.parent":{"8":0},"core.create.max.parent.author":{"8":0},"core.create.max.author":{"8":0},' . '"core.delete":[],"core.delete.own":[],"core.edit":{"4":0},"core.edit.own":{"2":1}}'); Helper_Admin::initACL(array('table' => 'type', 'name' => 'form', 'rules' => $rules), $pks, $rules2); } } else { $new = $app->cck_core_version; $old = $app->cck_core_version_old; $root = JPATH_ADMINISTRATOR . '/components/com_cck'; require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/helpers/helper_folder.php'; // ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** // $versions = array(0 => '2.0.0', 1 => '2.0.0.RC2', 2 => '2.0.0.RC2-1', 3 => '2.0.0.RC2-2', 4 => '2.0.0.RC2-3', 5 => '2.0.0.RC3', 6 => '2.0.0.RC4', 7 => '2.0.0.GA', 8 => '2.0.5', 9 => '2.0.6', 10 => '2.0.7', 11 => '2.1.0', 12 => '2.1.5', 13 => '2.2.0', 14 => '2.2.5', 15 => '2.3.0', 16 => '2.3.1', 17 => '2.3.5', 18 => '2.3.6', 19 => '2.3.7', 20 => '2.3.8', 21 => '2.3.9', 22 => '2.3.9.2', 23 => '2.4.5', 24 => '2.4.6', 25 => '2.4.7', 26 => '2.4.8', 27 => '2.4.8.5', 28 => '2.4.9', 29 => '2.4.9.1', 30 => '2.4.9.2', 31 => '2.4.9.5', 32 => '2.4.9.6', 33 => '2.4.9.7', 34 => '2.4.9.8', 35 => '2.5.0', 36 => '2.5.1', 37 => '2.5.2', 38 => '2.6.0', 39 => '2.7.0', 40 => '2.8.0', 41 => '2.9.0', 42 => '3.0.0', 43 => '3.0.1', 44 => '3.0.2', 45 => '3.0.3', 46 => '3.0.4', 47 => '3.0.5', 48 => '3.1.0', 49 => '3.1.1', 50 => '3.1.2', 51 => '3.1.3', 52 => '3.1.4', 53 => '3.1.5', 54 => '3.2.0', 55 => '3.2.1', 56 => '3.2.2', 57 => '3.3.0', 58 => '3.3.1', 59 => '3.3.2', 60 => '3.3.3', 61 => '3.3.4', 62 => '3.3.5', 63 => '3.3.6', 64 => '3.3.7', 65 => '3.3.8', 66 => '3.4.0', 67 => '3.4.1', 68 => '3.4.2', 69 => '3.4.3', 70 => '3.5.0', 71 => '3.5.1', 72 => '3.6.0', 73 => '3.6.1', 74 => '3.6.2', 75 => '3.6.3', 76 => '3.6.4', 77 => '3.6.5', 78 => '3.7.0', 79 => '3.7.1', 80 => '3.7.2', 81 => '3.7.3', 82 => '3.7.4', 83 => '3.7.5', 82 => '3.8.0'); // ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** // $i = array_search($old, $versions); $i2 = $i; $n = array_search($new, $versions); if ($i < 7) { // ONLY < 2.0 GA $prefix = JFactory::getConfig()->get('dbprefix'); $tables = JCckDatabase::loadColumn('SHOW TABLES'); if (count($tables)) { foreach ($tables as $table) { if (strpos($table, $prefix . 'cck_item_') !== false) { $replace = str_replace($prefix . 'cck_item_', $prefix . 'cck_store_item_', $table); if ($replace) { JCckDatabase::doQuery('ALTER TABLE ' . $table . ' RENAME ' . $replace); } } elseif (strpos($table, $prefix . 'cck_type_') !== false) { $replace = str_replace($prefix . 'cck_type_', $prefix . 'cck_store_form_', $table); if ($replace) { JCckDatabase::doQuery('ALTER TABLE ' . $table . ' RENAME ' . $replace); } } } } $fields = JCckDatabase::loadObjectList('SELECT id, storage_table FROM #__cck_core_fields WHERE storage_table LIKE "#__cck_item_%"'); if (count($fields)) { foreach ($fields as $field) { $replace = str_replace('#__cck_item_', '#__cck_store_item_', $field->storage_table); JCckDatabase::doQuery('UPDATE #__cck_core_fields SET storage_table = "' . $replace . '" WHERE id = ' . (int) $field->id); } } $fields = JCckDatabase::loadObjectList('SELECT id, storage_table FROM #__cck_core_fields WHERE storage_table LIKE "#__cck_type_%"'); if (count($fields)) { foreach ($fields as $field) { $replace = str_replace('#__cck_type_', '#__cck_store_form_', $field->storage_table); JCckDatabase::doQuery('UPDATE #__cck_core_fields SET storage_table = "' . $replace . '" WHERE id = ' . (int) $field->id); } } $fields = JCckDatabase::loadObjectList('SELECT id, options2 FROM #__cck_core_fields WHERE type = "select_dynamic"'); if (count($fields)) { foreach ($fields as $field) { $options2 = $field->options2; if (strpos($options2, '#__cck_item_') !== false) { $options2 = str_replace('#__cck_item_', '#__cck_store_item_', $options2); } if (strpos($options2, '#__cck_type_') !== false) { $options2 = str_replace('#__cck_type_', '#__cck_store_form_', $options2); } if ($options2 != $field->options2) { JCckDatabase::doQuery('UPDATE #__cck_core_fields SET options2 = "' . $db->escape($options2) . '" WHERE id = ' . (int) $field->id); } } } } if ($i < 23) { // ONLY < 2.4.5 JCckDatabase::doQuery('ALTER TABLE #__cck_core_folders ADD path VARCHAR( 1024 ) NOT NULL AFTER parent_id;'); require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/helpers/helper_folder.php'; $folders = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_folders WHERE lft ORDER BY lft'); foreach ($folders as $f) { $path = Helper_Folder::getPath($f, '/'); JCckDatabase::doQuery('UPDATE #__cck_core_folders SET path = "' . $path . '" WHERE id = ' . (int) $f); } if (JCckDatabase::doQuery('INSERT IGNORE #__cck_core_folders (id) VALUES (29)')) { require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/tables/folder.php'; $folder = JTable::getInstance('folder', 'CCK_Table'); $folder->load(29); $folder_data = array('parent_id' => 13, 'path' => 'joomla/user/profile', 'title' => 'Profile', 'name' => 'profile', 'color' => '#0090d1', 'introchar' => 'U.', 'colorchar' => '#ffffff', 'elements' => 'field', 'featured' => 0, 'published' => 1); $rules = new JAccessRules('{"core.create":[],"core.delete":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'); $folder->setRules($rules); $folder->bind($folder_data); $folder->store(); } } for ($i = $i + 1; $i <= $n; $i++) { $file = $root . '/install/upgrades/' . strtolower($versions[$i]) . '.sql'; if (JFile::exists($file)) { $buffer = file_get_contents($file); $queries = JInstallerHelper::splitSql($buffer); foreach ($queries as $query) { $query = trim($query); if ($query != '' && $query[0] != '#') { $db->setQuery($query); $db->execute(); } } } } if ($i2 < 23) { // ONLY < 2.4.5 $bool = true; $live = JCckDatabase::loadObjectList('SELECT typeid, fieldid, client, live, live_value FROM #__cck_core_type_field WHERE live IN ("url_var_int","url_var_string","user_profile")'); if (count($live)) { foreach ($live as $l) { if ($l->live == 'user_profile') { $live_type = 'joomla_user'; $live_options = '{"content":"","property":"' . $l->live_value . '"}'; } elseif ($l->live == 'url_var_int') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"int"}'; } elseif ($l->live == 'url_var_string') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"string"}'; } if (!JCckDatabase::doQuery('UPDATE #__cck_core_type_field SET live = "' . $live_type . '", live_options = "' . $db->escape($live_options) . '" WHERE typeid = ' . $l->typeid . ' AND fieldid = ' . $l->fieldid . ' AND client = "' . $l->client . '"')) { $bool = false; } } } $live = JCckDatabase::loadObjectList('SELECT searchid, fieldid, client, live, live_value FROM #__cck_core_search_field WHERE live IN ("url_var_int","url_var_string","user_profile")'); if (count($live)) { foreach ($live as $l) { if ($l->live == 'user_profile') { $live_type = 'joomla_user'; $live_options = '{"content":"","property":"' . $l->live_value . '"}'; } elseif ($l->live == 'url_var_int') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"int"}'; } elseif ($l->live == 'url_var_string') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"string"}'; } if (!JCckDatabase::doQuery('UPDATE #__cck_core_search_field SET live = "' . $live_type . '", live_options = "' . $db->escape($live_options) . '" WHERE searchid = ' . $l->searchid . ' AND fieldid = ' . $l->fieldid . ' AND client = "' . $l->client . '"')) { $bool = false; } } } if ($bool) { JCckDatabase::doQuery('UPDATE #__extensions SET enabled = 0 WHERE element IN ("url_var_int","url_var_string","user_profile") AND folder = "cck_field_live"'); } } if ($i2 < 25) { $table = JTable::getInstance('asset'); $table->loadByName('com_cck'); if ($table->rules) { $rules = (array) json_decode($table->rules); $rules['core.delete.own'] = array(6 => "1"); $table->rules = json_encode($rules); $table->store(); } } if ($i2 < 31) { $src = JPATH_ADMINISTRATOR . '/components/com_cck/install/src/tmp/joomla_message'; if (JFolder::exists($src)) { JFolder::copy($src, JPATH_SITE . '/plugins/cck_storage_location/joomla_message', '', true); } } if ($i2 < 33) { $folders = array(10, 11, 12, 13, 14); foreach ($folders as $folder) { Helper_Folder::rebuildBranch($folder); } } if ($i2 < 35) { $objects = array('joomla_article' => 'article', 'joomla_category' => 'category', 'joomla_user' => 'user', 'joomla_user_group' => 'user_group'); foreach ($objects as $k => $v) { $params = JCckDatabase::loadResult('SELECT options FROM #__cck_core_objects WHERE name = "' . $k . '"'); $params = json_decode($params); $params->default_type = JCck::getConfig_Param('integration_' . $v, ''); $params->add_redirect = $params->default_type != '' ? '1' : '0'; $params->edit = JCck::getConfig_Param('integration_' . $v . '_edit', '0'); if ($k == 'joomla_category') { $params->exclude = JCck::getConfig_Param('integration_' . $v . '_exclude', ''); } JCckDatabase::doQuery('UPDATE #__cck_core_objects SET options = "' . $db->escape(json_encode($params)) . '" WHERE name = "' . $k . '"'); } } if ($i2 < 45) { $table = '#__cck_store_item_users'; $columns = $db->getTableColumns($table); if (isset($columns['password2'])) { JCckDatabase::doQuery('ALTER TABLE ' . JCckDatabase::quoteName($table) . ' DROP ' . JCckDatabase::quoteName('password2')); } } if ($i2 < 66) { $path = JPATH_ADMINISTRATOR . '/components/com_cck/download.php'; if (JFile::exists($path)) { JFile::delete($path); } } if ($i2 < 70) { $plg_image = JPluginHelper::getPlugin('cck_field', 'upload_image'); $plg_params = new JRegistry($plg_image->params); $com_cck = JComponentHelper::getComponent('com_cck'); $com_cck->params->set('media_quality_jpeg', $plg_params->get('quality_jpeg', '90')); $com_cck->params->set('media_quality_png', $plg_params->get('quality_png', '3')); JCckDatabase::doQuery('UPDATE #__extensions SET params = "' . $db->escape($com_cck->params->toString()) . '" WHERE type = "component" AND element = "com_cck"'); } // Folder Tree Helper_Folder::rebuildTree(2, 1); } // Overrides $path = JPATH_ADMINISTRATOR . '/components/com_cck/install/src'; if (JFolder::exists($path)) { $folders = JFolder::folders($path, '^joomla'); $folders = array_reverse($folders); $count = count($folders); foreach ($folders as $folder) { $version = str_replace('joomla', '', $folder); if (version_compare(JVERSION, $version, 'lt')) { $path .= '/' . $folder; $len = strlen($path); $items = JFolder::files($path, '.', true, true, array('index.html')); if (count($items)) { foreach ($items as $item) { $dest = JPATH_SITE . substr($item, $len); JFile::copy($item, $dest); } } break; } } } // Tmp $path = JPATH_ADMINISTRATOR . '/components/com_cck/install/src/tmp'; if (JFolder::exists($path)) { JFolder::delete($path); } }
public function distro_sql() { // Distro sql files $sqlfile = JRequest::getString('path', '', 'post'); $db = JFactory::getDBO(); $result->result = false; $buffer = file_get_contents(base64_decode($sqlfile)); if ($buffer === false) { $result->message = JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'); return $result; } $queries = JInstallerHelper::splitSql($buffer); if (count($queries) == 0) { // No queries to process $result->message = JText::_('COM_INSTALLER_SQL_FAILED'); return $result; } // 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()) { $result->message = JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)); return $result; } } } $result->result = true; $result->message = JText::_('COM_INSTALLER_SQL_RAN'); return $result; }
/** * Method to install template * * @param string $sql */ public function installTplFiles(&$sql, $step) { echo '<h4>' . JText::_('COM_BWPOSTMAN_TPL_INSTALL_TABLE_' . $step) . '</h4>'; $db = JFactory::getDBO(); $tempPath = JFactory::getConfig()->get('tmp_path'); $extractdir = $tempPath . '/tmp_bwpostman_installtpl/'; //we call sql file for the templates data $buffer = file_get_contents($extractdir . $sql); // Graceful exit and rollback if read not successful if ($buffer) { // Create an array of queries from the sql file jimport('joomla.installer.helper'); $queries = JInstallerHelper::splitSql($buffer); // No queries to process if (count($queries) != 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()) { echo '<p class="bw_tablecheck_error">' . JText::_('COM_BWPOSTMAN_TPL_INSTALL_TABLE_ERROR') . '</p>'; return false; } } } //endfoearch } } else { echo '<p class="bw_tablecheck_error">' . JText::_('COM_BWPOSTMAN_TPL_INSTALL_TABLE_ERROR') . '</p>'; return false; } echo '<p class="bw_tablecheck_ok">' . JText::_('COM_BWPOSTMAN_TPL_INSTALL_TABLE_' . $step . '_OK') . '</p>'; return true; }
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 = EBLOG_ADMIN_ROOT . '/queries'; if (!JFolder::exists($path)) { return $this->ajax->resolve(); } $files = JFolder::files($path, '.sql$', true, true); $result = array(); $db = EB::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->ajax->resolve(); } $path = EBLOG_ADMIN_UPDATES . '/' . $version; $files = JFolder::files($path, '.json$', true, true); $result = array(); foreach ($files as $file) { $contents = json_decode(JFile::read($file)); if (!is_array($contents)) { // @TODO: Error handling return; } $result = array_merge($result, $contents); } $tables = array(); $indexes = array(); $affected = 0; $db = EB::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) { $db->setQuery($row->query); try { $db->query(); } catch (Exception $e) { $this->ajax->reject($e->getMessage()); } $affected += 1; } } return $this->ajax->resolve(); }
function update($parent) { $this->install($parent); $db = JFactory::getDBO(); $dbserver = 'sqlsrv'; switch (strtolower($db->name)) { case 'mysql': case 'mysqli': $dbserver = 'mysql'; break; case 'postgresql': $dbserver = 'postgres'; break; } if (method_exists($parent, 'extension_root')) { $sqlfile = $parent->getPath('extension_root') . DS . 'sql' . DS . $dbserver . '.sql'; } else { $sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . $dbserver . '.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()) { if (!class_exists('ARKHelper')) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helper.php'; } ARKHelper::error(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true))); return false; } } } } } }
function createDefaultTable() { $db = JFactory::getDBO(); $buffer = file_get_contents(JPATH_ROOT . '/administrator/components/com_community/install.mysql.utf8.sql'); jimport('joomla.installer.helper'); $queries = JInstallerHelper::splitSql($buffer); if (count($queries) != 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()) { return $db->getErrorNum() . ':' . $db->getErrorMsg(); } } } } return false; }
/** * Let's say that a user tries to install a component and it somehow fails * in a non-graceful manner, e.g. a server timeout error, going over the * quota etc. In this case the component's administrator directory is * created and not removed (because the installer died an untimely death). * When the user retries installing the component JInstaller sees that and * thinks it's an update. This causes it to neither run the installation SQL * file (because it's not supposed to run on extension update) nor the * update files (because there is no schema version defined). As a result * the files are installed, the database tables are not, the component is * broken and I have to explain to non-technical users how to edit their * database with phpMyAdmin. * * This method detects this stupid situation and attempts to execute the * installation file instead. * * @param string $extension Extension name * @param JInstaller $parent Installer object * * @return void */ public static function fixBrokenSQLUpdates($extension, $parent) { // Get the extension ID $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('extension_id')->from('#__extensions')->where($db->qn('element') . ' = ' . $db->q($extension)); $db->setQuery($query); $eid = $db->loadResult(); // Get the schema version $query = $db->getQuery(true); $query->select('version_id')->from('#__schemas')->where('extension_id = ' . $eid); $db->setQuery($query); $version = $db->loadResult(); // If there is a schema version it's not a false update if ($version) { return; } // Execute the installation SQL file. Since I don't have access to // the manifest, I will improvise (again!) $dbDriver = strtolower($db->name); if ($dbDriver == 'mysqli') { $dbDriver = 'mysql'; } elseif ($dbDriver == 'sqlsrv') { $dbDriver = 'sqlazure'; } // Get the name of the sql file to process $sqlfile = $parent->getParent()->getPath('extension_root') . '/' . BABIOON_INSTALL_SUBDIR . $dbDriver . '/install.sql'; if (file_exists($sqlfile)) { $buffer = file_get_contents($sqlfile); if ($buffer === false) { return; } $queries = JInstallerHelper::splitSql($buffer); if (count($queries) == 0) { // No queries to process return; } // 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->execute()) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true))); return false; } } } } // Update #__schemas to the latest version. Again, since I don't have // access to the manifest I have to improvise... $path = $parent->getParent()->getPath('extension_root') . '/' . BABIOON_INSTALL_SUBDIR . 'updates/' . $dbDriver; $files = str_replace('.sql', '', JFolder::files($path, '\\.sql$')); if (count($files) > 0) { usort($files, 'version_compare'); $version = array_pop($files); } else { $version = '0.0.1-2007-08-15'; } $query = $db->getQuery(true); $query->insert($db->quoteName('#__schemas')); $query->columns(array($db->quoteName('extension_id'), $db->quoteName('version_id'))); $query->values($eid . ', ' . $db->quote($version)); $db->setQuery($query); $db->execute(); }
/** * * Enter description here ... * @return return_type */ function runInstallSQL() { $return = null; $db = JFactory::getDBO(); $sqlfile = JPATH_ADMINISTRATOR . '/components/' . $this->thisextension . '/install/install.sql'; if (!file_exists($sqlfile)) { return; } $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; } } } } } }
/** * Drops and recreates all ZOO database table indexes. * * @since 2.0 */ public function refreshDBTableIndexes() { // sanatize table indexes if ($this->app->path->path('component.admin:installation/index.sql')) { $db = $this->app->database; // read index.sql $buffer = JFile::read($this->app->path->path('component.admin:installation/index.sql')); // 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]; // check if table exists if (!$db->queryResult('SHOW TABLES LIKE ' . $db->Quote($table))) { continue; } // 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); } } } }
/** * Joomla modified function from installer.php file of /libraries/joomla/installer.php * * Method to extract the name of a discreet installation sql file from the installation manifest file. * * @access public * @param string $file The SQL file * @param string $version The database connector to use * @return mixed Number of queries processed or False on error * @since 1.5 */ function parseSQLFile($file) { // Initialize variables if (!file_exists($file)) { die('File does not exists ' . $file); } $queries = array(); $dbj =& JFactory::getDBO(); $class = get_class($dbj); $class = strtolower($class); if (stripos($class, 'mysql') !== false) { $dbjDriver = 'mysql'; } $dbjCharset = $dbj->hasUTF() ? 'utf8' : ''; // Get the array of file nodes to process // Get the name of the sql file to process $sqlfile = ''; // we will set a default charset of file to utf8 and mysql driver $fCharset = 'utf8'; //(strtolower($file->attributes('charset')) == 'utf8') ? 'utf8' : ''; $fDriver = 'mysql'; // strtolower($file->attributes('driver')); if ($fCharset == $dbjCharset && $fDriver == $dbjDriver) { $sqlfile = $file; // Check that sql files exists before reading. Otherwise raise error for rollback $buffer = file_get_contents($file); // 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] != '#') { $dbj->setQuery($query); if (!$dbj->query()) { JError::raiseWarning(1, 'JInstaller::install: ' . JText::_('SQL Error') . " " . $dbj->stderr(true)); return false; } } } } return (int) count($queries); }