summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-04-14 17:53:02 +0200
committerRobin Appelman <icewind@owncloud.com>2012-04-14 17:53:02 +0200
commitdec139716e7f93d25a7064ff03b2b68a51e3ebff (patch)
tree9dd560d8b11b36541eac7317686ce1665e8f6c3a
parent5608867edc0c4c7c9135f78800e6a199bfec7ada (diff)
downloadnextcloud-server-dec139716e7f93d25a7064ff03b2b68a51e3ebff.tar.gz
nextcloud-server-dec139716e7f93d25a7064ff03b2b68a51e3ebff.zip
cache app types in the db
-rwxr-xr-xlib/app.php33
-rw-r--r--lib/appconfig.php34
2 files changed, 62 insertions, 5 deletions
diff --git a/lib/app.php b/lib/app.php
index db2df7c2434..5fccf1fe68f 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -35,6 +35,7 @@ class OC_App{
static private $adminForms = array();
static private $personalForms = array();
static private $appInfo = array();
+ static private $appTypes = array();
/**
* @brief loads all apps
@@ -85,11 +86,7 @@ class OC_App{
if(is_string($types)){
$types=array($types);
}
- $appData=self::getAppInfo($app);
- if(!isset($appData['types'])){
- return false;
- }
- $appTypes=$appData['types'];
+ $appTypes=self::getAppTypes($app);
foreach($types as $type){
if(array_search($type,$appTypes)!==false){
return true;
@@ -97,6 +94,32 @@ class OC_App{
}
return false;
}
+
+ /**
+ * get the types of an app
+ * @param string $app
+ * @return array
+ */
+ private static function getAppTypes($app){
+ //load the cache
+ if(count(self::$appTypes)==0){
+ self::$appTypes=OC_Appconfig::getValues(false,'types');
+ }
+
+ //get it from info.xml if we haven't cached it
+ if(!isset(self::$appTypes[$app])){
+ $appData=self::getAppInfo($app);
+ if(isset($appData['types'])){
+ self::$appTypes[$app]=$appData['types'];
+ }else{
+ self::$appTypes[$app]=array();
+ }
+
+ OC_Appconfig::setValue($app,'types',implode(',',self::$appTypes[$app]));
+ }
+
+ return explode(',',self::$appTypes[$app]);
+ }
/**
* get all enabled apps
diff --git a/lib/appconfig.php b/lib/appconfig.php
index 2b5cef59adc..5aaaadd9c4a 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -163,4 +163,38 @@ class OC_Appconfig{
return true;
}
+
+ /**
+ * get multiply values, either the app or key can be used as wildcard by setting it to false
+ * @param app
+ * @param key
+ * @return array
+ */
+ public static function getValues($app,$key){
+ if($app!==false and $key!==false){
+ return false;
+ }
+ $where='WHERE';
+ $fields='configvalue';
+ $params=array();
+ if($app!==false){
+ $where.=' appid = ?';
+ $fields.=', configkey';
+ $params[]=$app;
+ $key='configkey';
+ }else{
+ $fields.=', appid';
+ $where.=' configkey = ?';
+ $params[]=$key;
+ $key='appid';
+ }
+ $queryString='SELECT '.$fields.' FROM *PREFIX*appconfig '.$where;
+ $query=OC_DB::prepare($queryString);
+ $result=$query->execute($params);
+ $values=array();
+ while($row=$result->fetchRow()){
+ $values[$row[$key]]=$row['configvalue'];
+ }
+ return $values;
+ }
}