コード例 #1
0
ファイル: configuration.php プロジェクト: N6REJ/joomla-cms
 /**
  * Method to create the root user for the site.
  *
  * @param   object  $options  The session options.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  */
 private function _createRootUser($options)
 {
     // Get the application
     /* @var InstallationApplicationWeb $app */
     $app = JFactory::getApplication();
     // Get a database object.
     try {
         $db = InstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
     } catch (RuntimeException $e) {
         $app->enqueueMessage(JText::sprintf('INSTL_ERROR_CONNECT_DB', $e->getMessage()), 'notice');
         return false;
     }
     $cryptpass = JUserHelper::hashPassword($options->admin_password);
     // Take the admin user id.
     $userId = InstallationModelDatabase::getUserId();
     // We don't need the randUserId in the session any longer, let's remove it.
     InstallationModelDatabase::resetRandUserId();
     // Create the admin user.
     date_default_timezone_set('UTC');
     $installdate = date('Y-m-d H:i:s');
     $nullDate = $db->getNullDate();
     // Sqlsrv change.
     $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('id') . ' = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query->clear()->update($db->quoteName('#__users'))->set($db->quoteName('name') . ' = ' . $db->quote('Super User'))->set($db->quoteName('username') . ' = ' . $db->quote(trim($options->admin_user)))->set($db->quoteName('email') . ' = ' . $db->quote($options->admin_email))->set($db->quoteName('password') . ' = ' . $db->quote($cryptpass))->set($db->quoteName('block') . ' = 0')->set($db->quoteName('sendEmail') . ' = 1')->set($db->quoteName('registerDate') . ' = ' . $db->quote($installdate))->set($db->quoteName('lastvisitDate') . ' = ' . $db->quote($nullDate))->set($db->quoteName('activation') . ' = ' . $db->quote('0'))->set($db->quoteName('params') . ' = ' . $db->quote(''))->where($db->quoteName('id') . ' = ' . $db->quote($userId));
     } else {
         $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'), $db->quoteName('email'), $db->quoteName('password'), $db->quoteName('block'), $db->quoteName('sendEmail'), $db->quoteName('registerDate'), $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
         $query->clear()->insert('#__users', true)->columns($columns)->values($db->quote($userId) . ', ' . $db->quote('Super User') . ', ' . $db->quote(trim($options->admin_user)) . ', ' . $db->quote($options->admin_email) . ', ' . $db->quote($cryptpass) . ', ' . $db->quote('0') . ', ' . $db->quote('1') . ', ' . $db->quote($installdate) . ', ' . $db->quote($nullDate) . ', ' . $db->quote('0') . ', ' . $db->quote(''));
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         return false;
     }
     // Map the super admin to the Super Admin Group
     $query->clear()->select($db->quoteName('user_id'))->from($db->quoteName('#__user_usergroup_map'))->where($db->quoteName('user_id') . ' = ' . $db->quote($userId));
     $db->setQuery($query);
     if ($db->loadResult()) {
         $query->clear()->update($db->quoteName('#__user_usergroup_map'))->set($db->quoteName('user_id') . ' = ' . $db->quote($userId))->set($db->quoteName('group_id') . ' = 8');
     } else {
         $query->clear()->insert($db->quoteName('#__user_usergroup_map'), false)->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')))->values($db->quote($userId) . ', 8');
     }
     $db->setQuery($query);
     try {
         $db->execute();
     } catch (RuntimeException $e) {
         $app->enqueueMessage($e->getMessage(), 'notice');
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: database.php プロジェクト: klas/joomla-cms
 /**
  * Method to initialise the database.
  *
  * @param   array  $options  The options to use for configuration.
  *
  * @return  JDatabaseDriver|boolean  Database object on success, boolean false on failure
  *
  * @since   3.1
  */
 public function initialise($options)
 {
     // Get the application.
     /* @var InstallationApplicationWeb $app */
     $app = JFactory::getApplication();
     // Get the options as a object for easier handling.
     $options = JArrayHelper::toObject($options);
     // Load the back-end language files so that the DB error messages work.
     $lang = JFactory::getLanguage();
     $currentLang = $lang->getTag();
     // Load the selected language
     if (JLanguage::exists($currentLang, JPATH_ADMINISTRATOR)) {
         $lang->load('joomla', JPATH_ADMINISTRATOR, $currentLang, true);
     } else {
         $lang->load('joomla', JPATH_ADMINISTRATOR, 'en-GB', true);
     }
     // Ensure a database type was selected.
     if (empty($options->db_type)) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_INVALID_TYPE'), 'notice');
         return false;
     }
     // Ensure that a hostname and user name were input.
     if (empty($options->db_host) || empty($options->db_user)) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_INVALID_DB_DETAILS'), 'notice');
         return false;
     }
     // Ensure that a database name was input.
     if (empty($options->db_name)) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_EMPTY_NAME'), 'notice');
         return false;
     }
     // Validate database table prefix.
     if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $options->db_prefix)) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_PREFIX_MSG'), 'notice');
         return false;
     }
     // Validate length of database table prefix.
     if (strlen($options->db_prefix) > 15) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_FIX_TOO_LONG'), 'notice');
         return false;
     }
     // Validate length of database name.
     if (strlen($options->db_name) > 64) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_TOO_LONG'), 'notice');
         return false;
     }
     // Workaround for UPPERCASE table prefix for postgresql
     if ($options->db_type == 'postgresql') {
         if (strtolower($options->db_prefix) != $options->db_prefix) {
             $app->enqueueMessage(JText::_('INSTL_DATABASE_FIX_LOWERCASE'), 'notice');
             return false;
         }
     }
     // Get a database object.
     try {
         return InstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix, $options->db_select);
     } catch (RuntimeException $e) {
         $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()), 'notice');
         return false;
     }
 }
コード例 #3
0
ファイル: database.php プロジェクト: exntu/joomla-cms
 /**
  * @since	3.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 = InstallationHelperDatabase::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
         if ($type == 'mysqli' || $type == 'mysql') {
             $dblocalise = 'sql/mysql/localise.sql';
         } elseif ($type == 'sqlsrv' || $type == 'sqlazure') {
             $dblocalise = 'sql/sqlazure/localise.sql';
         } else {
             $dblocalise = 'sql/' . $type . '/localise.sql';
         }
         if (JFile::exists($dblocalise)) {
             if (!$this->populateDatabase($db, $dblocalise)) {
                 $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.
         $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;
 }