/** * Shorthand method to get the connection to the current database * * @return ADatabaseDriver */ protected function getDatabase() { $connectionVars = $this->getDbConnectionVars(); $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); return $db; }
/** * Get a reference to the database driver object * * @return ADatabaseDriver */ public function &getDbo() { if (!is_object($this->db)) { /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $this->db = ADatabaseFactory::getInstance()->getDriver($name, $options); $this->db->setUTF(); } return $this->db; }
private function updateStore() { $version = $this->container->session->get('version'); $name = $this->get('dbtype'); $options = array('database' => $this->get('dbname'), 'select' => 1, 'host' => $this->get('dbhost'), 'user' => $this->get('dbuser'), 'password' => $this->get('dbpass'), 'prefix' => $this->get('dbprefix')); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); if (version_compare($version, '1.5', 'lt')) { $id = 'id_store'; $table = '#__store'; } else { $id = 'id_shop'; $table = '#__shop'; } $query = $db->getQuery(true)->select('MIN(' . $db->qn($id) . ')')->from($db->qn($table)); $shopid = $db->setQuery($query)->loadResult(); // Update the Shop name. We're just updating the first shop, in the future we'll have to // take care of multi-shops, too $query = $db->getQuery(true)->update($db->qn($table))->set($db->qn('name') . ' = ' . $db->q($this->get('sitename')))->where($db->qn($id) . ' = ' . $db->q($shopid)); $db->setQuery($query)->execute(); // Update shop links. Again, we're updating only the first shop $site = str_replace('https://', '', $this->get('siteurl')); $site = str_replace('http://', '', $site); list($root, $folder) = explode('/', $site, 2); $root = trim($root, '/'); // The URL table is available under PS 1.5 and later if (version_compare($version, '1.5', 'gt')) { if ($folder) { $folder = '/' . trim($folder, '/') . '/'; } else { $folder = '/'; } $query = $db->getQuery(true)->update($db->qn('#__shop_url'))->set($db->qn('domain') . ' = ' . $db->q($root))->set($db->qn('domain_ssl') . ' = ' . $db->q($root))->set($db->qn('physical_uri') . ' = ' . $db->q($folder))->where($db->qn('id_shop') . ' = ' . $db->q($shopid)); $db->setQuery($query)->execute(); } // Prestashop has a big table that holds all the variables, we have to update it, too $query = $db->getQuery(true)->update($db->qn('#__configuration'))->set($db->qn('value') . ' = ' . $db->q($root))->where($db->qn('name') . ' IN(' . $db->q('PS_SHOP_DOMAIN') . ', ' . $db->q('PS_SHOP_DOMAIN_SSL') . ')'); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__configuration'))->set($db->qn('value') . ' = ' . $db->q($this->get('sitename')))->where($db->qn('name') . ' = ' . $db->q('PS_SHOP_NAME')); $db->setQuery($query)->execute(); }
/** * Gets an instance of a factory object to return on subsequent calls of getInstance. * * @param ADatabaseFactory $instance A ADatabaseFactory object. * * @return void */ public static function setInstance(ADatabaseFactory $instance = null) { self::$_instance = $instance; }
/** * Merges configuration options read from the settings.php file with the options stored inside the database * * @param string $key Site key we are currently working on * @param array $config Configuration loaded from the settings.php file */ protected function getOptionsFromDatabase($key, &$config) { $connectionVars = $this->getDatabase($key); try { $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); $searchFor = array($db->q('file_temporary_path'), $db->q('site_mail'), $db->q('site_name')); $query = $db->getQuery(true)->select(array($db->qn('name'), $db->qn('value')))->from('#__variable')->where($db->qn('name') . ' IN (' . implode(',', $searchFor) . ')'); $options = $db->setQuery($query)->loadObjectList(); foreach ($options as $option) { $key = $option->name; // Let's normalize the name of the config vars if ($option->name == 'file_temporary_path') { $key = 'tmp_path'; } elseif ($option->name == 'site_name') { $key = 'sitename'; } // Strings are stored as serialized objects... $config[$key] = unserialize($option->value); } } catch (Exception $exc) { // Well, what the hell... } }
/** * Writes the new config params inside the wp-config file and the database. * * @param string $file * * @return bool */ public function writeConfig($file) { // First of all I'll save the options stored inside the db. In this way, even if // the configuration file write fails, the user has only to manually update the // config file and he's ready to go. $name = $this->get('dbtype'); $options = array('database' => $this->get('dbname'), 'select' => 1, 'host' => $this->get('dbhost'), 'user' => $this->get('dbuser'), 'password' => $this->get('dbpass'), 'prefix' => $this->get('dbprefix')); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); // If supplied in the request (ie restoring using UNiTE) let's use that URL $livesite = $this->get('livesite', ''); if (!$livesite) { $livesite = AUri::root(); } $url = str_replace('/installation', '', $livesite); // The URL must end with a slash $url = rtrim($url, '/') . '/'; $query = $db->getQuery(true)->update($db->qn('#__core_config_data'))->set($db->qn('value') . ' = ' . $db->q($url))->where($db->qn('path') . ' = ' . $db->q('web/unsecure/base_url')); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__core_config_data'))->set($db->qn('value') . ' = ' . $db->q($url))->where($db->qn('path') . ' = ' . $db->q('web/secure/base_url')); $db->setQuery($query)->execute(); $new_config = $this->getFileContents($file); if (!file_put_contents($file, $new_config)) { return false; } return true; }
/** * Merges configuration options read from the settings.php file with the options stored inside the database * * @param string $key Site key we are currently working on * @param array $config Configuration loaded from the settings.php file */ protected function getOptionsFromDatabase($key, &$config) { $connectionVars = $this->getDatabase($key); // Drupal 8 stores configuration values inside serialized PHP objects try { $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); $query = $db->getQuery(true)->select($db->qn('data'))->from('#__config')->where($db->qn('name') . ' = ' . $db->q('system.site')); $serialized = $db->setQuery($query)->loadResult(); $drupal_config = @unserialize($serialized); // Something bad while unserializing it? Let's stop here if ($drupal_config !== false) { $config['sitename'] = $drupal_config['name']; $config['site_mail'] = $drupal_config['mail']; } $query = $db->getQuery(true)->select($db->qn('data'))->from('#__config')->where($db->qn('name') . ' = ' . $db->q('system.file')); $serialized = $db->setQuery($query)->loadResult(); $drupal_config = @unserialize($serialized); // Something bad while unserializing it? Let's stop here if ($drupal_config !== false) { $config['tmp_path'] = $drupal_config['path']['temporary']; } } catch (Exception $exc) { // Well, what the hell... } }
/** * @param $config */ protected function getOptionsFromDatabase(&$config) { // PageKit has some options set inside the db, too /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); try { $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); $query = $db->getQuery(true)->select($db->qn('value'))->from('#__system_config')->where($db->qn('name') . ' = ' . $db->q('system/site')); $pk_options = $db->setQuery($query)->loadResult(); $pk_options = json_decode($pk_options, true); if ($pk_options && isset($pk_options['title'])) { $config['sitename'] = $pk_options['title']; } } catch (Exception $exc) { } }
/** * Writes the new config params inside the config.php file and the database. * * @param string $file * * @return bool */ public function writeConfig($file) { // First of all I'll save the options stored inside the db. In this way, even if // the configuration file write fails, the user has only to manually update the // config file and he's ready to go. /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); /* * We have to update the following values: Fullname and short name, chat host and ip, * create a new exportsalt for calendars, create a new site identifier */ // Update site fullname and shortname $query = $db->getQuery(true)->update($db->qn('#__course'))->set($db->qn('fullname') . ' = ' . $db->q($this->get('fullname')))->set($db->qn('shortname') . ' = ' . $db->q($this->get('shortname')))->where($db->qn('category') . ' = ' . $db->q(0)); $db->setQuery($query)->execute(); // Create a new site identifier $newsiteidentifier = $this->random_string(32) . $_SERVER['HTTP_HOST']; $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('value') . ' = ' . $db->q($newsiteidentifier))->where($db->qn('name') . ' = ' . $db->q('siteidentifier')); $db->setQuery($query)->execute(); // Create a new export calendar salt $new_salt = $this->random_string(60); $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('value') . ' = ' . $db->q($new_salt))->where($db->qn('name') . ' = ' . $db->q('calendar_exportsalt')); $db->setQuery($query)->execute(); // Update the chat server host $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('value') . ' = ' . $db->q($this->get('chat_host')))->where($db->qn('name') . ' = ' . $db->q('chat_serverhost')); $db->setQuery($query)->execute(); // Update the chat server ip $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('value') . ' = ' . $db->q($this->get('chat_ip')))->where($db->qn('name') . ' = ' . $db->q('chat_serverip')); $db->setQuery($query)->execute(); $new_config = $this->getFileContents($file); if (!file_put_contents($file, $new_config)) { return false; } return true; }
/** * @param $config */ protected function getOptionsFromDatabase(&$config) { // Wordpress has some options set inside the db, too /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); try { $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); $searchFor = array($db->q('blogname'), $db->q('blogdescription'), $db->q('home'), $db->q('siteurl')); $query = $db->getQuery(true)->select(array($db->qn('option_name'), $db->qn('option_value')))->from('#__options')->where($db->qn('option_name') . ' IN (' . implode(',', $searchFor) . ')'); $wp_options = $db->setQuery($query)->loadObjectList(); foreach ($wp_options as $option) { // Let me save the old home url, it will useful later when I'll have to replace it inside the posts if ($option->option_name == 'home') { $config['oldurl'] = $option->option_value; } else { $config[$option->option_name] = $option->option_value; } } } catch (Exception $exc) { } }
private function applySuperAdminChanges() { // Get the Super User ID. If it's empty, skip. $id = $this->getState('superuserid', 0); if (!$id) { return false; } // Get the Super User email and password $email = $this->getState('superuseremail', ''); $password1 = $this->getState('superuserpassword', ''); $password2 = $this->getState('superuserpasswordrepeat', ''); // If the email is empty but the passwords are not, fail if (empty($email)) { if (empty($password1) && empty($password2)) { return false; } else { throw new Exception(AText::_('SETUP_ERR_EMAILEMPTY')); } } // If the passwords are empty, skip if (empty($password1) && empty($password2)) { return false; } // Make sure the passwords match if ($password1 != $password2) { throw new Exception(AText::_('SETUP_ERR_PASSWORDSDONTMATCH')); } // Let's load the password compatibility file require_once APATH_ROOT . '/installation/framework/utils/password.php'; // Connect to the database $connectionVars = $this->getDbConnectionVars(); $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); // Create a new encrypted password, at the moment (July 2015) Mautic is using a cost of 13 $cryptpass = password_hash($password1, PASSWORD_BCRYPT, array('cost' => 13)); // Update the database record $query = $db->getQuery(true)->update($db->qn('#__users'))->set($db->qn('password') . ' = ' . $db->q($cryptpass))->set($db->qn('email') . ' = ' . $db->q($email))->where($db->qn('id') . ' = ' . $db->q($id)); $db->setQuery($query); $db->execute(); return true; }
/** * Writes the new config params inside the config file and the database. * * @param string $file * * @return bool */ public function writeConfig($file) { // First of all I'll save the options stored inside the db. In this way, even if // the configuration file write fails, the user has only to manually update the // config file and he's ready to go. $name = $this->get('dbtype'); $options = array('database' => $this->get('dbname'), 'select' => 1, 'host' => $this->get('dbhost'), 'user' => $this->get('dbuser'), 'password' => $this->get('dbpass'), 'prefix' => $this->get('dbprefix')); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); try { $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($this->get('sitename')))->where($db->qn('config_name') . ' = ' . $db->q('sitename')); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($this->get('sitedescr')))->where($db->qn('config_name') . ' = ' . $db->q('site_desc')); $db->setQuery($query)->execute(); $url = $this->get('siteurl'); if (strpos($url, 'https://') !== false) { $protocol = 'https://'; } else { $protocol = 'http://'; } $url = str_replace($protocol, '', $url); list($server, $folder) = explode('/', $url, 2); if ($folder) { $folder = '/' . trim($folder, '/'); } else { $folder = '/'; } $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($protocol))->where($db->qn('config_name') . ' = ' . $db->q('server_protocol')); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($server))->where($db->qn('config_name') . ' = ' . $db->q('server_name')); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($server))->where($db->qn('config_name') . ' = ' . $db->q('cookie_domain')); $db->setQuery($query)->execute(); $query = $db->getQuery(true)->update($db->qn('#__config'))->set($db->qn('config_value') . ' = ' . $db->q($folder))->where($db->qn('config_name') . ' = ' . $db->q('script_path')); $db->setQuery($query)->execute(); } catch (Exception $e) { // This should never happen... } $new_config = $this->getFileContents($file); if (!file_put_contents($file, $new_config)) { return false; } return true; }