diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-06-29 21:46:09 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-06-29 21:46:09 +0200 |
commit | 246894243a1be7977df66e594549b9ac25c8ebf1 (patch) | |
tree | 4a3c233853f011e80eedad6fbf617b0bca0a782d /lib | |
parent | 08e707d25821fd6111ed8f8b91aa5f77ee1b490f (diff) | |
parent | 719c7f7f6ebfe53a73eeffb07c6c23d6a788e711 (diff) | |
download | nextcloud-server-246894243a1be7977df66e594549b9ac25c8ebf1.tar.gz nextcloud-server-246894243a1be7977df66e594549b9ac25c8ebf1.zip |
Merge branch 'master' into calendar_import
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/app.php | 13 | ||||
-rw-r--r-- | lib/files.php | 4 | ||||
-rw-r--r-- | lib/helper.php | 9 | ||||
-rw-r--r-- | lib/migrate.php | 6 | ||||
-rw-r--r-- | lib/setup.php | 37 |
5 files changed, 54 insertions, 15 deletions
diff --git a/lib/app.php b/lib/app.php index a9feff1620a..4c2c43ec26b 100755 --- a/lib/app.php +++ b/lib/app.php @@ -36,6 +36,7 @@ class OC_App{ static private $appInfo = array(); static private $appTypes = array(); static private $loadedApps = array(); + static private $checkedApps = array(); /** * @brief loads all apps @@ -349,9 +350,13 @@ class OC_App{ protected static function findAppInDirectories($appid) { + static $app_dir = array(); + if (isset($app_dir[$appid])) { + return $app_dir[$appid]; + } foreach(OC::$APPSROOTS as $dir) { if(file_exists($dir['path'].'/'.$appid)) { - return $dir; + return $app_dir[$appid]=$dir; } } } @@ -530,6 +535,10 @@ class OC_App{ * check if the app need updating and update when needed */ public static function checkUpgrade($app) { + if (in_array($app, self::$checkedApps)) { + return; + } + self::$checkedApps[] = $app; $versions = self::getAppVersions(); $currentVersion=OC_App::getAppVersion($app); if ($currentVersion) { @@ -564,7 +573,7 @@ class OC_App{ } /** - * get the installed version of all papps + * get the installed version of all apps */ public static function getAppVersions(){ static $versions; diff --git a/lib/files.php b/lib/files.php index 469c3a15b8e..d5bebb7e549 100644 --- a/lib/files.php +++ b/lib/files.php @@ -167,10 +167,12 @@ class OC_Files { * @param file $target */ public static function move($sourceDir,$source,$targetDir,$target){ - if(OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared')){ + if(OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared') && !OC_Filesystem::file_exists($targetDir.'/'.$target)){ $targetFile=self::normalizePath($targetDir.'/'.$target); $sourceFile=self::normalizePath($sourceDir.'/'.$source); return OC_Filesystem::rename($sourceFile,$targetFile); + } else { + return false; } } diff --git a/lib/helper.php b/lib/helper.php index 6ab55f27618..64378da356e 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -38,13 +38,10 @@ class OC_Helper { */ public static function linkTo( $app, $file ){ if( $app != '' ){ - $app .= '/'; + $app_path = OC_App::getAppPath($app); // Check if the app is in the app folder - if( file_exists( OC_App::getAppPath($app).'/'.$file )){ + if( $app_path && file_exists( $app_path.'/'.$file )){ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){ - if(substr($app, -1, 1) == '/'){ - $app = substr($app, 0, strlen($app) - 1); - } $urlLinkTo = OC::$WEBROOT . '/?app=' . $app; $urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):''; }else{ @@ -52,7 +49,7 @@ class OC_Helper { } } else{ - $urlLinkTo = OC::$WEBROOT . '/' . $app . $file; + $urlLinkTo = OC::$WEBROOT . '/' . $app . '/' . $file; } } else{ diff --git a/lib/migrate.php b/lib/migrate.php index f26b4b25673..731b6a6839c 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -64,7 +64,7 @@ class OC_Migrate{ $apps = OC_App::getAllApps(); foreach($apps as $app){ - $path = self::getAppPath($app) . '/appinfo/migrate.php'; + $path = OC_App::getAppPath($app) . '/appinfo/migrate.php'; if( file_exists( $path ) ){ include( $path ); } @@ -398,7 +398,7 @@ class OC_Migrate{ if( OC_App::isEnabled( $provider->getID() ) ){ $success = true; // Does this app use the database? - if( file_exists( self::getAppPath($provider->getID()).'/appinfo/database.xml' ) ){ + if( file_exists( OC_App::getAppPath($provider->getID()).'/appinfo/database.xml' ) ){ // Create some app tables $tables = self::createAppTables( $provider->getID() ); if( is_array( $tables ) ){ @@ -539,7 +539,7 @@ class OC_Migrate{ } // There is a database.xml file - $content = file_get_contents(self::getAppPath($appid) . '/appinfo/database.xml' ); + $content = file_get_contents(OC_App::getAppPath($appid) . '/appinfo/database.xml' ); $file2 = 'static://db_scheme'; // TODO get the relative path to migration.db from the data dir diff --git a/lib/setup.php b/lib/setup.php index 5f1fb1525ec..5387a0ef493 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -150,7 +150,7 @@ class OC_Setup { $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; - $dbtableprefix = $options['dbtableprefix']; + $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_CONFIG::setValue('dbname', $dbname); OC_CONFIG::setValue('dbhost', $dbhost); OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); @@ -163,6 +163,7 @@ class OC_Setup { 'error' => 'PostgreSQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.' ); + return $error; } else { //check for roles creation rights in postgresql @@ -284,13 +285,23 @@ class OC_Setup { //we cant use OC_BD functions here because we need to connect as the administrative user. $e_name = pg_escape_string($name); $e_user = pg_escape_string($user); - $query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\""; + $query = "select datname from pg_database where datname = '$e_name'"; $result = pg_query($connection, $query); if(!$result) { $entry='DB Error: "'.pg_last_error($connection).'"<br />'; $entry.='Offending command was: '.$query.'<br />'; echo($entry); } + if(! pg_fetch_row($result)) { + //The database does not exists... let's create it + $query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\""; + $result = pg_query($connection, $query); + if(!$result) { + $entry='DB Error: "'.pg_last_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + } $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC"; $result = pg_query($connection, $query); } @@ -298,13 +309,33 @@ class OC_Setup { private static function pg_createDBUser($name,$password,$connection) { $e_name = pg_escape_string($name); $e_password = pg_escape_string($password); - $query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';"; + $query = "select * from pg_roles where rolname='$e_name';"; $result = pg_query($connection, $query); if(!$result) { $entry='DB Error: "'.pg_last_error($connection).'"<br />'; $entry.='Offending command was: '.$query.'<br />'; echo($entry); } + + if(! pg_fetch_row($result)) { + //user does not exists let's create it :) + $query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';"; + $result = pg_query($connection, $query); + if(!$result) { + $entry='DB Error: "'.pg_last_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + } + else { // change password of the existing role + $query = "ALTER ROLE \"$e_name\" WITH PASSWORD '$e_password';"; + $result = pg_query($connection, $query); + if(!$result) { + $entry='DB Error: "'.pg_last_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + } } /** |