Skip to content
Snippets Groups Projects
Commit 721311c9 authored by Robin Appelman's avatar Robin Appelman
Browse files

some minor optimizations

parent 926b2b78
Branches
No related tags found
No related merge requests found
......@@ -36,18 +36,14 @@ class OC_DB {
static private $affected=0;
static private $result=false;
static private $inTransaction=false;
static private $prefix=null;
static private $type=null;
/**
* @brief connects to the database
* @returns true if connection can be established or nothing (die())
*
* Connects to the database as specified in config.php
* check which backend we should use
* @return BACKEND_MDB2 or BACKEND_PDO
*/
public static function connect($backend=null){
if(self::$connection){
return;
}
if(is_null($backend)){
private static function getDBBackend(){
$backend=self::BACKEND_MDB2;
if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
$type = OC_Config::getValue( "dbtype", "sqlite" );
......@@ -58,6 +54,20 @@ class OC_DB {
}
}
}
/**
* @brief connects to the database
* @returns true if connection can be established or nothing (die())
*
* Connects to the database as specified in config.php
*/
public static function connect($backend=null){
if(self::$connection){
return;
}
if(is_null($backend)){
$backend=self::getDBBackend();
}
if($backend==self::BACKEND_PDO){
self::connectPDO();
self::$connection=self::$PDO;
......@@ -423,8 +433,14 @@ class OC_DB {
private static function processQuery( $query ){
self::connect();
// We need Database type and table prefix
$type = OC_Config::getValue( "dbtype", "sqlite" );
$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
if(is_null(self::$type)){
self::$type=OC_Config::getValue( "dbtype", "oc_" );
}
$type = self::$type;
if(is_null(self::$prefix)){
self::$prefix=OC_Config::getValue( "dbtableprefix", "oc_" );
}
$prefix = self::$prefix;
// differences in escaping of table names ('`' for mysql) and getting the current timestamp
if( $type == 'sqlite' || $type == 'sqlite3' ){
......
......@@ -261,18 +261,15 @@ class OC_L10N{
public static function findAvailableLanguages($app=null){
$available=array('en');//english is always available
$dir = self::findI18nDir($app);
if(file_exists($dir)){
$dh = opendir($dir);
while(($file = readdir($dh)) !== false){
if(substr($file, -4, 4) == '.php' and (strlen($file) == 6 || strlen($file) == 9)){
if(is_dir($dir)){
$files=scandir($dir);
foreach($files as $file){
if(substr($file, -4, 4) == '.php'){
$i = substr($file, 0, -4);
if($i != ''){
$available[] = $i;
}
}
}
closedir($dh);
}
return $available;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment