/** * Process the main SQL file. * * @return $this * * @since 1.0 * @throws \RuntimeException * @throws \UnexpectedValueException */ private function processSql() { // Install. $dbType = $this->getApplication()->get('database.driver'); if ('mysqli' == $dbType) { $dbType = 'mysql'; } $fName = JPATH_ROOT . '/etc/' . $dbType . '.sql'; if (false == file_exists($fName)) { throw new \UnexpectedValueException(sprintf(g11n3t('Install SQL file for %s not found.'), $dbType)); } $sql = file_get_contents($fName); if (false == $sql) { throw new \UnexpectedValueException(g11n3t('SQL file corrupted.')); } $this->out(sprintf(g11n3t('Creating tables from file %s'), realpath($fName)), false); foreach ($this->db->splitSql($sql) as $query) { $q = trim($this->db->replacePrefix($query)); if ('' == trim($q)) { continue; } $this->db->setQuery($q)->execute(); $this->out('.', false); } $this->outOk(); return $this; }
/** * Process the main SQL file. * * @return $this * * @since 1.0 * @throws \RuntimeException * @throws \UnexpectedValueException */ private function processSql() { $fName = JPATH_ROOT . '/etc/schema.sql'; if (!file_exists($fName)) { throw new \UnexpectedValueException('Install SQL file not found.'); } $sql = file_get_contents($fName); if (!$sql) { throw new \UnexpectedValueException('Unable to read SQL file.'); } $this->app->out(sprintf('Creating tables from file %s', realpath($fName)), false); foreach ($this->db->splitSql($sql) as $query) { $q = trim($this->db->replacePrefix($query)); if (trim($q) == '') { continue; } $this->db->setQuery($q)->execute(); $this->app->out('.', false); } $this->app->out("\nFinished!"); return $this; }
/** * Tests the Joomla\Database\DatabaseDriver::replacePrefix method. * * @return void * * @since 1.0 */ public function testReplacePrefix() { $this->assertThat($this->instance->replacePrefix('SELECT * FROM #__dbtest'), $this->equalTo('SELECT * FROM &dbtest'), 'replacePrefix method should return the query string with the #__ prefix replaced by the actual table prefix.'); }