Esempio n. 1
0
 /**
  * connects to migration.db, or creates if not found
  * @param string $path to migration.db, defaults to user data dir
  * @return bool whether the operation was successful
  */
 private static function connectDB($path = null)
 {
     // Has the dbpath been set?
     self::$dbpath = !is_null($path) ? $path : self::$dbpath;
     if (!self::$dbpath) {
         OC_Log::write('migration', 'connectDB() was called without dbpath being set', OC_Log::ERROR);
         return false;
     }
     // Already connected
     if (!self::$migration_database) {
         $datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
         $connectionParams = array('path' => self::$dbpath, 'driver' => 'pdo_sqlite');
         $connectionParams['adapter'] = '\\OC\\DB\\AdapterSqlite';
         $connectionParams['wrapperClass'] = 'OC\\DB\\Connection';
         $connectionParams['tablePrefix'] = '';
         // Try to establish connection
         self::$migration_database = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @brief connects to migration.db, or creates if not found
  * @param $db optional path to migration.db, defaults to user data dir
  * @return bool whether the operation was successful
  */
 private static function connectDB($path = null)
 {
     // Has the dbpath been set?
     self::$dbpath = !is_null($path) ? $path : self::$dbpath;
     if (!self::$dbpath) {
         OC_Log::write('migration', 'connectDB() was called without dbpath being set', OC_Log::ERROR);
         return false;
     }
     // Already connected
     if (!self::$MDB2) {
         require_once 'MDB2.php';
         $datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
         // DB type
         if (class_exists('SQLite3')) {
             $dbtype = 'sqlite3';
         } else {
             if (is_callable('sqlite_open')) {
                 $dbtype = 'sqlite';
             } else {
                 OC_Log::write('migration', 'SQLite not found', OC_Log::ERROR);
                 return false;
             }
         }
         // Prepare options array
         $options = array('portability' => MDB2_PORTABILITY_ALL & !MDB2_PORTABILITY_FIX_CASE, 'log_line_break' => '<br>', 'idxname_format' => '%s', 'debug' => true, 'quote_identifier' => true);
         $dsn = array('phptype' => $dbtype, 'database' => self::$dbpath, 'mode' => '0644');
         // Try to establish connection
         self::$MDB2 = MDB2::factory($dsn, $options);
         // Die if we could not connect
         if (PEAR::isError(self::$MDB2)) {
             die(self::$MDB2->getMessage());
             OC_Log::write('migration', 'Failed to create/connect to migration.db', OC_Log::FATAL);
             OC_Log::write('migration', self::$MDB2->getUserInfo(), OC_Log::FATAL);
             OC_Log::write('migration', self::$MDB2->getMessage(), OC_Log::FATAL);
             return false;
         }
         // We always, really always want associative arrays
         self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
     }
     return true;
 }