Esempio n. 1
0
 /**
  * Gets the basic site parameters
  *
  * @return  array
  */
 protected function getSiteParamsVars()
 {
     $siteurl = str_replace('/installation/', '', AUri::root());
     $homeurl = str_replace('/installation/', '', AUri::root());
     $ret = array('blogname' => $this->getState('blogname', $this->configModel->get('blogname', 'Restored website')), 'blogdescription' => $this->getState('blogdescription', $this->configModel->get('blogdescription', 'Restored website')), 'dbcharset' => $this->getState('dbcharset', $this->configModel->get('dbcharset', 'utf_8')), 'dbcollation' => $this->getState('dbcollation', $this->configModel->get('dbcollation', '')), 'homeurl' => $this->getState('homeurl', $homeurl), 'siteurl' => $this->getState('siteurl', $siteurl));
     require_once APATH_INSTALLATION . '/angie/helpers/setup.php';
     $ret['homeurl'] = AngieHelperSetup::cleanLiveSite($ret['homeurl']);
     $ret['siteurl'] = AngieHelperSetup::cleanLiveSite($ret['siteurl']);
     $this->configModel->set('siteurl', $ret['siteurl']);
     $this->configModel->set('homeurl', $ret['homeurl']);
     // Special handling: if we were told to downgrade data from utf8mb4 to utf8 and the dbcharset or dbcollation
     // contains utf8mb4 we have to downgrade that too to utf8.
     /** @var AngieModelDatabase $dbModel */
     $dbModel = AModel::getTmpInstance('Database', 'AngieModel');
     $allDbIni = $dbModel->getDatabasesIni();
     $dbNames = $dbModel->getDatabaseNames();
     $firstDb = array_shift($dbNames);
     $dbIni = $allDbIni[$firstDb];
     $dbOptions = array('driver' => $dbIni['dbtype'], 'database' => $dbIni['dbname'], 'select' => 0, 'host' => $dbIni['dbhost'], 'user' => $dbIni['dbuser'], 'password' => $dbIni['dbpass'], 'prefix' => $dbIni['prefix']);
     $db = ADatabaseDriver::getInstance($dbOptions);
     $downgradeUtf8 = $dbIni['utf8tables'] && (!$dbIni['utf8mb4'] || $dbIni['utf8mb4'] && !$db->supportsUtf8mb4());
     if ($downgradeUtf8) {
         $ret['dbcharset'] = str_replace('utf8mb4', 'utf8', $ret['dbcharset']);
         $ret['dbcollation'] = str_replace('utf8mb4', 'utf8', $ret['dbcollation']);
         $this->configModel->set('dbcharset', $ret['dbcharset']);
         $this->configModel->set('dbcollation', $ret['dbcollation']);
     }
     return $ret;
 }
Esempio n. 2
0
 /**
  * Database object constructor
  *
  * @param   array  $options  List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     // Finalize initialization
     parent::__construct($options);
 }
Esempio n. 3
0
 /**
  * Constructor.
  *
  * @param   array  $options  List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     // Finalize initialisation
     parent::__construct($options);
 }
Esempio n. 4
0
 public static function dbtype($selected = 'mysqli', $technology = null)
 {
     $connectors = ADatabaseDriver::getConnectors($technology);
     $options = array();
     foreach ($connectors as $connector) {
         $options[] = self::option($connector, AText::_('DATABASE_LBL_TYPE_' . $connector));
     }
     return self::genericlist($options, 'dbtype', null, 'value', 'text', $selected);
 }
Esempio n. 5
0
 /**
  * Constructor.
  *
  * @param   array $options List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     // Get the default UTF8MB4 option
     $defaultAllowUtf8Mb4 = null;
     if (defined('ANGIE_ALLOW_UTF8MB4_DEFAULT')) {
         $defaultAllowUtf8Mb4 = ANGIE_ALLOW_UTF8MB4_DEFAULT;
     }
     // Get some basic values from the options.
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '******';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $options['select'] = isset($options['select']) ? (bool) $options['select'] : true;
     $options['port'] = isset($options['port']) ? (int) $options['port'] : null;
     $options['socket'] = isset($options['socket']) ? $options['socket'] : null;
     $options['utf8mb4'] = isset($options['utf8mb4']) ? $options['utf8mb4'] : $defaultAllowUtf8Mb4;
     // Figure out if a port is included in the host name
     if (empty($options['port'])) {
         // Unlike mysql_connect(), mysqli_connect() takes the port and socket
         // as separate arguments. Therefore, we have to extract them from the
         // host string.
         $options['port'] = null;
         $options['socket'] = null;
         $targetSlot = substr(strstr($options['host'], ":"), 1);
         if (!empty($targetSlot)) {
             // Get the port number or socket name
             if (is_numeric($targetSlot)) {
                 $options['port'] = $targetSlot;
             } else {
                 $options['socket'] = $targetSlot;
             }
             // Extract the host name only
             $host = substr($options['host'], 0, strlen($options['host']) - (strlen($targetSlot) + 1));
             // This will take care of the following notation: ":3306"
             if ($host == '') {
                 $options['host'] = 'localhost';
             }
         }
     }
     // Finalize initialisation.
     parent::__construct($options);
 }
Esempio n. 6
0
File: pdo.php Progetto: akeeba/angie
 /**
  * Sets the SQL statement string for later execution.
  *
  * @param   mixed    $query          The SQL statement to set either as a JDatabaseQuery object or a string.
  * @param   integer  $offset         The affected row offset to set.
  * @param   integer  $limit          The maximum affected rows to set.
  * @param   array    $driverOptions  The optional PDO driver options
  *
  * @return  Pdo  This object to support method chaining.
  *
  * @since   1.0
  */
 public function setQuery($query, $offset = null, $limit = null, $driverOptions = array())
 {
     $this->connect();
     $this->freeResult();
     if (is_string($query)) {
         // Allows taking advantage of bound variables in a direct query:
         $query = $this->getQuery(true)->setQuery($query);
     }
     if ($query instanceof ADatabaseQueryLimitable && !is_null($offset) && !is_null($limit)) {
         $query->setLimit($limit, $offset);
     }
     $sql = $this->replacePrefix((string) $query);
     $this->prepared = $this->connection->prepare($sql, $driverOptions);
     // Store reference to the DatabaseQuery instance:
     parent::setQuery($query, $offset, $limit);
     return $this;
 }
Esempio n. 7
0
 /**
  * Get the map of IDs to blog URLs
  *
  * @param   ADatabaseDriver $db The database connection
  *
  * @return  array  The map, or an empty array if this is not a multisite installation
  */
 protected function getMultisiteMap($db)
 {
     static $map = null;
     if (is_null($map)) {
         /** @var AngieModelWordpressConfiguration $config */
         $config = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container);
         // Which site ID should I use?
         $site_id = $config->get('site_id_current_site', 1);
         // Get all of the blogs of this site
         $query = $db->getQuery(true)->select(array($db->qn('blog_id'), $db->qn('domain'), $db->qn('path')))->from($db->qn('#__blogs'))->where($db->qn('site_id') . ' = ' . $db->q($site_id));
         try {
             $map = $db->setQuery($query)->loadAssocList('blog_id');
         } catch (Exception $e) {
             $map = array();
         }
     }
     return $map;
 }
Esempio n. 8
0
 /**
  * Returns the instance of the database driver, creating it if it doesn't
  * exist.
  *
  * @return  ADatabaseDriver
  *
  * @throws RuntimeException
  */
 protected function getDatabase()
 {
     if (!is_object($this->db)) {
         $options = array('driver' => $this->dbiniValues['dbtype'], 'database' => $this->dbiniValues['dbname'], 'select' => 0, 'host' => $this->dbiniValues['dbhost'], 'user' => $this->dbiniValues['dbuser'], 'password' => $this->dbiniValues['dbpass'], 'prefix' => $this->dbiniValues['prefix']);
         $class = 'ADatabaseDriver' . ucfirst(strtolower($options['driver']));
         try {
             $this->db = new $class($options);
             $this->db->setUTF();
         } catch (RuntimeException $e) {
             throw new RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage()));
         }
     }
     return $this->db;
 }
Esempio n. 9
0
 /**
  * Perform a simple replacement on the current table
  *
  * @param ADatabaseDriver $db
  *
  * @return void
  */
 protected function performSimpleReplacement($db)
 {
     $tableName = $this->currentTable['table'];
     // Run all replacements
     foreach ($this->replacements as $from => $to) {
         $query = $db->getQuery(true)->update($db->qn($tableName));
         foreach ($this->currentTable['fields'] as $field) {
             $query->set($db->qn($field) . ' = REPLACE(' . $db->qn($field) . ', ' . $db->q($from) . ', ' . $db->q($to) . ')');
         }
         try {
             $db->setQuery($query)->execute();
         } catch (Exception $e) {
             // Do nothing if the replacement fails
         }
     }
 }