aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-12-19 15:57:04 +0100
committerRobin Appelman <icewind@owncloud.com>2013-12-19 15:57:04 +0100
commit321d96135385cd4b8941ad49555bb7612e5cbddf (patch)
tree7cd748eb696804a5057cb9554985e78a87717c4c /lib
parente7a5c90cab3f1afd9c3f81a76c128eced7e94b69 (diff)
parentae3df84e207f9bcac1b12923319c18fd80d5252d (diff)
downloadnextcloud-server-321d96135385cd4b8941ad49555bb7612e5cbddf.tar.gz
nextcloud-server-321d96135385cd4b8941ad49555bb7612e5cbddf.zip
Merge branch 'master' into user-no-change-displayname
Diffstat (limited to 'lib')
-rw-r--r--lib/private/appconfig.php143
-rw-r--r--lib/private/db/mdb2schemareader.php8
-rw-r--r--lib/private/eventsource.php6
-rw-r--r--lib/private/json.php13
-rw-r--r--lib/private/memcache/xcache.php36
-rw-r--r--lib/private/mimetypes.list.php8
-rw-r--r--lib/private/session/internal.php13
-rw-r--r--lib/private/session/memory.php2
-rwxr-xr-xlib/private/util.php6
-rw-r--r--lib/public/db.php12
-rw-r--r--lib/public/json.php8
11 files changed, 173 insertions, 82 deletions
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index 4f170e054e9..dfe03698059 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -37,7 +37,12 @@
* This class provides an easy way for apps to store config values in the
* database.
*/
-class OC_Appconfig{
+class OC_Appconfig {
+
+ private static $cache = array();
+
+ private static $appsLoaded = array();
+
/**
* @brief Get all apps using the config
* @return array with app ids
@@ -47,11 +52,11 @@ class OC_Appconfig{
*/
public static function getApps() {
// No magic in here!
- $query = OC_DB::prepare( 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`' );
+ $query = OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`');
$result = $query->execute();
$apps = array();
- while( $row = $result->fetchRow()) {
+ while ($row = $result->fetchRow()) {
$apps[] = $row["appid"];
}
@@ -66,19 +71,35 @@ class OC_Appconfig{
* This function gets all keys of an app. Please note that the values are
* not returned.
*/
- public static function getKeys( $app ) {
+ public static function getKeys($app) {
// No magic in here as well
- $query = OC_DB::prepare( 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?' );
- $result = $query->execute( array( $app ));
+ $query = OC_DB::prepare('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $result = $query->execute(array($app));
$keys = array();
- while( $row = $result->fetchRow()) {
+ while ($row = $result->fetchRow()) {
$keys[] = $row["configkey"];
}
return $keys;
}
+ private static function getAppValues($app) {
+ if (!isset(self::$cache[$app])) {
+ self::$cache[$app] = array();
+ }
+ if (array_search($app, self::$appsLoaded) === false) {
+ $query = OC_DB::prepare('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+ . ' WHERE `appid` = ?');
+ $result = $query->execute(array($app));
+ while ($row = $result->fetchRow()) {
+ self::$cache[$app][$row['configkey']] = $row['configvalue'];
+ }
+ self::$appsLoaded[] = $app;
+ }
+ return self::$cache[$app];
+ }
+
/**
* @brief Gets the config value
* @param string $app app
@@ -89,15 +110,18 @@ class OC_Appconfig{
* This function gets a value from the appconfig table. If the key does
* not exist the default value will be returned
*/
- public static function getValue( $app, $key, $default = null ) {
- // At least some magic in here :-)
- $query = OC_DB::prepare( 'SELECT `configvalue` FROM `*PREFIX*appconfig`'
- .' WHERE `appid` = ? AND `configkey` = ?' );
- $result = $query->execute( array( $app, $key ));
- $row = $result->fetchRow();
- if($row) {
- return $row["configvalue"];
- }else{
+ public static function getValue($app, $key, $default = null) {
+ if (!isset(self::$cache[$app])) {
+ self::$cache[$app] = array();
+ }
+ if (isset(self::$cache[$app][$key])) {
+ return self::$cache[$app][$key];
+ }
+ $values = self::getAppValues($app);
+ if (isset($values[$key])) {
+ return $values[$key];
+ } else {
+ self::$cache[$app][$key] = $default;
return $default;
}
}
@@ -109,8 +133,11 @@ class OC_Appconfig{
* @return bool
*/
public static function hasKey($app, $key) {
- $exists = self::getKeys( $app );
- return in_array( $key, $exists );
+ if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) {
+ return true;
+ }
+ $exists = self::getKeys($app);
+ return in_array($key, $exists);
}
/**
@@ -122,17 +149,16 @@ class OC_Appconfig{
*
* Sets a value. If the key did not exist before it will be created.
*/
- public static function setValue( $app, $key, $value ) {
+ public static function setValue($app, $key, $value) {
// Does the key exist? yes: update. No: insert
- if(! self::hasKey($app, $key)) {
- $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*appconfig` ( `appid`, `configkey`, `configvalue` )'
- .' VALUES( ?, ?, ? )' );
- $query->execute( array( $app, $key, $value ));
- }
- else{
- $query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `configvalue` = ?'
- .' WHERE `appid` = ? AND `configkey` = ?' );
- $query->execute( array( $value, $app, $key ));
+ if (!self::hasKey($app, $key)) {
+ $query = OC_DB::prepare('INSERT INTO `*PREFIX*appconfig` ( `appid`, `configkey`, `configvalue` )'
+ . ' VALUES( ?, ?, ? )');
+ $query->execute(array($app, $key, $value));
+ } else {
+ $query = OC_DB::prepare('UPDATE `*PREFIX*appconfig` SET `configvalue` = ?'
+ . ' WHERE `appid` = ? AND `configkey` = ?');
+ $query->execute(array($value, $app, $key));
}
// TODO where should this be documented?
\OC_Hook::emit('OC_Appconfig', 'post_set_value', array(
@@ -140,6 +166,10 @@ class OC_Appconfig{
'key' => $key,
'value' => $value
));
+ if (!isset(self::$cache[$app])) {
+ self::$cache[$app] = array();
+ }
+ self::$cache[$app][$key] = $value;
}
/**
@@ -150,10 +180,13 @@ class OC_Appconfig{
*
* Deletes a key.
*/
- public static function deleteKey( $app, $key ) {
+ public static function deleteKey($app, $key) {
// Boring!
- $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?' );
- $query->execute( array( $app, $key ));
+ $query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
+ $query->execute(array($app, $key));
+ if (isset(self::$cache[$app]) and isset(self::$cache[$app][$key])) {
+ unset(self::$cache[$app][$key]);
+ }
return true;
}
@@ -165,44 +198,46 @@ class OC_Appconfig{
*
* Removes all keys in appconfig belonging to the app.
*/
- public static function deleteApp( $app ) {
+ public static function deleteApp($app) {
// Nothing special
- $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?' );
- $query->execute( array( $app ));
+ $query = OC_DB::prepare('DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?');
+ $query->execute(array($app));
+ self::$cache[$app] = array();
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) {
+ if ($app !== false and $key !== false) {
return false;
}
- $fields='`configvalue`';
- $where='WHERE';
- $params=array();
- if($app!==false) {
- $fields.=', `configkey`';
- $where.=' `appid` = ?';
- $params[]=$app;
- $key='configkey';
- }else{
- $fields.=', `appid`';
- $where.=' `configkey` = ?';
- $params[]=$key;
- $key='appid';
+ $fields = '`configvalue`';
+ $where = 'WHERE';
+ $params = array();
+ if ($app !== false) {
+ $fields .= ', `configkey`';
+ $where .= ' `appid` = ?';
+ $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'];
+ $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;
}
diff --git a/lib/private/db/mdb2schemareader.php b/lib/private/db/mdb2schemareader.php
index 511bd1c90bd..b1fd2454cb0 100644
--- a/lib/private/db/mdb2schemareader.php
+++ b/lib/private/db/mdb2schemareader.php
@@ -183,6 +183,14 @@ class MDB2SchemaReader {
$primary = $this->asBool($child);
$options['primary'] = $primary;
break;
+ case 'precision':
+ $precision = (string)$child;
+ $options['precision'] = $precision;
+ break;
+ case 'scale':
+ $scale = (string)$child;
+ $options['scale'] = $scale;
+ break;
default:
throw new \DomainException('Unknown element: ' . $child->getName());
diff --git a/lib/private/eventsource.php b/lib/private/eventsource.php
index a83084d9251..4df0bc2e7cd 100644
--- a/lib/private/eventsource.php
+++ b/lib/private/eventsource.php
@@ -64,13 +64,13 @@ class OC_EventSource{
}
if($this->fallback) {
$response='<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack('
- .$this->fallBackId.',"'.$type.'",'.json_encode($data).')</script>'.PHP_EOL;
+ .$this->fallBackId.',"' . $type . '",' . OCP\JSON::encode($data) . ')</script>' . PHP_EOL;
echo $response;
}else{
if($type) {
- echo 'event: '.$type.PHP_EOL;
+ echo 'event: ' . $type.PHP_EOL;
}
- echo 'data: '.json_encode($data).PHP_EOL;
+ echo 'data: ' . OCP\JSON::encode($data) . PHP_EOL;
}
echo PHP_EOL;
flush();
diff --git a/lib/private/json.php b/lib/private/json.php
index 6ba0b13806b..6a9e5a2df5e 100644
--- a/lib/private/json.php
+++ b/lib/private/json.php
@@ -109,7 +109,16 @@ class OC_JSON{
if($setContentType) {
self::setContentTypeHeader();
}
- array_walk_recursive($data, array('OC_JSON', 'to_string'));
- echo json_encode($data);
+ echo self::encode($data);
+ }
+
+ /**
+ * Encode JSON
+ */
+ public static function encode($data) {
+ if (is_array($data)) {
+ array_walk_recursive($data, array('OC_JSON', 'to_string'));
+ }
+ return json_encode($data);
}
}
diff --git a/lib/private/memcache/xcache.php b/lib/private/memcache/xcache.php
index 33de30562f9..1337a7ad612 100644
--- a/lib/private/memcache/xcache.php
+++ b/lib/private/memcache/xcache.php
@@ -8,9 +8,13 @@
namespace OC\Memcache;
+/**
+ * See http://xcache.lighttpd.net/wiki/XcacheApi for provided constants and
+ * functions etc.
+ */
class XCache extends Cache {
/**
- * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
+ * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users
*/
protected function getNameSpace() {
return $this->prefix;
@@ -37,24 +41,32 @@ class XCache extends Cache {
}
public function clear($prefix='') {
- xcache_unset_by_prefix($this->getNamespace().$prefix);
+ if (function_exists('xcache_unset_by_prefix')) {
+ return xcache_unset_by_prefix($this->getNamespace().$prefix);
+ } else {
+ // Since we can not clear by prefix, we just clear the whole cache.
+ xcache_clear_cache(\XC_TYPE_VAR, 0);
+ }
return true;
}
static public function isAvailable(){
if (!extension_loaded('xcache')) {
return false;
- } elseif (\OC::$CLI) {
+ }
+ if (\OC::$CLI) {
return false;
- }else{
- return true;
}
- }
-}
-
-if(!function_exists('xcache_unset_by_prefix')) {
- function xcache_unset_by_prefix($prefix) {
- // Since we can't clear targetted cache, we'll clear all. :(
- xcache_clear_cache(\XC_TYPE_VAR, 0);
+ if (!function_exists('xcache_unset_by_prefix') && ini_get('xcache.admin.enable_auth')) {
+ // We do not want to use XCache if we can not clear it without
+ // using the administration function xcache_clear_cache()
+ // AND administration functions are password-protected.
+ return false;
+ }
+ $var_size = (int) ini_get('xcache.var_size');
+ if (!$var_size) {
+ return false;
+ }
+ return true;
}
}
diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php
index 8ab8ac81bd8..3034c2777f7 100644
--- a/lib/private/mimetypes.list.php
+++ b/lib/private/mimetypes.list.php
@@ -82,7 +82,7 @@ return array(
'mov'=>'video/quicktime',
'webm'=>'video/webm',
'wmv'=>'video/x-ms-asf',
- 'py'=>'text/x-script.phyton',
+ 'py'=>'text/x-script.python',
'vcf' => 'text/vcard',
'vcard' => 'text/vcard',
'doc'=>'application/msword',
@@ -103,5 +103,9 @@ return array(
'markdown' => 'text/markdown',
'mdown' => 'text/markdown',
'mdwn' => 'text/markdown',
- 'reveal' => 'text/reveal'
+ 'reveal' => 'text/reveal',
+ 'c' => 'text/x-c',
+ 'cc' => 'text/x-c',
+ 'cpp' => 'text/x-c++src',
+ 'c++' => 'text/x-c++src',
);
diff --git a/lib/private/session/internal.php b/lib/private/session/internal.php
index 60aecccc8aa..a7c9e2fdefd 100644
--- a/lib/private/session/internal.php
+++ b/lib/private/session/internal.php
@@ -26,10 +26,21 @@ class Internal extends Memory {
}
public function __destruct() {
- $_SESSION = $this->data;
+ $_SESSION = array_merge($_SESSION, $this->data);
session_write_close();
}
+ /**
+ * @param string $key
+ */
+ public function remove($key) {
+ // also remove it from $_SESSION to prevent re-setting the old value during the merge
+ if (isset($_SESSION[$key])) {
+ unset($_SESSION[$key]);
+ }
+ parent::remove($key);
+ }
+
public function clear() {
session_unset();
@session_regenerate_id(true);
diff --git a/lib/private/session/memory.php b/lib/private/session/memory.php
index c148ff4b9b9..134cee582ed 100644
--- a/lib/private/session/memory.php
+++ b/lib/private/session/memory.php
@@ -11,7 +11,7 @@ namespace OC\Session;
/**
* Class Internal
*
- * store session data in an in-memory array, not persistance
+ * store session data in an in-memory array, not persistent
*
* @package OC\Session
*/
diff --git a/lib/private/util.php b/lib/private/util.php
index a73564b3f68..c0e618cc863 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -1085,7 +1085,11 @@ class OC_Util {
}
// XCache
if (function_exists('xcache_clear_cache')) {
- xcache_clear_cache(XC_TYPE_VAR, 0);
+ if (ini_get('xcache.admin.enable_auth')) {
+ OC_Log::write('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OC_Log::WARN);
+ } else {
+ xcache_clear_cache(XC_TYPE_PHP, 0);
+ }
}
// Opcache (PHP >= 5.5)
if (function_exists('opcache_reset')) {
diff --git a/lib/public/db.php b/lib/public/db.php
index c9997c79c3c..4a19d78d444 100644
--- a/lib/public/db.php
+++ b/lib/public/db.php
@@ -39,9 +39,9 @@ class DB {
* @param string $query Query string
* @param int $limit Limit of the SQL statement
* @param int $offset Offset of the SQL statement
- * @return \MDB2_Statement_Common prepared SQL query
+ * @return \Doctrine\DBAL\Statement prepared SQL query
*
- * SQL query via MDB2 prepare(), needs to be execute()'d!
+ * SQL query via Doctrine prepare(), needs to be execute()'d!
*/
static public function prepare( $query, $limit=null, $offset=null ) {
return(\OC_DB::prepare($query, $limit, $offset));
@@ -73,7 +73,7 @@ class DB {
* @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
* @return int
*
- * MDB2 lastInsertID()
+ * \Doctrine\DBAL\Connection lastInsertID()
*
* Call this method right after the insert command or other functions may
* cause trouble!
@@ -86,18 +86,18 @@ class DB {
* Start a transaction
*/
public static function beginTransaction() {
- return(\OC_DB::beginTransaction());
+ \OC_DB::beginTransaction();
}
/**
* Commit the database changes done during a transaction that is in progress
*/
public static function commit() {
- return(\OC_DB::commit());
+ \OC_DB::commit();
}
/**
- * Check if a result is an error, works with MDB2 and PDOException
+ * Check if a result is an error, works with Doctrine
* @param mixed $result
* @return bool
*/
diff --git a/lib/public/json.php b/lib/public/json.php
index 134f724b0e6..831e3ef1cf6 100644
--- a/lib/public/json.php
+++ b/lib/public/json.php
@@ -169,4 +169,12 @@ class JSON {
public static function checkAdminUser() {
return(\OC_JSON::checkAdminUser());
}
+
+ /**
+ * Encode JSON
+ * @param array $data
+ */
+ public static function encode($data) {
+ return(\OC_JSON::encode($data));
+ }
}