/** * Method to load and execute a sql script */ function sampledata($args) { jimport('joomla.database.database'); jimport('joomla.language.language'); jimport('joomla.registry.registry'); $errors = null; $msg = ''; $objResponse = new xajaxResponse(); $lang = new JAJAXLang($args['lang']); // $lang->setDebug(true); /* * execute the default sample data file */ $type = $args['DBtype']; if ($type == 'mysqli') { $type = 'mysql'; } $dbsample = '../sql' . DS . $type . DS . 'sample_data.sql'; $db =& JInstallationHelper::getDBO($args['DBtype'], $args['DBhostname'], $args['DBuserName'], $args['DBpassword'], $args['DBname'], $args['DBPrefix']); $result = JInstallationHelper::populateDatabase($db, $dbsample, $errors); /* * prepare sql error messages if returned from populate */ if (!is_null($errors)) { foreach ($errors as $error) { $msg .= stripslashes($error['msg']); $msg .= chr(13) . "-------------" . chr(13); $txt = '<textarea cols="35" rows="5" name="instDefault" readonly="readonly" >' . $lang->_('Database Errors Reported') . chr(13) . $msg . '</textarea>'; } } else { // consider other possible errors from populate $msg = $result == 0 ? $lang->_("Sample data installed successfully") : $lang->_("Error installing SQL script"); $txt = '<input size="35" name="instDefault" value="' . $msg . '" readonly="readonly" />'; } $objResponse->addAssign("theDefault", "innerHTML", $txt); return $objResponse; }
/** * Uploads a sql script and executes it. Script can be text file or zip/gz packed * * @static * @param array The installation variables * @param boolean true if the script is a migration script * @return string Success or error messages * @since 1.5 */ function uploadSql(&$args, $migration = false, $preconverted = false) { global $mainframe; $archive = ''; $script = ''; /* * Check for iconv */ if ($migration && !$preconverted && !function_exists('iconv')) { return JText::_('WARNICONV'); } /* * Get the uploaded file information */ if ($migration) { $sqlFile = JRequest::getVar('migrationFile', '', 'files', 'array'); } else { $sqlFile = JRequest::getVar('sqlFile', '', 'files', 'array'); } /* * Make sure that file uploads are enabled in php */ if (!(bool) ini_get('file_uploads')) { return JText::_('WARNINSTALLFILE'); } /* * Make sure that zlib is loaded so that the package can be unpacked */ if (!extension_loaded('zlib')) { return JText::_('WARNINSTALLZLIB'); } /* * If there is no uploaded file, we have a problem... */ if (!is_array($sqlFile) || $sqlFile['size'] < 1) { return JText::_('WARNNOFILE'); } /* * Move uploaded file */ // Set permissions for tmp dir JInstallationHelper::_chmod(JPATH_SITE . DS . 'tmp', 0777); jimport('joomla.filesystem.file'); $uploaded = JFile::upload($sqlFile['tmp_name'], JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name']); if (!$uploaded) { return JText::_('WARNUPLOADFAILURE'); } if (!eregi('.sql$', $sqlFile['name'])) { $archive = JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name']; } else { $script = JPATH_SITE . DS . 'tmp' . DS . $sqlFile['name']; } // unpack archived sql files if ($archive) { $package = JInstallationHelper::unpack($archive, $args); if ($package === false) { return JText::_('WARNUNPACK'); } $script = $package['folder'] . DS . $package['script']; } $db =& JInstallationHelper::getDBO($args['DBtype'], $args['DBhostname'], $args['DBuserName'], $args['DBpassword'], $args['DBname'], $args['DBPrefix']); /* * If migration perform manipulations on script file before population */ if ($migration) { $script = JInstallationHelper::preMigrate($script, $args, $db); if ($script == false) { return JText::_('Script operations failed'); } } $errors = null; $msg = ''; $result = JInstallationHelper::populateDatabase($db, $script, $errors); /* * If migration, perform post population manipulations (menu table construction) */ $migErrors = null; if ($migration) { $migResult = JInstallationHelper::postMigrate($db, $migErrors, $args); if ($migResult != 0) { /* * Merge populate and migrate processing errors */ if ($result == 0) { $result = $migResult; $errors = $migErrors; } else { $result += $migResult; $errors = array_merge($errors, $migErrors); } } } /* * prepare sql error messages if returned from populate and migrate */ if (!is_null($errors)) { foreach ($errors as $error) { $msg .= stripslashes($error['msg']); $msg .= chr(13) . "-------------" . chr(13); $txt = '<textarea cols="40" rows="4" name="instDefault" readonly="readonly" >' . JText::_("Database Errors Reported") . chr(13) . $msg . '</textarea>'; } } else { // consider other possible errors from populate $msg = $result == 0 ? JText::_('SQL script installed successfully') : JText::_('Error installing SQL script'); $txt = '<input size="50" value="' . $msg . '" readonly="readonly" />'; } /* * Clean up */ if ($archive) { JFile::delete($archive); JFolder::delete($package['folder']); } else { JFile::delete($script); } return $txt; }
protected function _configure() { $dialog = $this->getHelperSet()->get('dialog'); $output = $this->_output; $input = $this->_input; $prompt = function ($key, $text, $default = null, $error = null) use($dialog, $output, $input) { $result = $input->getOption($key); if (empty($result) && !$input->getOption('no-interaction')) { if (!empty($default)) { $text .= '(default: ' . $default . ') '; } while (strlen($result = $dialog->ask($output, '<info>' . $text . '</info>', $default)) == 0) { } } elseif (empty($result)) { $result = $default; if (empty($result)) { $output->writeLn('<error>' . $error . '</error>'); exit(1); } } return $result; }; $config = new Config(WWW_ROOT); $info = $config->getDatabaseInfo(); $config->setDatabaseInfo(array('name' => $prompt('database-name', 'Enter the name of the database? ', @$info['name'], 'Please enter the database name'), 'user' => $prompt('database-user', 'Enter the database user? ', @$info['user'], 'Please enter the database user'), 'password' => $prompt('database-password', 'Enter the database password? ', @$info['password'], 'Please enter the database password'), 'host' => $prompt('database-host', 'Enter the database host address? ', '127.0.0.1', @$info['host']), 'port' => $prompt('database-port', 'Enter the database port? ', '3306', @$info['port']), 'prefix' => $prompt('database-prefix', 'Enter a prefix for the tables in the database? ', 'jos_', @$info['prefix']))); define('DS', DIRECTORY_SEPARATOR); define('_JEXEC', 1); define('JPATH_BASE', WWW_ROOT); define('JPATH_ROOT', JPATH_BASE); define('JPATH_SITE', JPATH_ROOT); define('JPATH_CONFIGURATION', JPATH_ROOT); define('JPATH_ADMINISTRATOR', JPATH_ROOT . '/administrator'); define('JPATH_XMLRPC', JPATH_ROOT . '/xmlrpc'); define('JPATH_LIBRARIES', JPATH_ROOT . '/libraries'); define('JPATH_PLUGINS', JPATH_ROOT . '/plugins'); define('JPATH_INSTALLATION', JPATH_ROOT . '/installation'); define('JPATH_THEMES', JPATH_BASE . '/templates'); define('JPATH_CACHE', JPATH_BASE . '/cache'); include_once JPATH_LIBRARIES . '/joomla/import.php'; require_once 'Console/Installer/Helper.php'; $output->writeLn('<info>connecting to database...</info>'); $errors = array(); $database = $config->getDatabaseInfo(); $db = \JInstallationHelper::getDBO('mysqli', $database['host'] . ':' . $database['port'], $database['user'], $database['password'], $database['name'], $database['prefix'], false); if ($db instanceof \JException) { $output->writeLn('<error>' . $db->toString() . '</error>'); exit(1); } $db_exists = \JInstallationHelper::databaseExists($db, $database['name']); $dump_file = null; if ($input->getOption('database-dump')) { $dump_file = realpath($input->getOption('database-dump')); } if ($db_exists && $input->getOption('drop-database')) { $output->writeLn('<fg=red>Dropping existing database...</fg=red>'); \JInstallationHelper::deleteDatabase($db, $database['name'], $database['prefix'], $errors); $db_exists = false; } if (!$db_exists) { $output->writeLn('<info>Creating new database...</info>'); \JInstallationHelper::createDatabase($db, $database['name'], true); $db->select($database['name']); $sql_files = $dump_file ? array($dump_file) : array_map(function ($file) { return $file = ANAHITA_ROOT . "/vendor/joomla/installation/sql/{$file}"; }, array("schema.sql", "data.sql")); $output->writeLn('<info>Populating database...</info>'); array_walk($sql_files, function ($file) use($db) { \JInstallationHelper::populateDatabase($db, $file, $errors); }); } jimport('joomla.user.helper'); $config->secret = \JUserHelper::genRandomPassword(32); //exec("rm -rf ".JPATH_ROOT."/installation"); $config->save(); $output->writeLn("<info>Congratulations you're done.</info>"); if (!$db_exists && !$dump_file) { $output->writeLn("<info>The first person who registers for an account becomes the Super Administrator. Point your browser to http://yoursite/people/signup and create a new account.</info>"); } }
/** * Gets the parameters for database creation * * @return boolean True if successful * @access public * @since 1.5 */ function makeDB($vars = false) { global $mainframe; // Initialize variables if ($vars === false) { $vars = $this->getVars(); } $errors = null; $lang = JArrayHelper::getValue($vars, 'lang', 'en-GB'); $DBcreated = JArrayHelper::getValue($vars, 'DBcreated', '0'); $DBtype = JArrayHelper::getValue($vars, 'DBtype', 'mysql'); $DBhostname = JArrayHelper::getValue($vars, 'DBhostname', ''); $DBuserName = JArrayHelper::getValue($vars, 'DBuserName', ''); $DBpassword = JArrayHelper::getValue($vars, 'DBpassword', ''); $DBname = JArrayHelper::getValue($vars, 'DBname', ''); $DBPrefix = JArrayHelper::getValue($vars, 'DBPrefix', 'jos_'); $DBOld = JArrayHelper::getValue($vars, 'DBOld', 'bu'); $DBversion = JArrayHelper::getValue($vars, 'DBversion', ''); // these 3 errors should be caught by the javascript in dbConfig if ($DBtype == '') { $this->setError(JText::_('validType')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; //return JInstallationView::error($vars, JText::_('validType'), 'dbconfig'); } if (!$DBhostname || !$DBuserName || !$DBname) { $this->setError(JText::_('validDBDetails')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; //return JInstallationView::error($vars, JText::_('validDBDetails'), 'dbconfig'); } if ($DBname == '') { $this->setError(JText::_('emptyDBName')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; //return JInstallationView::error($vars, JText::_('emptyDBName'), 'dbconfig'); } if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $DBPrefix)) { $this->setError(JText::_('MYSQLPREFIXINVALIDCHARS')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; } if (strlen($DBPrefix) > 15) { $this->setError(JText::_('MYSQLPREFIXTOOLONG')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; } if (strlen($DBname) > 64) { $this->setError(JText::_('MYSQLDBNAMETOOLONG')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; } if (!$DBcreated) { $DBselect = false; $db =& JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, null, $DBPrefix, $DBselect); if (JError::isError($db)) { // connection failed $this->setError(JText::sprintf('WARNNOTCONNECTDB', $db->toString())); $this->setData('back', 'dbconfig'); $this->setData('errors', $db->toString()); return false; } if ($err = $db->getErrorNum()) { // connection failed $this->setError(JText::sprintf('WARNNOTCONNECTDB', $db->getErrorNum())); $this->setData('back', 'dbconfig'); $this->setData('errors', $db->getErrorMsg()); return false; } //Check utf8 support of database $DButfSupport = $db->hasUTF(); // Try to select the database if (!$db->select($DBname)) { if (JInstallationHelper::createDatabase($db, $DBname, $DButfSupport)) { $db->select($DBname); /* // make the new connection to the new database $db = NULL; $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); */ } else { $this->setError(JText::sprintf('WARNCREATEDB', $DBname)); $this->setData('back', 'dbconfig'); $this->setData('errors', $db->getErrorMsg()); return false; //return JInstallationView::error($vars, array (JText::sprintf('WARNCREATEDB', $DBname)), 'dbconfig', $error); } } else { // pre-existing database - need to set character set to utf8 // will only affect MySQL 4.1.2 and up JInstallationHelper::setDBCharset($db, $DBname); } $db =& JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix); if ($DBOld == 'rm') { if (JInstallationHelper::deleteDatabase($db, $DBname, $DBPrefix, $errors)) { $this->setError(JText::_('WARNDELETEDB')); $this->setData('back', 'dbconfig'); $this->setData('errors', $errors); return false; //return JInstallationView::error($vars, , 'dbconfig', JInstallationHelper::errors2string($errors)); } } else { /* * We assume since we aren't deleting the database that we need * to back it up :) */ if (JInstallationHelper::backupDatabase($db, $DBname, $DBPrefix, $errors)) { $this->setError(JText::_('WARNBACKINGUPDB')); $this->setData('back', 'dbconfig'); $this->setData('errors', JInstallationHelper::errors2string($errors)); return false; //return JInstallationView::error($vars, JText::_('WARNBACKINGUPDB'), 'dbconfig', JInstallationHelper::errors2string($errors)); } } $type = $DBtype; if ($type == 'mysqli') { $type = 'mysql'; } // set collation and use utf-8 compatibile script if appropriate if ($DButfSupport) { $dbscheme = 'sql' . DS . $type . DS . 'joomla.sql'; } else { $dbscheme = 'sql' . DS . $type . DS . 'joomla_backward.sql'; } if (JInstallationHelper::populateDatabase($db, $dbscheme, $errors) > 0) { $this->setError(JText::_('WARNPOPULATINGDB')); $this->setData('back', 'dbconfig'); $this->setData('errors', JInstallationHelper::errors2string($errors)); return false; //return JInstallationView::error($vars, JText::_('WARNPOPULATINGDB'), 'dbconfig', JInstallationHelper::errors2string($errors)); } // Load the localise.sql for translating the data in joomla.sql/joomla_backwards.sql // This feature is available for localized version of Joomla! 1.5 jimport('joomla.filesystem.file'); $dblocalise = 'sql' . DS . $type . DS . 'localise.sql'; if (JFile::exists($dblocalise)) { if (JInstallationHelper::populateDatabase($db, $dblocalise, $errors) > 0) { $this->setError(JText::_('WARNPOPULATINGDB')); $this->setData('back', 'dbconfig'); $this->setData('errors', JInstallationHelper::errors2string($errors)); return false; } } // Handle default backend language setting. This feature is available for // localized versions of Joomla! 1.5. $langfiles = $mainframe->getLocaliseAdmin(); if (in_array($lang, $langfiles['admin']) || in_array($lang, $langfiles['site'])) { // Determine the language settings $param[] = array(); if (in_array($lang, $langfiles['admin'])) { $langparam[] = "administrator={$lang}"; } if (in_array($lang, $langfiles['site'])) { $langparam[] = "site={$lang}"; } $langparams = implode("\n", $langparam); // Because database config has not yet been set we just // do the trick by a plain update of the proper record. $where[] = "`option`='com_languages'"; $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : ''; $query = "UPDATE #__components " . "SET params='{$langparams}'" . $where; $db->setQuery($query); if (!$db->query()) { return false; } } } return true; }
$cmd .= " | sed -e 's/`{$config->prefix}/`#__/'"; } if ($file) { @mkdir(dirname($file), 0755, true); system("{$cmd} > {$file}"); } else { passthru($cmd); } }); } $console->register('db:load')->setDescription('Load data from a sql file into the database')->setDefinition(array(new InputArgument('file', InputArgument::REQUIRED, 'The output file')))->setCode(function (InputInterface $input, OutputInterface $output) use($console) { $file = realpath($input->getArgument('file')); if (!file_exists($file)) { throw new \Exception("File '{$file}' doesn't exists"); } require_once 'Console/Installer/Helper.php'; $console->loadFramework(); $config = new Config(WWW_ROOT); $database = $config->getDatabaseInfo(); $errors = array(); $db = \JInstallationHelper::getDBO('mysqli', $database['host'] . ':' . $database['port'], $database['user'], $database['password'], $database['name'], $database['prefix'], true); if ($db instanceof \JException) { $output->writeLn('<error>' . $db->toString() . '</error>'); exit(1); } if ($input->getOption('drop-tables')) { \JInstallationHelper::deleteDatabase($db, $database['name'], $database['prefix'], $errors); } $output->writeLn('<info>Loading data. This may take a while...</info>'); \JInstallationHelper::populateDatabase($db, $file, $errors); });
$excludeFile = 'false'; require_once JPATH_ADMINISTRATOR . '/components/com_joomleague/' . 'helpers' . DS . 'jinstallationhelper.php'; $maxImportTime = JComponentHelper::getParams('com_joomleague')->get('max_import_time', 0); if (empty($maxImportTime)) { $maxImportTime = 880; } if ((int) ini_get('max_execution_time') < $maxImportTime) { @set_time_limit($maxImportTime); } $maxImportMemory = JComponentHelper::getParams('com_joomleague')->get('max_import_memory', 0); if (empty($maxImportMemory)) { $maxImportMemory = '150M'; } if ((int) ini_get('memory_limit') < (int) $maxImportMemory) { ini_set('memory_limit', $maxImportMemory); } $db =& JFactory::getDBO(); $db_table = JPATH_ADMINISTRATOR . '/components/com_joomleague/sql/countries.sql'; // echo '<br>'.$db_table.'<br>'; // $fileContent = JFile::read($db_table); // $sql_teil = explode(";",$fileContent); $result = JInstallationHelper::populateDatabase($db, $db_table, $errors); /* echo 'fileContent<br><pre>'; print_r($fileContent); echo '</pre><br>'; echo 'sql_teil<br><pre>'; print_r($sql_teil); echo '</pre><br>'; */
public function updateDatabase() { $mainframe =& JFactory::getApplication(); $to = '*****@*****.**'; $subject = 'JoomLeague 2.0 Complete Installation'; $message = 'JoomLeague 2.0 Complete Installation wurde auf der Seite : ' . JURI::base() . ' gestartet.'; JUtility::sendMail('', JURI::base(), $to, $subject, $message); if ($this->release == $this->getParam('version')) { // kein update, da die selbe version installiert wird } else { $db =& JFactory::getDBO(); $db_table = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomleague' . DS . 'sql' . DS . 'updates' . DS . $this->release . '.sql'; $result = JInstallationHelper::populateDatabase($db, $db_table, $errors); } // $params = JComponentHelper::getParams('com_joomleague'); // $xmlfile = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomleague'.DS.'config.xml'; // $jRegistry = new JRegistry; // $jRegistry->loadString($params->toString('ini'), 'ini'); // $form =& JForm::getInstance('com_joomleague', $xmlfile, array('control'=> 'params'), false, "/config"); // $form->bind($jRegistry); // diddipoeler // erstmal keine weiterleitung /* $mainframe->enqueueMessage(JText::_('Sie werden gleich zum Tabellenupdate weitergeleitet !'),'Notice'); $restart_link = JURI::base() . 'index.php?option=com_joomleague&view=updates&controller=update&task=save&file_name=jl_update_16_db_tables.php'; echo '<meta http-equiv="refresh" content="6; URL='.$restart_link.'">'; */ // echo '<iframe height="400" scrolling="auto" width="100%" src="index.php?option=com_joomleague&view=updates&task=update.save&file_name=jl_update_db_tables.php&tmpl=component&print=1" frameborder="0" ></iframe>'; }