示例#1
0
 function setupDatabaseDriverOverride()
 {
     //override only the override file exist
     if (file_exists(dirname(__FILE__) . '/falang_database.php')) {
         require_once dirname(__FILE__) . '/falang_database.php';
         $conf = JFactory::getConfig();
         $host = $conf->get('host');
         $user = $conf->get('user');
         $password = $conf->get('password');
         $db = $conf->get('db');
         $dbprefix = $conf->get('dbprefix');
         $driver = $conf->get('dbtype');
         $debug = $conf->get('debug');
         $options = array('driver' => $driver, "host" => $host, "user" => $user, "password" => $password, "database" => $db, "prefix" => $dbprefix, "select" => true);
         $db = new JFalangDatabase($options);
         $db->debug($debug);
         if ($db->getErrorNum() > 2) {
             JError::raiseError('joomla.library:' . $db->getErrorNum(), 'JDatabase::getInstance: Could not connect to database <br/>' . $db->getErrorMsg());
         }
         // replace the database handle in the factory
         JFactory::$database = null;
         JFactory::$database = $db;
         $test = JFactory::getDBO();
     }
 }
	public static function setUpBeforeClass()
	{
		jimport('joomla.database.database');
		jimport('joomla.database.table');

		// Load the config if available.
		@ include_once JPATH_TESTS . '/config.php';
		if (class_exists('JTestConfig')) {
			$config = new JTestConfig;
		}

		if (!is_object(self :: $dbo)) {
			$options = array (
				'driver' => isset ($config) ? $config->dbtype : 'mysql',
				'host' => isset ($config) ? $config->host : '127.0.0.1',
				'user' => isset ($config) ? $config->user : '******',
				'password' => isset ($config) ? $config->password : '******',
				'database' => isset ($config) ? $config->db : 'joomla_ut',
				'prefix' => isset ($config) ? $config->dbprefix : 'jos_'
			);

			self :: $dbo = JDatabase :: getInstance($options);

			if (JError :: isError(self :: $dbo)) {
				//ignore errors
				define('DB_NOT_AVAILABLE', true);
			}
		}
		self :: $database = JFactory :: $database;
		JFactory :: $database = self :: $dbo;
	}
	/**
	 * Sets up the fixture.
	 *
	 * This method is called before a test is executed.
	 *
	 * @return  void
	 *
	 * @since   11.1
	 */
	protected function setUp()
	{
		parent::setUp();

		$this->saveFactoryState();

		JFactory::$database = $this->getMockDatabase();
	}
示例#4
0
 private function setUpDb()
 {
     $dbo = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => '/Users/rouven/Sites/jd12dk/guestbook.sqlite'));
     $dbo->setQuery('CREATE TABLE IF NOT EXISTS Comments (Id INTEGER PRIMARY KEY, Name TEXT, Email TEXT, Comment Text, Ip INTEGER, date TEXT)');
     $dbo->execute();
     // Inject database into JFactory
     JFactory::$database = $dbo;
 }
示例#5
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.0
  */
 protected function setUp()
 {
     parent::setUp();
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     JFactory::$database = $this->getMockDatabase('Mysqli');
     // Register the object
     $this->object = JSchemaChangeset::getInstance(JFactory::getDbo(), null);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     parent::setUp();
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     // Set up our mock database
     JFactory::$database = $this->getMockDatabase('Mysqli');
     FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$database = $this->getMockDatabase();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['SCRIPT_NAME'] = '';
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     // Set up our mock database
     $db = JFactory::getDbo();
     $db->name = 'mysqli';
     JFactory::$database = $db;
     FinderIndexerHelper::$stemmer = FinderIndexerStemmer::getInstance('porter_en');
 }
示例#9
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     JFactory::$database = $this->getMockDatabase();
     // Set up our mock database
     $this->db = JFactory::getDbo();
     $this->db->name = 'mysqli';
     // Register the object
     $this->object = JSchemaChangeset::getInstance($this->db, null);
 }
示例#10
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$database = $this->getMockDatabase('Mysqli');
     JFactory::$session = $this->getMockSession();
     // Register the object
     $this->object = FinderIndexer::getInstance();
 }
示例#11
0
 /**
  * Sets the Factory pointers
  *
  * @return  void
  */
 protected function restoreFactoryState()
 {
     \JFactory::$application = $this->savedFactoryState['application'];
     \JFactory::$config = $this->savedFactoryState['config'];
     \JFactory::$dates = $this->savedFactoryState['dates'];
     \JFactory::$session = $this->savedFactoryState['session'];
     \JFactory::$language = $this->savedFactoryState['language'];
     \JFactory::$document = $this->savedFactoryState['document'];
     \JFactory::$acl = $this->savedFactoryState['acl'];
     \JFactory::$database = $this->savedFactoryState['database'];
     \JFactory::$mailer = $this->savedFactoryState['mailer'];
 }
示例#12
0
文件: neno.php 项目: andresmaeso/neno
 /**
  * Method to register a custom database driver
  *
  * @return void
  */
 public function onAfterInitialise()
 {
     $nenoLoader = JPATH_LIBRARIES . '/neno/loader.php';
     if (file_exists($nenoLoader)) {
         JLoader::register('NenoLoader', $nenoLoader);
         // Register the Class prefix in the autoloader
         NenoLoader::init();
         // Load custom driver.
         JFactory::$database = null;
         JFactory::$database = NenoFactory::getDbo();
     }
 }
示例#13
0
 /**
  * Allows the application to load a custom or default database driver.
  *
  * @param   JDatabaseDriver  $driver  An optional database driver object. If omitted, the application driver is created.
  *
  * @return  JApplicationBase This method is chainable.
  *
  * @since   12.1
  */
 public function loadDatabase(JDatabaseDriver $driver = null)
 {
     if ($driver === null) {
         $this->db = JDatabaseDriver::getInstance(array('driver' => $this->get('db_driver'), 'host' => $this->get('db_host'), 'user' => $this->get('db_user'), 'password' => $this->get('db_pass'), 'database' => $this->get('db_name'), 'prefix' => $this->get('db_prefix')));
         // Select the database.
         $this->db->select($this->get('db_name'));
     } else {
         $this->db = $driver;
     }
     // Set the database to our static cache.
     JFactory::$database = $this->db;
     return $this;
 }
示例#14
0
 /**
  * Constructor: Deletes the default installation config file and recreates it with the good config file.
  *
  * @since  3.1
  */
 public function __construct()
 {
     // Overrides application config and set the configuration.php file so tokens and database works.
     JFactory::$config = null;
     JFactory::getConfig(JPATH_SITE . '/configuration.php');
     /*
      * JFactory::getDbo() gets called during app bootup, and because of the "uniqueness" of the install app, the config doesn't get read
      * correctly at that point.  So, we have to reset the factory database object here so that we can get a valid database configuration.
      * The day we have proper dependency injection will be a glorious one.
      */
     JFactory::$database = null;
     parent::__construct();
 }
示例#15
0
文件: neno.php 项目: javigomez/neno
 /**
  * Entry point for CLI script
  *
  * @return  void
  *
  * @since   3.0
  */
 public function doExecute()
 {
     $nenoLoader = JPATH_LIBRARIES . '/neno/loader.php';
     if (file_exists($nenoLoader)) {
         JLoader::register('NenoLoader', $nenoLoader);
         // Register the Class prefix in the autoloader
         NenoLoader::init(false);
         // Load custom driver.
         JFactory::$database = null;
         JFactory::$database = NenoFactory::getDbo();
     }
     NenoTaskMonitor::runTask();
 }
示例#16
0
 /**
  * Get a database object.
  *
  * Returns the global {@link JDatabase} object, only creating it if it doesn't already exist.
  *
  * @return  JDatabase object
  *
  * @see     JDatabase
  * @since   11.1
  */
 public static function getDbo()
 {
     if (class_exists('\\App')) {
         if (\App::has('db')) {
             return \App::get('db');
         }
     }
     if (!self::$database) {
         self::$database = self::createDbo();
     }
     return self::$database;
 }
示例#17
0
 /**
  * Method to create the database tables.
  *
  * @param   array  $options  The options array.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  */
 public function createTables($options)
 {
     // Get the application.
     /* @var InstallationApplicationWeb $app */
     $app = JFactory::getApplication();
     if (!isset($options['db_created']) || !$options['db_created']) {
         return $this->createDatabase($options);
     }
     if (!($db = $this->initialise($options))) {
         return false;
     }
     // Get the options as a object for easier handling.
     $options = JArrayHelper::toObject($options);
     // Check database type.
     $type = $options->db_type;
     // Set the character set to UTF-8 for pre-existing databases.
     $this->setDatabaseCharset($db, $options->db_name);
     // Set the appropriate schema script based on UTF-8 support.
     if ($type == 'mysql' || $type == 'mysqli' || $type == 'pdomysql') {
         $schema = 'sql/mysql/joomla.sql';
     } elseif ($type == 'sqlsrv' || $type == 'sqlazure') {
         $schema = 'sql/sqlazure/joomla.sql';
     } else {
         $schema = 'sql/' . $type . '/joomla.sql';
     }
     // Check if the schema is a valid file
     if (!is_file($schema)) {
         $app->enqueueMessage(JText::sprintf('INSTL_ERROR_DB', JText::_('INSTL_DATABASE_NO_SCHEMA')), 'notice');
         return false;
     }
     // Attempt to import the database schema.
     if (!$this->populateDatabase($db, $schema)) {
         return false;
     }
     // Attempt to update the table #__schema.
     $pathPart = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/';
     if ($type == 'mysql' || $type == 'mysqli' || $type == 'pdomysql') {
         $pathPart .= 'mysql/';
     } elseif ($type == 'sqlsrv' || $type == 'sqlazure') {
         $pathPart .= 'sqlazure/';
     } else {
         $pathPart .= $type . '/';
     }
     $files = JFolder::files($pathPart, '\\.sql$');
     if (empty($files)) {
         $app->enqueueMessage(JText::_('INSTL_ERROR_INITIALISE_SCHEMA'), 'notice');
         return false;
     }
     $version = '';
     foreach ($files as $file) {
         if (version_compare($version, JFile::stripExt($file)) < 0) {
             $version = JFile::stripExt($file);
         }
     }
     $query = $db->getQuery(true)->insert($db->quoteName('#__schemas'))->columns(array($db->quoteName('extension_id'), $db->quoteName('version_id')))->values('700, ' . $db->quote($version));
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         return false;
     }
     // Attempt to refresh manifest caches.
     $query->clear()->select('*')->from('#__extensions');
     $db->setQuery($query);
     $return = true;
     try {
         $extensions = $db->loadObjectList();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         $return = false;
     }
     JFactory::$database = $db;
     $installer = JInstaller::getInstance();
     foreach ($extensions as $extension) {
         if (!$installer->refreshManifestCache($extension->extension_id)) {
             $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_REFRESH_MANIFEST_CACHE', $extension->name), 'notice');
             return false;
         }
     }
     // Load the localise.sql for translating the data in joomla.sql.
     if ($type == 'mysql' || $type == 'mysqli' || $type == 'pdomysql') {
         $dblocalise = 'sql/mysql/localise.sql';
     } elseif ($type == 'sqlsrv' || $type == 'sqlazure') {
         $dblocalise = 'sql/sqlazure/localise.sql';
     } else {
         $dblocalise = 'sql/' . $type . '/localise.sql';
     }
     if (is_file($dblocalise)) {
         if (!$this->populateDatabase($db, $dblocalise)) {
             return false;
         }
     }
     // Handle default backend language setting. This feature is available for localized versions of Joomla.
     $app = JFactory::getApplication();
     $languages = $app->getLocaliseAdmin($db);
     if (in_array($options->language, $languages['admin']) || in_array($options->language, $languages['site'])) {
         // Build the language parameters for the language manager.
         $params = array();
         // Set default administrator/site language to sample data values.
         $params['administrator'] = 'en-GB';
         $params['site'] = 'en-GB';
         if (in_array($options->language, $languages['admin'])) {
             $params['administrator'] = $options->language;
         }
         if (in_array($options->language, $languages['site'])) {
             $params['site'] = $options->language;
         }
         $params = json_encode($params);
         // Update the language settings in the language manager.
         $query->clear()->update($db->quoteName('#__extensions'))->set($db->quoteName('params') . ' = ' . $db->quote($params))->where($db->quoteName('element') . ' = ' . $db->quote('com_languages'));
         $db->setQuery($query);
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             $app->enqueueMessage($e->getMessage(), 'notice');
             $return = false;
         }
     }
     return $return;
 }
示例#18
0
 /**
  * Tests __construct()
  *
  * @return  void
  *
  * @since   1.0
  */
 public function test__construct2()
 {
     JFactory::$database = 'factory db';
     JFactory::$application = $this->getMockWeb();
     $factory = new JContentFactory('TCPrefix', null, null, new JUser());
     // Construct the object.
     $model = new WebServiceModelBase($factory, null, null);
     // Verify that the values injected into the constructor are present.
     $this->assertEquals('factory db', TestReflection::getValue($model, 'db'));
 }
示例#19
0
 /**
  * Method to create a database driver for the Web application.
  *
  * @return void
  *
  * @since 1.0
  */
 protected function loadDatabase()
 {
     $database = 'sqlite' == $this->get('db_driver') ? APP_PATH_DATA . '/' . $this->get('db_name') : $this->get('db_name');
     $this->db = JDatabaseDriver::getInstance(array('driver' => $this->get('db_driver'), 'host' => $this->get('db_host'), 'user' => $this->get('db_user'), 'password' => $this->get('db_pass'), 'database' => $database, 'prefix' => $this->get('db_prefix')));
     // Select the database.
     if ('sqlite' != $this->get('db_driver')) {
         $this->db->select($this->get('db_name'));
     }
     // Set the debug flag.
     $this->db->setDebug($this->get('debug'));
     // Set the database to our static cache.
     JFactory::$database = $this->db;
 }
示例#20
0
 /**
  * Get a database object.
  *
  * Returns the global {@link JDatabaseDriver} object, only creating it if it doesn't already exist.
  *
  * @return  JDatabaseDriver
  *
  * @see     JDatabaseDriver
  * @since   11.1
  */
 public static function getDbo()
 {
     if (!self::$database) {
         self::$database = self::createDbo();
     }
     return self::$database;
 }
示例#21
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function setUp()
 {
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$database = $this->getMockDatabase();
 }
示例#22
0
 /**
  * Method to process SQL updates previous to the install process
  *
  * @param   JInstallerAdapter  $parent  Class calling this method
  *
  * @return  boolean          True on success
  */
 public function preprocessUpdates($parent)
 {
     $manifest = $parent->get('manifest');
     if (isset($manifest->update)) {
         if (isset($manifest->update->attributes()->folder)) {
             $path = $manifest->update->attributes()->folder;
             if (isset($manifest->update->pre) && isset($manifest->update->pre->schemas)) {
                 $schemapaths = $manifest->update->pre->schemas->children();
                 if (count($schemapaths)) {
                     $sourcePath = $parent->getParent()->getPath('source');
                     // If it just upgraded redCORE to a newer version using RFactory for database, it forces using the redCORE database drivers
                     if (substr(get_class(JFactory::$database), 0, 1) == 'J' && $this->extensionElement != 'com_redcore') {
                         RFactory::$database = null;
                         JFactory::$database = null;
                         JFactory::$database = RFactory::getDbo();
                     }
                     $db = JFactory::getDbo();
                     $dbDriver = strtolower($db->name);
                     $schemapath = '';
                     if ($dbDriver == 'mysqli') {
                         $dbDriver = 'mysql';
                     }
                     foreach ($schemapaths as $entry) {
                         if (isset($entry->attributes()->type)) {
                             $uDriver = strtolower($entry->attributes()->type);
                             if ($uDriver == 'mysqli') {
                                 $uDriver = 'mysql';
                             }
                             if ($uDriver == $dbDriver) {
                                 $schemapath = (string) $entry;
                                 break;
                             }
                         }
                     }
                     if ($schemapath != '') {
                         $files = str_replace('.sql', '', JFolder::files($sourcePath . '/' . $path . '/' . $schemapath, '\\.sql$'));
                         usort($files, 'version_compare');
                         if (count($files)) {
                             foreach ($files as $file) {
                                 if (version_compare($file, $this->oldVersion) > 0) {
                                     $buffer = file_get_contents($sourcePath . '/' . $path . '/' . $schemapath . '/' . $file . '.sql');
                                     $queries = RHelperDatabase::splitSQL($buffer);
                                     if (count($queries)) {
                                         foreach ($queries as $query) {
                                             if ($query != '' && $query[0] != '#') {
                                                 $db->setQuery($query);
                                                 if (!$db->execute(true)) {
                                                     JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
                                                     return false;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
 /**
  * Setup the tests.
  *
  * @return  void
  *
  * @since   12.1
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$database = TestMockDatabaseDriver::create($this);
     $this->_instance = new DatabaseModel();
 }
 /**
  * Method to restore the factory database instance
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function restoreFactoryDatabase()
 {
     JFactory::$database = $this->factoryDb;
 }
示例#25
0
 /**
  * Get a database object
  *
  * Returns the global {@link JDatabase} object, only creating it
  * if it doesn't already exist.
  *
  * @return object JDatabase
  */
 public static function getDbo()
 {
     if (!is_object(self::$database)) {
         //get the debug configuration setting
         $conf =& self::getConfig();
         $debug = $conf->getValue('config.debug');
         self::$database = self::_createDbo();
         self::$database->debug($debug);
     }
     return self::$database;
 }
示例#26
0
 /**
  * Effectively bootstrap redCORE.
  *
  * @param   bool  $loadBootstrap  Load bootstrap with redcore plugin options
  *
  * @return  void
  */
 public static function bootstrap($loadBootstrap = true)
 {
     if ($loadBootstrap && !defined('REDCORE_BOOTSTRAPPED')) {
         define('REDCORE_BOOTSTRAPPED', 1);
     }
     if (!defined('REDCORE_LIBRARY_LOADED')) {
         // Sets bootstrapped variable, to avoid bootstrapping redCORE twice
         define('REDCORE_LIBRARY_LOADED', 1);
         // Use our own base field
         if (!class_exists('JFormField', false)) {
             $baseField = JPATH_LIBRARIES . '/redcore/joomla/form/field.php';
             if (file_exists($baseField)) {
                 require_once $baseField;
             }
         }
         // Register the classes for autoload.
         JLoader::registerPrefix('R', JPATH_REDCORE);
         // Setup the RLoader.
         RLoader::setup();
         // Make available the redCORE fields
         JFormHelper::addFieldPath(JPATH_REDCORE . '/form/field');
         JFormHelper::addFieldPath(JPATH_REDCORE . '/form/fields');
         // Make available the redCORE form rules
         JFormHelper::addRulePath(JPATH_REDCORE . '/form/rules');
         // HTML helpers
         JHtml::addIncludePath(JPATH_REDCORE . '/html');
         RHtml::addIncludePath(JPATH_REDCORE . '/html');
         // Load library language
         $lang = JFactory::getLanguage();
         $lang->load('lib_redcore', JPATH_REDCORE);
         // For Joomla! 2.5 compatibility we add some core functions
         if (version_compare(JVERSION, '3.0', '<')) {
             RLoader::registerPrefix('J', JPATH_LIBRARIES . '/redcore/joomla', false, true);
         }
         // Make available the fields
         JFormHelper::addFieldPath(JPATH_LIBRARIES . '/redcore/form/fields');
         // Make available the rules
         JFormHelper::addRulePath(JPATH_LIBRARIES . '/redcore/form/rules');
         // Replaces Joomla database driver for redCORE database driver
         JFactory::$database = null;
         JFactory::$database = RFactory::getDbo();
         if (self::getConfig('enable_translations', 0) == 1 && !JFactory::getApplication()->isAdmin()) {
             // This is our object now
             $db = JFactory::getDbo();
             // Enable translations
             $db->translate = self::getConfig('enable_translations', 0) == 1;
             // Reset plugin translations params if needed
             RTranslationHelper::resetPluginTranslation();
         }
     }
 }
示例#27
0
 /**
  * Get a database object.
  *
  * Returns the global {@link JDatabaseDriver} object, only creating it if it doesn't already exist.
  *
  * @return  JDatabaseDriver
  *
  * @see     JDatabaseDriver
  * @since   11.1
  */
 public static function getDbo()
 {
     if (!self::$database) {
         // Get the debug configuration setting
         $conf = self::getConfig();
         $debug = $conf->get('debug');
         self::$database = self::createDbo();
         self::$database->setDebug($debug);
     }
     return self::$database;
 }
示例#28
0
 /**
  * Prepares the environment before running a test.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function setUp()
 {
     parent::setUp();
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'ws_');
     $driver = JDatabaseDriver::getInstance($options);
     $pdo = new PDO('sqlite::memory:');
     $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ws.sql')) or die(print_r($pdo->errorInfo()));
     TestReflection::setValue($driver, 'connection', $pdo);
     JFactory::$database = $driver;
     JFactory::$application = $this->getMockWeb();
     $testInput = new JInput();
     $testMock = MockWebServiceApplicationWeb::create($this);
     $this->_instance = new WebServiceControllerV1JsonBaseDelete('general', $testInput, $testMock);
 }
示例#29
0
 /**
  * This method is called after the last test of this test class is run.
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function tearDownAfterClass()
 {
     JFactory::$database = self::$_stash;
     self::$driver = null;
 }
示例#30
0
 public function initialise($options)
 {
     // Get the options as a JObject for easier handling.
     $options = JArrayHelper::toObject($options, 'JObject');
     // Load the back-end language files so that the DB error messages work
     $jlang = JFactory::getLanguage();
     // Pre-load en-GB in case the chosen language files do not exist
     $jlang->load('joomla', JPATH_ADMINISTRATOR, 'en-GB', true);
     // Load the selected language
     $jlang->load('joomla', JPATH_ADMINISTRATOR, $options->language, true);
     // Ensure a database type was selected.
     if (empty($options->db_type)) {
         $this->setError(JText::_('INSTL_DATABASE_INVALID_TYPE'));
         return false;
     }
     // Ensure that a valid hostname and user name were input.
     if (empty($options->db_host) || empty($options->db_user)) {
         $this->setError(JText::_('INSTL_DATABASE_INVALID_DB_DETAILS'));
         return false;
     }
     // Ensure that a database name was input.
     if (empty($options->db_name)) {
         $this->setError(JText::_('INSTL_DATABASE_EMPTY_NAME'));
         return false;
     }
     // Validate database table prefix.
     if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $options->db_prefix)) {
         $this->setError(JText::_('INSTL_DATABASE_PREFIX_INVALID_CHARS'));
         return false;
     }
     // Validate length of database table prefix.
     if (strlen($options->db_prefix) > 15) {
         $this->setError(JText::_('INSTL_DATABASE_FIX_TOO_LONG'));
         return false;
     }
     // Validate length of database name.
     if (strlen($options->db_name) > 64) {
         $this->setError(JText::_('INSTL_DATABASE_NAME_TOO_LONG'));
         return false;
     }
     // If the database is not yet created, create it.
     if (empty($options->db_created)) {
         // Get a database object.
         try {
             $db = JInstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, null, $options->db_prefix, false);
             // Check database version.
             $db_version = $db->getVersion();
             $type = $options->db_type;
         } catch (RuntimeException $e) {
             $this->setError(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()));
             return false;
         }
         if (!$db->isMinimumVersion()) {
             $this->setError(JText::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($type) . '_VERSION', $db_version));
             return false;
         }
         if ($type == ('mysql' || 'mysqli')) {
             // @internal MySQL versions pre 5.1.6 forbid . / or \ or NULL
             if (preg_match('#[\\\\/\\.\\0]#', $options->db_name) && !version_compare($db_version, '5.1.6', '>=')) {
                 $this->setError(JText::sprintf('INSTL_DATABASE_INVALID_NAME', $db_version));
                 return false;
             }
         }
         // @internal Check for spaces in beginning or end of name
         if (strlen(trim($options->db_name)) != strlen($options->db_name)) {
             $this->setError(JText::_('INSTL_DATABASE_NAME_INVALID_SPACES'));
             return false;
         }
         // @internal Check for asc(00) Null in name
         if (strpos($options->db_name, chr(00)) !== false) {
             $this->setError(JText::_('INSTL_DATABASE_NAME_INVALID_CHAR'));
             return false;
         }
         // Try to select the database
         try {
             $db->select($options->db_name);
         } catch (RuntimeException $e) {
             // If the database could not be selected, attempt to create it and then select it.
             if ($this->createDatabase($db, $options->db_name)) {
                 $db->select($options->db_name);
             } else {
                 $this->setError(JText::sprintf('INSTL_DATABASE_ERROR_CREATE', $options->db_name));
                 return false;
             }
         }
         // Set the character set to UTF-8 for pre-existing databases.
         $this->setDatabaseCharset($db, $options->db_name);
         // Should any old database tables be removed or backed up?
         if ($options->db_old == 'remove') {
             // Attempt to delete the old database tables.
             if (!$this->deleteDatabase($db, $options->db_name, $options->db_prefix)) {
                 $this->setError(JText::_('INSTL_DATABASE_ERROR_DELETE'));
                 return false;
             }
         } else {
             // If the database isn't being deleted, back it up.
             if (!$this->backupDatabase($db, $options->db_name, $options->db_prefix)) {
                 $this->setError(JText::_('INSTL_DATABASE_ERROR_BACKINGUP'));
                 return false;
             }
         }
         // Set the appropriate schema script based on UTF-8 support.
         if ($type == 'mysqli' || $type == 'mysql') {
             $schema = 'sql/mysql/joomla.sql';
         } elseif ($type == 'sqlsrv' || $type == 'sqlazure') {
             $schema = 'sql/sqlazure/joomla.sql';
         } else {
             $schema = 'sql/' . $type . '/joomla.sql';
         }
         // Check if the schema is a valid file
         if (!JFile::exists($schema)) {
             $this->setError(JText::sprintf('INSTL_ERROR_DB', JText::_('INSTL_DATABASE_NO_SCHEMA')));
             return false;
         }
         // Attempt to import the database schema.
         if (!$this->populateDatabase($db, $schema)) {
             $this->setError(JText::sprintf('INSTL_ERROR_DB', $this->getError()));
             return false;
         }
         // Attempt to update the table #__schema.
         $files = JFolder::files(JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/mysql/', '\\.sql$');
         if (empty($files)) {
             $this->setError(JText::_('INSTL_ERROR_INITIALISE_SCHEMA'));
             return false;
         }
         $version = '';
         foreach ($files as $file) {
             if (version_compare($version, JFile::stripExt($file)) < 0) {
                 $version = JFile::stripExt($file);
             }
         }
         $query = $db->getQuery(true);
         $query->insert('#__schemas');
         $query->columns(array($db->quoteName('extension_id'), $db->quoteName('version_id')));
         $query->values('700, ' . $db->quote($version));
         $db->setQuery($query);
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             return false;
         }
         // Attempt to refresh manifest caches
         $query = $db->getQuery(true);
         $query->select('*');
         $query->from('#__extensions');
         $db->setQuery($query);
         try {
             $extensions = $db->loadObjectList();
         } catch (RuntimeException $e) {
             $this->setError($e->getMessage());
             $return = false;
         }
         JFactory::$database = $db;
         $installer = JInstaller::getInstance();
         foreach ($extensions as $extension) {
             if (!$installer->refreshManifestCache($extension->extension_id)) {
                 $this->setError(JText::sprintf('INSTL_DATABASE_COULD_NOT_REFRESH_MANIFEST_CACHE', $extension->name));
                 return false;
             }
         }
         // Load the localise.sql for translating the data in joomla.sql/joomla_backwards.sql
         $dblocalise = 'sql/' . ($type == 'mysqli' ? 'mysql' : $type) . '/localise.sql';
         if (JFile::exists($dblocalise)) {
             if (!$this->populateDatabase($db, $dblocalise)) {
                 $this->setError(JText::sprintf('INSTL_ERROR_DB', $this->getError()));
                 return false;
             }
         }
         $dblocalise_sql = 'sql/' . ($type == 'sqlsrv' ? 'sqlazure' : $type) . '/localise.sql';
         if (JFile::exists($dblocalise_sql)) {
             if (!$this->populateDatabase($db, $dblocalise_sql)) {
                 $this->setError(JText::sprintf('INSTL_ERROR_DB', $this->getError()));
                 return false;
             }
         }
         // Handle default backend language setting. This feature is available for localized versions of Joomla 1.5.
         $app = JFactory::getApplication();
         $languages = $app->getLocaliseAdmin($db);
         if (in_array($options->language, $languages['admin']) || in_array($options->language, $languages['site'])) {
             // Build the language parameters for the language manager.
             $params = array();
             // Set default administrator/site language to sample data values:
             $params['administrator'] = 'en-GB';
             $params['site'] = 'en-GB';
             if (in_array($options->language, $languages['admin'])) {
                 $params['administrator'] = $options->language;
             }
             if (in_array($options->language, $languages['site'])) {
                 $params['site'] = $options->language;
             }
             $params = json_encode($params);
             // Update the language settings in the language manager.
             $db->setQuery('UPDATE ' . $db->quoteName('#__extensions') . ' SET ' . $db->quoteName('params') . ' = ' . $db->Quote($params) . ' WHERE ' . $db->quoteName('element') . '=\'com_languages\'');
             try {
                 $db->execute();
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 $return = false;
             }
         }
     }
     return true;
 }