diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-03-30 18:48:30 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-03-30 18:48:30 +0200 |
commit | ef1e359c7c10f4ebd8230b4fa79bd0b284b5186e (patch) | |
tree | d6e81e96b6e5fd026bb7f52ff9f81ae8050e71e7 /lib | |
parent | 90286353e24738006128b1801c55483d2103e6ae (diff) | |
parent | 284955573c59e91ed4cab7771487d1cebbb44262 (diff) | |
download | nextcloud-server-ef1e359c7c10f4ebd8230b4fa79bd0b284b5186e.tar.gz nextcloud-server-ef1e359c7c10f4ebd8230b4fa79bd0b284b5186e.zip |
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/app.php | 91 | ||||
-rw-r--r-- | lib/base.php | 7 | ||||
-rw-r--r-- | lib/filecache.php | 28 | ||||
-rw-r--r-- | lib/installer.php | 4 | ||||
-rw-r--r-- | lib/util.php | 2 |
5 files changed, 101 insertions, 31 deletions
diff --git a/lib/app.php b/lib/app.php index 3daf539aa21..6c882963a02 100755 --- a/lib/app.php +++ b/lib/app.php @@ -34,16 +34,20 @@ class OC_App{ static private $settingsForms = array(); static private $adminForms = array(); static private $personalForms = array(); + static private $appInfo = array(); /** * @brief loads all apps + * @param array $types * @returns true/false * * This function walks through the owncloud directory and loads all apps * it can find. A directory contains an app if the file /appinfo/app.php * exists. + * + * if $types is set, only apps of those types will be loaded */ - public static function loadApps(){ + public static function loadApps($types=null){ // Did we allready load everything? if( self::$init ){ return true; @@ -51,13 +55,15 @@ class OC_App{ // Our very own core apps are hardcoded foreach( array('files', 'settings') as $app ){ - require( $app.'/appinfo/app.php' ); + if(is_null($types) or self::isType($app,$types)){ + require( $app.'/appinfo/app.php' ); + } } // The rest comes here - $apps = OC_Appconfig::getApps(); + $apps = self::getEnabledApps(); foreach( $apps as $app ){ - if( self::isEnabled( $app )){ + if(is_null($types) or self::isType($app,$types)){ if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){ require( $app.'/appinfo/app.php' ); } @@ -71,6 +77,41 @@ class OC_App{ } /** + * check if an app is of a sepcific type + * @param string $app + * @param string/array $types + */ + public static function isType($app,$types){ + if(is_string($types)){ + $types=array($types); + } + $appData=self::getAppInfo($app); + if(!isset($appData['types'])){ + return false; + } + $appTypes=$appData['types']; + foreach($types as $type){ + if(array_search($type,$appTypes)!==false){ + return true; + } + } + return false; + } + + /** + * get all enabled apps + */ + public static function getEnabledApps(){ + $apps=array(); + $query = OC_DB::prepare( 'SELECT appid FROM *PREFIX*appconfig WHERE configkey = "enabled" AND configvalue="yes"' ); + $query->execute(); + while($row=$query->fetchRow()){ + $apps[]=$row['appid']; + } + return $apps; + } + + /** * @brief checks whether or not an app is enabled * @param $app app * @returns true/false @@ -265,24 +306,36 @@ class OC_App{ /** * @brief Read app metadata from the info.xml file * @param string $appid id of the app or the path of the info.xml file + * @param boolean path (optional) * @returns array */ - public static function getAppInfo($appid){ - if(is_file($appid)){ + public static function getAppInfo($appid,$path=false){ + if($path){ $file=$appid; }else{ - $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml'; - if(!is_file($file)){ - return array(); + if(isset(self::$appInfo[$appid])){ + return self::$appInfo[$appid]; } + $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml'; } $data=array(); $content=file_get_contents($file); + if(!$content){ + return; + } $xml = new SimpleXMLElement($content); $data['info']=array(); foreach($xml->children() as $child){ - $data[$child->getName()]=(string)$child; + if($child->getName()=='types'){ + $data['types']=array(); + foreach($child->children() as $type){ + $data['types'][]=$type->getName(); + } + }else{ + $data[$child->getName()]=(string)$child; + } } + self::$appInfo[$appid]=$data; return $data; } @@ -381,9 +434,8 @@ class OC_App{ */ public static function updateApps(){ // The rest comes here - $apps = OC_Appconfig::getApps(); - foreach( $apps as $app ){ - $installedVersion=OC_Appconfig::getValue($app,'installed_version'); + $versions = self::getAppVersions(); + foreach( $versions as $app=>$installedVersion ){ $appInfo=OC_App::getAppInfo($app); if (isset($appInfo['version'])) { $currentVersion=$appInfo['version']; @@ -396,6 +448,19 @@ class OC_App{ } /** + * get the installed version of all papps + */ + public static function getAppVersions(){ + $versions=array(); + $query = OC_DB::prepare( 'SELECT appid, configvalue FROM *PREFIX*appconfig WHERE configkey = "installed_version"' ); + $result = $query->execute(); + while($row = $result->fetchRow()){ + $versions[$row['appid']]=$row['configvalue']; + } + return $versions; + } + + /** * update the database for the app and call the update script * @param string appid */ diff --git a/lib/base.php b/lib/base.php index b07ac5af416..b031572f177 100644 --- a/lib/base.php +++ b/lib/base.php @@ -333,8 +333,13 @@ class OC{ // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; + global $RUNTIME_APPTYPES; if(!$RUNTIME_NOAPPS ){ - OC_App::loadApps(); + if($RUNTIME_APPTYPES){ + OC_App::loadApps($RUNTIME_APPTYPES); + }else{ + OC_App::loadApps(); + } } //make sure temporary files are cleaned up diff --git a/lib/filecache.php b/lib/filecache.php index 280a9929db0..a8c48e3f144 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -59,8 +59,8 @@ class OC_FileCache{ $root=''; } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path)))->fetchRow(); if(is_array($result)){ return $result; }else{ @@ -111,8 +111,8 @@ class OC_FileCache{ } $mimePart=dirname($data['mimetype']); $user=OC_User::getUser(); - $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'); - $result=$query->execute(array($parent,basename($path),$path,$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); + $query=OC_DB::prepare('INSERT INTO *PREFIX*fscache(parent, name, path, path_hash, size, mtime, ctime, mimetype, mimepart,user,writable,encrypted,versioned) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)'); + $result=$query->execute(array($parent,basename($path),$path,md5($path),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned'])); if(OC_DB::isError($result)){ OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); } @@ -162,8 +162,8 @@ class OC_FileCache{ $oldPath=$root.$oldPath; $newPath=$root.$newPath; $newParent=self::getParentId($newPath); - $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=? WHERE path=?'); - $query->execute(array($newParent,basename($newPath),$newPath,$oldPath)); + $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?'); + $query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath))); } /** @@ -285,12 +285,12 @@ class OC_FileCache{ * @return int */ private static function getFileId($path){ - $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path=?'); + $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path_hash=?'); if(OC_DB::isError($query)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; } - $result=$query->execute(array($path)); + $result=$query->execute(array(md5($path))); if(OC_DB::isError($result)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; @@ -367,8 +367,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path))->fetchRow(); + $query=OC_DB::prepare('SELECT ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path)))->fetchRow(); if(is_array($result)){ if(isset(self::$savedData[$path])){ $result=array_merge($result,self::$savedData[$path]); @@ -389,8 +389,8 @@ class OC_FileCache{ } } $path=$root.$path; - $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path)); + $query=OC_DB::prepare('SELECT size FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path))); if($row=$result->fetchRow()){ return $row['size']; }else{//file not in cache @@ -579,8 +579,8 @@ class OC_FileCache{ $mtime=$view->filemtime($path); $isDir=$view->is_dir($path); $path=$root.$path; - $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path=?'); - $result=$query->execute(array($path)); + $query=OC_DB::prepare('SELECT mtime FROM *PREFIX*fscache WHERE path_hash=?'); + $result=$query->execute(array(md5($path))); if($row=$result->fetchRow()){ $cachedMTime=$row['mtime']; return ($mtime>$cachedMTime); diff --git a/lib/installer.php b/lib/installer.php index c5ecacae544..38e17130e3c 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -123,7 +123,7 @@ class OC_Installer{ } return false; } - $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml'); + $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true); $basedir=OC::$APPSROOT.'/apps/'.$info['id']; //check if an app with the same id is already installed @@ -296,7 +296,7 @@ class OC_Installer{ if(is_file(OC::$APPSROOT."/apps/$app/appinfo/install.php")){ include(OC::$APPSROOT."/apps/$app/appinfo/install.php"); } - $info=OC_App::getAppInfo(OC::$APPSROOT."/apps/$app/appinfo/info.xml"); + $info=OC_App::getAppInfo($app); OC_Appconfig::setValue($app,'installed_version',$info['version']); return $info; } diff --git a/lib/util.php b/lib/util.php index fa5b3daaab6..529b6d958fb 100644 --- a/lib/util.php +++ b/lib/util.php @@ -66,7 +66,7 @@ class OC_Util { * @return array */ public static function getVersion(){ - return array(3,00,3); + return array(3,00,4); } /** |