factory() public static method

Create adapter
public static factory ( string $adapterName, array &$dbInfos, boolean $connect = true ) : Piwik\Db\AdapterInterface
$adapterName string database adapter name
$dbInfos array database connection info
$connect boolean
return Piwik\Db\AdapterInterface
コード例 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Set memory limit to off
     @ini_set('memory_limit', -1);
     Piwik::doAsSuperUser(function () use($input, $output) {
         $settings = new MigratorSettings();
         $settings->idSite = $input->getArgument('idSite');
         $settings->site = $this->getSite($settings->idSite);
         $settings->dateFrom = $input->getOption('date-from') ? new \DateTime($input->getOption('date-from')) : null;
         $settings->dateTo = $input->getOption('date-to') ? new \DateTime($input->getOption('date-to')) : null;
         $settings->skipArchiveData = $input->getOption('skip-archive-data');
         $settings->skipLogData = $input->getOption('skip-log-data');
         $config = Db::getDatabaseConfig();
         $startTime = microtime(true);
         $this->createTargetDatabaseConfig($input, $output, $config);
         $tmpConfig = $config;
         $sourceDb = Db::get();
         try {
             $targetDb = @Db\Adapter::factory($config['adapter'], $tmpConfig);
         } catch (\Exception $e) {
             throw new \RuntimeException('Unable to connect to the target database: ' . $e->getMessage(), 0, $e);
         }
         $sourceDbHelper = new DBHelper($sourceDb, Db::getDatabaseConfig());
         $migratorFacade = new Migrator($sourceDbHelper, new DBHelper($targetDb, $config), GCHelper::getInstance(), $settings, new ArchiveLister($sourceDbHelper));
         $migratorFacade->migrate();
         $endTime = microtime(true);
         Log::debug(sprintf('Time taken: %01.2f sec', $endTime - $startTime));
         Log::debug(sprintf('Peak memory usage: %01.2f MB', memory_get_peak_usage(true) / 1048576));
     });
 }
コード例 #2
0
ファイル: FormDatabaseSetup.php プロジェクト: imreFitos/piwik
 /**
  * Creates database object based on form data.
  *
  * @throws Exception|Zend_Db_Adapter_Exception
  * @return array The database connection info. Can be passed into Piwik::createDatabaseObject.
  */
 public function createDatabaseObject()
 {
     $dbname = $this->getSubmitValue('dbname');
     if (empty($dbname)) {
         throw new Exception("No database name");
     }
     $adapter = $this->getSubmitValue('adapter');
     $port = Adapter::getDefaultPortForAdapter($adapter);
     $dbInfos = array('host' => $this->getSubmitValue('host'), 'username' => $this->getSubmitValue('username'), 'password' => $this->getSubmitValue('password'), 'dbname' => $dbname, 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port, 'schema' => Config::getInstance()->database['schema'], 'type' => $this->getSubmitValue('type'));
     if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
         // unix_socket=/path/sock.n
         $dbInfos['port'] = substr($dbInfos['host'], $portIndex);
         $dbInfos['host'] = '';
     } else {
         if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
             // host:port
             $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
             $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
         }
     }
     try {
         @Db::createDatabaseObject($dbInfos);
     } catch (Zend_Db_Adapter_Exception $e) {
         $db = Adapter::factory($adapter, $dbInfos, $connect = false);
         // database not found, we try to create  it
         if ($db->isErrNo($e, '1049')) {
             $dbInfosConnectOnly = $dbInfos;
             $dbInfosConnectOnly['dbname'] = null;
             @Db::createDatabaseObject($dbInfosConnectOnly);
             @DbHelper::createDatabase($dbInfos['dbname']);
             // select the newly created database
             @Db::createDatabaseObject($dbInfos);
         } else {
             throw $e;
         }
     }
     return $dbInfos;
 }
コード例 #3
0
ファイル: Db.php プロジェクト: FluentDevelopment/piwik
 /**
  * Connects to the database.
  *
  * Shouldn't be called directly, use {@link get()} instead.
  *
  * @param array|null $dbConfig Connection parameters in an array. Defaults to the `[database]`
  *                             INI config section.
  */
 public static function createDatabaseObject($dbConfig = null)
 {
     $dbConfig = self::getDatabaseConfig($dbConfig);
     $db = @Adapter::factory($dbConfig['adapter'], $dbConfig);
     self::$connection = $db;
 }
コード例 #4
0
ファイル: Db.php プロジェクト: KiwiJuicer/handball-dachau
 /**
  * Connects to the database.
  * 
  * Shouldn't be called directly, use {@link get()} instead.
  * 
  * @param array|null $dbInfos Connection parameters in an array. Defaults to the `[database]`
  *                            INI config section.
  */
 public static function createDatabaseObject($dbInfos = null)
 {
     $config = Config::getInstance();
     if (is_null($dbInfos)) {
         $dbInfos = $config->database;
     }
     /**
      * Triggered before a database connection is established.
      * 
      * This event can be used to change the settings used to establish a connection.
      * 
      * @param array *$dbInfos Reference to an array containing database connection info,
      *                        including:
      * 
      *                        - **host**: The host name or IP address to the MySQL database.
      *                        - **username**: The username to use when connecting to the
      *                                        database.
      *                        - **password**: The password to use when connecting to the
      *                                       database.
      *                        - **dbname**: The name of the Piwik MySQL database.
      *                        - **port**: The MySQL database port to use.
      *                        - **adapter**: either `'PDO_MYSQL'` or `'MYSQLI'`
      */
     Piwik::postEvent('Reporting.getDatabaseConfig', array(&$dbInfos));
     $dbInfos['profiler'] = $config->Debug['enable_sql_profiler'];
     $adapter = $dbInfos['adapter'];
     $db = @Adapter::factory($adapter, $dbInfos);
     self::$connection = $db;
 }