示例#1
0
文件: Mysql.php 项目: igorclark/piwik
 /**
  * Connects to the DB
  *
  * @throws Exception if there was an error connecting the DB
  */
 public function connect()
 {
     if (self::$profiling) {
         $timer = $this->initProfiler();
     }
     $config = PiwikDb::getDatabaseConfig();
     $this->connection = @new PDO($this->dsn, $this->username, $this->password, $config['driver_options']);
     $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // we may want to setAttribute(PDO::ATTR_TIMEOUT ) to a few seconds (default is 60) in case the DB is locked
     // the piwik.php would stay waiting for the database... bad!
     // we delete the password from this object "just in case" it could be printed
     $this->password = '';
     /*
      * Lazy initialization via MYSQL_ATTR_INIT_COMMAND depends
      * on mysqlnd support, PHP version, and OS.
      * see ZF-7428 and http://bugs.php.net/bug.php?id=47224
      */
     if (!empty($this->charset)) {
         $sql = "SET NAMES '" . $this->charset . "'";
         $this->connection->exec($sql);
     }
     if (self::$profiling && isset($timer)) {
         $this->recordQueryProfile('connect', $timer);
     }
 }
 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));
     });
 }
示例#3
0
 private function getDbName()
 {
     $dbInfos = Db::getDatabaseConfig();
     $dbName = $dbInfos['dbname'];
     return $dbName;
 }
示例#4
0
 private function getDbSetting($key)
 {
     $dbInfos = Db::getDatabaseConfig();
     $engine = $dbInfos[$key];
     return $engine;
 }