From c546874159d7880e3c8665eaaa7ae9a42b66adbb Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 2 Mar 2013 17:17:11 +0100 Subject: [PATCH 01/74] Convert OC_Appconfig to object interface Implemented unittest for OC\AppConfig --- lib/appconfig.php | 148 +++++++++++++++++--------------- lib/legacy/appconfig.php | 120 ++++++++++++++++++++++++++ tests/lib/appconfig.php | 181 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 382 insertions(+), 67 deletions(-) create mode 100644 lib/legacy/appconfig.php diff --git a/lib/appconfig.php b/lib/appconfig.php index e615d838173..9a21bfb0a24 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -33,11 +33,21 @@ * */ +namespace OC; + +use \OC\DB\Connection; + /** * This class provides an easy way for apps to store config values in the * database. */ -class OC_Appconfig{ +class AppConfig { + protected $conn; + + public function __construct(Connection $conn) { + $this->conn = $conn; + } + /** * @brief Get all apps using the config * @return array with app ids @@ -45,16 +55,14 @@ class OC_Appconfig{ * This function returns a list of all apps that have at least one * entry in the appconfig table. */ - public static function getApps() { - // No magic in here! - $query = OC_DB::prepare( 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`' ); - $result = $query->execute(); + public function getApps() { + $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'; + $result = $this->conn->executeQuery( $query ); $apps = array(); - while( $row = $result->fetchRow()) { - $apps[] = $row["appid"]; + while( $appid = $result->fetchColumn()) { + $apps[] = $appid; } - return $apps; } @@ -66,14 +74,13 @@ class OC_Appconfig{ * This function gets all keys of an app. Please note that the values are * not returned. */ - 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 )); + public function getKeys( $app ) { + $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; + $result = $this->conn->executeQuery( $query, array( $app )); $keys = array(); - while( $row = $result->fetchRow()) { - $keys[] = $row["configkey"]; + while( $key = $result->fetchColumn()) { + $keys[] = $key; } return $keys; @@ -89,15 +96,13 @@ 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(); + public function getValue( $app, $key, $default = null ) { + $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' + .' WHERE `appid` = ? AND `configkey` = ?'; + $row = $this->conn->fetchAssoc($query, array( $app, $key )); if($row) { - return $row["configvalue"]; - }else{ + return $row['configvalue']; + } else { return $default; } } @@ -108,8 +113,8 @@ class OC_Appconfig{ * @param string $key * @return bool */ - public static function hasKey($app, $key) { - $exists = self::getKeys( $app ); + public function hasKey($app, $key) { + $exists = $this->getKeys( $app ); return in_array( $key, $exists ); } @@ -118,21 +123,27 @@ class OC_Appconfig{ * @param string $app app * @param string $key key * @param string $value value - * @return bool * * Sets a value. If the key did not exist before it will be created. */ - 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 )); + public function setValue( $app, $key, $value ) { + // Does the key exist? no: insert, yes: update. + if ( !$this->hasKey($app, $key)) { + $data = array( + 'appid' => $app, + 'configkey' => $key, + 'configvalue' => $value, + ); + $this->conn->insert('*PREFIX*appconfig', $data); + } else { + $data = array( + 'configvalue' => $value, + ); + $where = array( + 'appid' => $app, + 'configkey' => $key, + ); + $this->conn->update('*PREFIX*appconfig', $data, $where); } } @@ -144,12 +155,12 @@ class OC_Appconfig{ * * Deletes a 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 )); - - return true; + public function deleteKey( $app, $key ) { + $where = array( + 'appid' => $app, + 'configkey' => $key, + ); + $this->conn->delete('*PREFIX*appconfig', $where); } /** @@ -159,12 +170,11 @@ class OC_Appconfig{ * * Removes all keys in appconfig belonging to the app. */ - public static function deleteApp( $app ) { - // Nothing special - $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*appconfig` WHERE `appid` = ?' ); - $query->execute( array( $app )); - - return true; + public function deleteApp( $app ) { + $where = array( + 'appid' => $app, + ); + $this->conn->delete('*PREFIX*appconfig', $where); } /** @@ -173,31 +183,35 @@ class OC_Appconfig{ * @param key * @return array */ - public static function getValues($app, $key) { - if($app!==false and $key!==false) { + public function getValues($app, $key) { + if(($app!==false) == ($key!==false)) { return false; } - $fields='`configvalue`'; - $where='WHERE'; - $params=array(); + + $fields = '`configvalue`'; + $where = 'WHERE'; + $params = array(); if($app!==false) { - $fields.=', `configkey`'; - $where.=' `appid` = ?'; - $params[]=$app; - $key='configkey'; + $fields .= ', `configkey`'; + $where .= ' `appid` = ?'; + $params[] = $app; + $key = 'configkey'; }else{ - $fields.=', `appid`'; - $where.=' `configkey` = ?'; - $params[]=$key; - $key='appid'; + $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']; + $query = 'SELECT '.$fields.' FROM `*PREFIX*appconfig` '.$where; + $result = $this->conn->executeQuery( $query, $params ); + + $values = array(); + while( $row = $result->fetch((\PDO::FETCH_ASSOC))) { + $values[$row[$key]] = $row['configvalue']; } + return $values; } } + +require_once __DIR__.'/legacy/'.basename(__FILE__); diff --git a/lib/legacy/appconfig.php b/lib/legacy/appconfig.php new file mode 100644 index 00000000000..0ca6d4150ef --- /dev/null +++ b/lib/legacy/appconfig.php @@ -0,0 +1,120 @@ +. + * + */ + +/** + * This class provides an easy way for apps to store config values in the + * database. + */ +OC_Appconfig::$object = new \OC\AppConfig(OC_DB::getConnection()); +class OC_Appconfig{ + public static $object; + /** + * @brief Get all apps using the config + * @return array with app ids + * + * This function returns a list of all apps that have at least one + * entry in the appconfig table. + */ + public static function getApps() { + return self::$object->getApps(); + } + + /** + * @brief Get the available keys for an app + * @param string $app the app we are looking for + * @return array with key names + * + * This function gets all keys of an app. Please note that the values are + * not returned. + */ + public static function getKeys( $app ) { + return self::$object->getKeys( $app ); + } + + /** + * @brief Gets the config value + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default + * + * 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 ) { + return self::$object->getValue($app, $key, $default); + } + + /** + * @brief check if a key is set in the appconfig + * @param string $app + * @param string $key + * @return bool + */ + public static function hasKey($app, $key) { + return self::$object->hasKey($app, $key); + } + + /** + * @brief sets a value in the appconfig + * @param string $app app + * @param string $key key + * @param string $value value + * + * Sets a value. If the key did not exist before it will be created. + */ + public static function setValue( $app, $key, $value ) { + self::$object->setValue( $app, $key, $value ); + } + + /** + * @brief Deletes a key + * @param string $app app + * @param string $key key + * + * Deletes a key. + */ + public static function deleteKey( $app, $key ) { + self::$object->deleteKey( $app, $key ); + } + + /** + * @brief Remove app from appconfig + * @param string $app app + * + * Removes all keys in appconfig belonging to the app. + */ + public static function deleteApp( $app ) { + self::$object->deleteApp( $app ); + } + + /** + * 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) { + return self::$object->getValues($app, $key); + } +} diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 4d82cd5ba7b..1b7a1c668e7 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -1,6 +1,7 @@ + * Copyright (c) 2013 Bart Visscher * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -130,3 +131,183 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $values); } } + +class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { + public function testGetApps() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(2)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('executeQuery') + ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`')) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $apps = $appconfig->getApps(); + $this->assertEquals(array('foo'), $apps); + } + + public function testGetKeys() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(2)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $keys = $appconfig->getKeys('bar'); + $this->assertEquals(array('foo'), $keys); + } + + public function testGetValue() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('fetchAssoc') + ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'), + $this->equalTo(array('bar', 'red'))) + ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null)); + + $appconfig = new OC\AppConfig($connectionMock); + $value = $appconfig->getValue('bar', 'red'); + $this->assertEquals('foo', $value); + $value = $appconfig->getValue('bar', 'red', 'def'); + $this->assertEquals('def', $value); + } + + public function testHasKey() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(3)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false, false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $this->assertTrue($appconfig->hasKey('bar', 'foo')); + $this->assertFalse($appconfig->hasKey('bar', 'foo')); + } + + public function testSetValue() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(4)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false, 'foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + $connectionMock->expects($this->once()) + ->method('insert') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'appid' => 'bar', + 'configkey' => 'moo', + 'configvalue' => 'v1', + ) + )); + $connectionMock->expects($this->once()) + ->method('update') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'configvalue' => 'v2', + )), + $this->equalTo( + array( + 'appid' => 'bar', + 'configkey' => 'foo', + ) + )); + + $appconfig = new OC\AppConfig($connectionMock); + $appconfig->setValue('bar', 'moo', 'v1'); + $appconfig->setValue('bar', 'foo', 'v2'); + } + + public function testDeleteKey() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('delete') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'appid' => 'bar', + 'configkey' => 'foo', + ) + )); + + $appconfig = new OC\AppConfig($connectionMock); + $appconfig->deleteKey('bar', 'foo'); + } + + public function testDeleteApp() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('delete') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'appid' => 'bar', + ) + )); + + $appconfig = new OC\AppConfig($connectionMock); + $appconfig->deleteApp('bar'); + } + + public function testGetValues() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(4)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->onConsecutiveCalls( + array('configvalue' =>'bar', 'configkey' => 'x'), + false, + array('configvalue' =>'foo', 'appid' => 'y'), + false + )); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->at(0)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('foo'))) + ->will($this->returnValue($statementMock)); + $connectionMock->expects($this->at(1)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $values = $appconfig->getValues('foo', false); + //$this->assertEquals(array('x'=> 'bar'), $values); + $values = $appconfig->getValues(false, 'bar'); + //$this->assertEquals(array('y'=> 'foo'), $values); + $values = $appconfig->getValues(false, false); + //$this->assertEquals(false, $values); + $values = $appconfig->getValues('x', 'x'); + //$this->assertEquals(false, $values); + } +} From ca88cf93ae929c8bd35e92665958c34b65701493 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 21 Mar 2013 20:36:40 +0100 Subject: [PATCH 02/74] check for valid appinfo in installer --- lib/installer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/installer.php b/lib/installer.php index e082c7eeee9..89358e78277 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -396,6 +396,9 @@ class OC_Installer{ include OC_App::getAppPath($app)."/appinfo/install.php"; } $info=OC_App::getAppInfo($app); + if (is_null($info)) { + return; + } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); //set remote/public handelers From 2f79e94a350e2c24f88fcd98cb03e9a89298d154 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 25 Aug 2013 22:34:54 +0200 Subject: [PATCH 03/74] Style fixes --- lib/appconfig.php | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/appconfig.php b/lib/appconfig.php index 9a21bfb0a24..7c84faf7f16 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -42,8 +42,14 @@ use \OC\DB\Connection; * database. */ class AppConfig { + /** + * @var \OC\DB\Connection $conn + */ protected $conn; + /** + * @param \OC\DB\Connection $conn + */ public function __construct(Connection $conn) { $this->conn = $conn; } @@ -57,10 +63,10 @@ class AppConfig { */ public function getApps() { $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'; - $result = $this->conn->executeQuery( $query ); + $result = $this->conn->executeQuery($query); $apps = array(); - while( $appid = $result->fetchColumn()) { + while ($appid = $result->fetchColumn()) { $apps[] = $appid; } return $apps; @@ -74,12 +80,12 @@ class AppConfig { * This function gets all keys of an app. Please note that the values are * not returned. */ - public function getKeys( $app ) { + public function getKeys($app) { $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; - $result = $this->conn->executeQuery( $query, array( $app )); + $result = $this->conn->executeQuery($query, array($app)); $keys = array(); - while( $key = $result->fetchColumn()) { + while ($key = $result->fetchColumn()) { $keys[] = $key; } @@ -96,11 +102,11 @@ class AppConfig { * This function gets a value from the appconfig table. If the key does * not exist the default value will be returned */ - public function getValue( $app, $key, $default = null ) { + public function getValue($app, $key, $default = null) { $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' .' WHERE `appid` = ? AND `configkey` = ?'; - $row = $this->conn->fetchAssoc($query, array( $app, $key )); - if($row) { + $row = $this->conn->fetchAssoc($query, array($app, $key)); + if ($row) { return $row['configvalue']; } else { return $default; @@ -114,8 +120,8 @@ class AppConfig { * @return bool */ public function hasKey($app, $key) { - $exists = $this->getKeys( $app ); - return in_array( $key, $exists ); + $exists = $this->getKeys($app); + return in_array($key, $exists); } /** @@ -126,9 +132,9 @@ class AppConfig { * * Sets a value. If the key did not exist before it will be created. */ - public function setValue( $app, $key, $value ) { + public function setValue($app, $key, $value) { // Does the key exist? no: insert, yes: update. - if ( !$this->hasKey($app, $key)) { + if (!$this->hasKey($app, $key)) { $data = array( 'appid' => $app, 'configkey' => $key, @@ -155,7 +161,7 @@ class AppConfig { * * Deletes a key. */ - public function deleteKey( $app, $key ) { + public function deleteKey($app, $key) { $where = array( 'appid' => $app, 'configkey' => $key, @@ -170,7 +176,7 @@ class AppConfig { * * Removes all keys in appconfig belonging to the app. */ - public function deleteApp( $app ) { + public function deleteApp($app) { $where = array( 'appid' => $app, ); @@ -184,19 +190,19 @@ class AppConfig { * @return array */ public function getValues($app, $key) { - if(($app!==false) == ($key!==false)) { + if (($app !== false) == ($key !== false)) { return false; } $fields = '`configvalue`'; $where = 'WHERE'; $params = array(); - if($app!==false) { + if ($app !== false) { $fields .= ', `configkey`'; $where .= ' `appid` = ?'; $params[] = $app; $key = 'configkey'; - }else{ + } else { $fields .= ', `appid`'; $where .= ' `configkey` = ?'; $params[] = $key; @@ -206,12 +212,10 @@ class AppConfig { $result = $this->conn->executeQuery( $query, $params ); $values = array(); - while( $row = $result->fetch((\PDO::FETCH_ASSOC))) { + while ($row = $result->fetch((\PDO::FETCH_ASSOC))) { $values[$row[$key]] = $row['configvalue']; } return $values; } -} - -require_once __DIR__.'/legacy/'.basename(__FILE__); +} \ No newline at end of file From 6619d8273aa264d39c34a13ecafe720fc2356f90 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 25 Aug 2013 22:40:23 +0200 Subject: [PATCH 04/74] Enable appconfig asserts --- tests/lib/appconfig.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 1b7a1c668e7..1f605263560 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -302,12 +302,12 @@ class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { $appconfig = new OC\AppConfig($connectionMock); $values = $appconfig->getValues('foo', false); - //$this->assertEquals(array('x'=> 'bar'), $values); + $this->assertEquals(array('x'=> 'bar'), $values); $values = $appconfig->getValues(false, 'bar'); - //$this->assertEquals(array('y'=> 'foo'), $values); + $this->assertEquals(array('y'=> 'foo'), $values); $values = $appconfig->getValues(false, false); - //$this->assertEquals(false, $values); + $this->assertEquals(false, $values); $values = $appconfig->getValues('x', 'x'); - //$this->assertEquals(false, $values); + $this->assertEquals(false, $values); } } From b35b22977cfc9412278ae70b49c402a95efca19e Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 2 Oct 2013 09:15:31 +0200 Subject: [PATCH 05/74] Move legacy file to correct location --- lib/{ => private}/legacy/appconfig.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{ => private}/legacy/appconfig.php (100%) diff --git a/lib/legacy/appconfig.php b/lib/private/legacy/appconfig.php similarity index 100% rename from lib/legacy/appconfig.php rename to lib/private/legacy/appconfig.php From 059c3c8708c9b94df80d43ab8cac0cfc9b867cb8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 16 Dec 2013 15:38:12 +0100 Subject: [PATCH 06/74] fix issue with logging non utf8 chars --- lib/private/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/image.php b/lib/private/image.php index 7761a3c7737..314a4216b82 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -416,7 +416,7 @@ class OC_Image { // exif_imagetype throws "read error!" if file is less than 12 byte if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) { // Debug output disabled because this method is tried before loadFromBase64? - OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagePath, OC_Log::DEBUG); + OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) $imagePath, OC_Log::DEBUG); return false; } $iType = exif_imagetype($imagePath); From 320353c237fbee2d9a8f12dd474feb3a0f6ddec6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 9 Dec 2013 01:34:31 +0100 Subject: [PATCH 07/74] Add support for multiple memcached servers. --- config/config.sample.php | 10 ++++++++-- lib/private/memcache/memcached.php | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 1070ef72eda..67152accc3b 100755 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -114,8 +114,14 @@ $CONFIG = array( /* Password to use for sendmail mail, depends on mail_smtpauth if this is used */ "mail_smtppassword" => "", -/* memcached hostname and port (Only used when xCache, APC and APCu are absent.) */ -"memcached_server" => array('localhost', 11211), +/* memcached servers (Only used when xCache, APC and APCu are absent.) */ +"memcached_servers" => array( + // hostname, port and optional weight. Also see: + // http://www.php.net/manual/en/memcached.addservers.php + // http://www.php.net/manual/en/memcached.addserver.php + array('localhost', 11211), + //array('other.host.local', 11211), +), /* How long should ownCloud keep deleted files in the trash bin, default value: 30 days */ 'trashbin_retention_obligation' => 30, diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php index 978e6c2eff1..13b1867231a 100644 --- a/lib/private/memcache/memcached.php +++ b/lib/private/memcache/memcached.php @@ -18,8 +18,8 @@ class Memcached extends Cache { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); - list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211)); - self::$cache->addServer($host, $port); + $servers = \OC_Config::getValue('memcached_servers', array(array('localhost', 11211))); + self::$cache->addServers($servers); } } From acd81f6c694373a18a0ee9ba29075b9924603c25 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 10 Jan 2014 00:57:40 +0100 Subject: [PATCH 08/74] Readd support for memcached_server config variable. --- lib/private/memcache/memcached.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php index 13b1867231a..075828eebad 100644 --- a/lib/private/memcache/memcached.php +++ b/lib/private/memcache/memcached.php @@ -18,7 +18,15 @@ class Memcached extends Cache { parent::__construct($prefix); if (is_null(self::$cache)) { self::$cache = new \Memcached(); - $servers = \OC_Config::getValue('memcached_servers', array(array('localhost', 11211))); + $servers = \OC_Config::getValue('memcached_servers'); + if (!$servers) { + $server = \OC_Config::getValue('memcached_server'); + if ($server) { + $servers = array($server); + } else { + $servers = array(array('localhost', 11211)); + } + } self::$cache->addServers($servers); } } From 6f21da12e8c953bebdbd444460b07160821ba7a8 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 11 Jan 2014 12:07:28 +0100 Subject: [PATCH 09/74] encode imagePath and fix documentation of loadFromFile --- lib/private/image.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/image.php b/lib/private/image.php index 314a4216b82..91a9f91e1d6 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -409,14 +409,14 @@ class OC_Image { /** * @brief Loads an image from a local file. - * @param $imageref The path to a local file. + * @param $imagePath The path to a local file. * @returns An image resource or false on error */ public function loadFromFile($imagePath=false) { // exif_imagetype throws "read error!" if file is less than 12 byte if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) { // Debug output disabled because this method is tried before loadFromBase64? - OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) $imagePath, OC_Log::DEBUG); + OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) urlencode($imagePath), OC_Log::DEBUG); return false; } $iType = exif_imagetype($imagePath); From 617acbd6f9e93254c31987639cc4915dceb7c4c0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 14:28:49 +0100 Subject: [PATCH 10/74] Add a FileInfo class which holds all info of a file and return that from getFileInfo, getDirectoryContent and search --- lib/private/files/fileinfo.php | 149 +++++++++++++++++++++++++++++++++ lib/private/files/view.php | 37 ++++---- lib/public/files/fileinfo.php | 87 +++++++++++++++++++ lib/public/util.php | 2 +- 4 files changed, 257 insertions(+), 18 deletions(-) create mode 100644 lib/private/files/fileinfo.php create mode 100644 lib/public/files/fileinfo.php diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php new file mode 100644 index 00000000000..24d99627aaf --- /dev/null +++ b/lib/private/files/fileinfo.php @@ -0,0 +1,149 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files; + +class FileInfo implements \OCP\Files\FileInfo { + /** + * @var array $data + */ + private $data; + + /** + * @var string $path + */ + private $path; + + /** + * @var \OC\Files\Storage\Storage $storage + */ + private $storage; + + /** + * @var string $internalPath + */ + private $internalPath; + + public function __construct($path, $storage, $internalPath, $data) { + $this->path = $path; + $this->storage = $storage; + $this->internalPath = $internalPath; + $this->data = $data; + } + + public function offsetSet($offset, $value) { + $this->data[$offset] = $value; + } + + public function offsetExists($offset) { + return isset($this->data[$offset]); + } + + public function offsetUnset($offset) { + unset($this->data[$offset]); + } + + public function offsetGet($offset) { + return $this->data[$offset]; + } + + public function jsonSerialize() { + return $this->data; + } + + /** + * @return string + */ + public function getPath() { + return $this->path; + } + + /** + * @return \OCP\Files\Storage + */ + public function getStorage() { + return $this->storage; + } + + /** + * @return string + */ + public function getInternalPath() { + return $this->internalPath; + } + + /** + * @return int + */ + public function getId() { + return $this->data['fileid']; + } + + /** + * @return string + */ + public function getMimetype() { + return $this->data['mimetype']; + } + + /** + * @return string + */ + public function getMimePart() { + return $this->data['mimepart']; + } + + /** + * @return string + */ + public function getName() { + return $this->data['name']; + } + + /** + * @return string + */ + public function getEtag() { + return $this->data['etag']; + } + + /** + * @return int + */ + public function getSize() { + return $this->data['size']; + } + + /** + * @return int + */ + public function getMtime() { + return $this->data['mtime']; + } + + /** + * @return bool + */ + public function isEncrypted() { + return $this->data['encrypted']; + } + + /** + * @return int + */ + public function getPermissions() { + return $this->data['permissions']; + } + + /** + * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER + */ + public function getType() { + return $this->data['type']; + } +} diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 8893911ed5d..39c2ffed93d 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -781,14 +781,7 @@ class View { * @param string $path * @param boolean $includeMountPoints whether to add mountpoint sizes, * defaults to true - * @return array - * - * returns an associative array with the following keys: - * - size - * - mtime - * - mimetype - * - encrypted - * - versioned + * @return \OC\Files\FileInfo | false */ public function getFileInfo($path, $includeMountPoints = true) { $data = array(); @@ -838,10 +831,13 @@ class View { $data['permissions'] = $permissions; } } + if (!$data) { + return false; + } $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data); - return $data; + return new FileInfo($path, $storage, $internalPath, $data); } /** @@ -849,7 +845,7 @@ class View { * * @param string $directory path under datadirectory * @param string $mimetype_filter limit returned content to this mimetype or mimepart - * @return array + * @return FileInfo[] */ public function getDirectoryContent($directory, $mimetype_filter = '') { $result = array(); @@ -875,7 +871,11 @@ class View { $watcher->checkUpdate($internalPath); } - $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + $files = array(); + $contents = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + foreach ($contents as $content) { + $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content); + } $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user); $ids = array(); @@ -933,7 +933,7 @@ class View { break; } } - $files[] = $rootEntry; + $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry); } } } @@ -955,6 +955,7 @@ class View { $result = $files; } } + return $result; } @@ -992,7 +993,7 @@ class View { * search for files with the name matching $query * * @param string $query - * @return array + * @return FileInfo[] */ public function search($query) { return $this->searchCommon('%' . $query . '%', 'search'); @@ -1002,7 +1003,7 @@ class View { * search for files by mimetype * * @param string $mimetype - * @return array + * @return FileInfo[] */ public function searchByMime($mimetype) { return $this->searchCommon($mimetype, 'searchByMime'); @@ -1011,7 +1012,7 @@ class View { /** * @param string $query * @param string $method - * @return array + * @return FileInfo[] */ private function searchCommon($query, $method) { $files = array(); @@ -1025,8 +1026,9 @@ class View { $results = $cache->$method($query); foreach ($results as $result) { if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') { + $internalPath = $result['path']; $result['path'] = substr($mountPoint . $result['path'], $rootLength); - $files[] = $result; + $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result); } } @@ -1040,8 +1042,9 @@ class View { $results = $cache->$method($query); if ($results) { foreach ($results as $result) { + $internalPath = $result['path']; $result['path'] = $relativeMountPoint . $result['path']; - $files[] = $result; + $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result); } } } diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php new file mode 100644 index 00000000000..a11378c2ee5 --- /dev/null +++ b/lib/public/files/fileinfo.php @@ -0,0 +1,87 @@ + Date: Mon, 13 Jan 2014 14:42:14 +0100 Subject: [PATCH 11/74] Extends phpdoc for \OCP\File\FileInfo --- lib/public/files/fileinfo.php | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index a11378c2ee5..09c194fe96d 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -22,65 +22,98 @@ interface FileInfo extends \ArrayAccess, \JsonSerializable { public function jsonSerialize(); /** + * Get the Etag of the file or folder + * * @return string */ public function getEtag(); /** + * Get the size in bytes for the file or folder + * * @return int */ public function getSize(); /** + * Get the last modified date as timestamp for the file or folder + * * @return int */ public function getMtime(); /** + * Get the name of the file or folder + * * @return string */ public function getName(); /** + * Get the path relative to the storage + * * @return string */ public function getInternalPath(); /** + * Get the absolute path + * * @return string */ public function getPath(); /** + * Get the full mimetype of the file or folder i.e. 'image/png' + * * @return string */ public function getMimetype(); /** + * Get the first part of the mimetype of the file or folder i.e. 'image' + * + * @return string + */ + public function getMimePart(); + + /** + * Get the storage the file or folder is storage on + * * @return \OCP\Files\Storage */ public function getStorage(); /** + * Get the file id of the file or folder + * * @return int */ public function getId(); /** - * @return string - */ - public function getMimePart(); - /** + * Check whether the file is encrypted + * * @return bool */ public function isEncrypted(); /** + * Get the permissions of the file or folder as bitmasked combination of the following constants + * \OCP\PERMISSION_CREATE + * \OCP\PERMISSION_READ + * \OCP\PERMISSION_UPDATE + * \OCP\PERMISSION_DELETE + * \OCP\PERMISSION_SHARE + * \OCP\PERMISSION_ALL + * * @return int */ public function getPermissions(); /** + * Check whether this is a file or a folder + * * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER */ public function getType(); From 82762bb4627364241c69a8b39b1d7840a1d71614 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 15:13:45 +0100 Subject: [PATCH 12/74] remove ArrayAccess, JsonSerializable from the public part of FileInfo --- lib/private/files/fileinfo.php | 4 ++-- lib/public/files/fileinfo.php | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 24d99627aaf..8e9b6a8b72c 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Robin Appelman * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,7 +8,7 @@ namespace OC\Files; -class FileInfo implements \OCP\Files\FileInfo { +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @var array $data */ diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index 09c194fe96d..cbe216023da 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -1,26 +1,16 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ namespace OCP\Files; -interface FileInfo extends \ArrayAccess, \JsonSerializable { +interface FileInfo { const TYPE_FILE = 'file'; const TYPE_FOLDER = 'folder'; - public function offsetSet($offset, $value); - - public function offsetGet($offset); - - public function offsetUnset($offset); - - public function offsetExists($offset); - - public function jsonSerialize(); - /** * Get the Etag of the file or folder * From e706cf6c06a0111f9ec5db65e46f0fcc9261b456 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Jan 2014 15:57:49 +0100 Subject: [PATCH 13/74] add Support for passing a FileInfo instance to View->putFileInfo --- lib/private/files/fileinfo.php | 4 ++++ lib/private/files/view.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 8e9b6a8b72c..b80873d1d00 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -146,4 +146,8 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { public function getType() { return $this->data['type']; } + + public function getData(){ + return $this->data; + } } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 39c2ffed93d..b5870279664 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -963,12 +963,15 @@ class View { * change file metadata * * @param string $path - * @param array $data + * @param array | \OCP\Files\FileInfo $data * @return int * * returns the fileid of the updated file */ public function putFileInfo($path, $data) { + if ($data instanceof FileInfo) { + $data = $data->getData(); + } $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path); /** * @var \OC\Files\Storage\Storage $storage From ec7c339930618726f2f87899546ab7bc80ca96d5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 17 Jan 2014 12:56:17 +0100 Subject: [PATCH 14/74] Don't use is_array on FileInfo --- apps/files_encryption/lib/proxy.php | 4 ++-- apps/files_encryption/lib/stream.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 41f352d853a..70077e5e1f5 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -117,7 +117,7 @@ class Proxy extends \OC_FileProxy { // update file cache for target file $tmpFileInfo = $view->getFileInfo($tmpPath); $fileInfo = $view->getFileInfo($path); - if (is_array($fileInfo) && is_array($tmpFileInfo)) { + if ($fileInfo && $tmpFileInfo) { $fileInfo['encrypted'] = true; $fileInfo['unencrypted_size'] = $tmpFileInfo['size']; $view->putFileInfo($path, $fileInfo); @@ -365,7 +365,7 @@ class Proxy extends \OC_FileProxy { } // if file is encrypted return real file size - if (is_array($fileInfo) && $fileInfo['encrypted'] === true) { + if ($fileInfo && $fileInfo['encrypted'] === true) { // try to fix unencrypted file size if it doesn't look plausible if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0 ) { $fixSize = $util->getFileSize($path); diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index b3bf34ddb82..88eacc6f136 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -567,7 +567,7 @@ class Stream { // get file info $fileInfo = $this->rootView->getFileInfo($path); - if (is_array($fileInfo)) { + if ($fileInfo) { // set encryption data $fileInfo['encrypted'] = true; $fileInfo['size'] = $this->size; From 642d8e370e366bab6734a07aca78c4d0c8eca1c0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 17 Jan 2014 13:32:38 +0100 Subject: [PATCH 15/74] Dont use php5.4 only features --- tests/lib/files/cache/cache.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 7d9329328a3..5ef1ed7ca30 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -169,8 +169,9 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertEquals(916, $this->cache->calculateFolderSize($file1)); // direct cache entry retrieval returns the original values - $this->assertEquals(1025, $this->cache->get($file1)['size']); - $this->assertEquals(916, $this->cache->get($file1)['unencrypted_size']); + $cacheResult = $this->cache->get($file1); + $this->assertEquals(1025, $cacheResult['size']); + $this->assertEquals(916, $cacheResult['unencrypted_size']); $this->cache->remove($file2); $this->cache->remove($file3); From 299bb4d99db935bb529a30fe6ae0c9bc72344d69 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 17 Jan 2014 14:38:14 +0100 Subject: [PATCH 16/74] remove more is_array from encryption --- apps/files_encryption/lib/proxy.php | 4 ++-- apps/files_encryption/tests/share.php | 14 +++++++------- apps/files_encryption/tests/util.php | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 70077e5e1f5..c1b60799e64 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -307,7 +307,7 @@ class Proxy extends \OC_FileProxy { public function postGetFileInfo($path, $data) { // if path is a folder do nothing - if (\OCP\App::isEnabled('files_encryption') && is_array($data) && array_key_exists('size', $data)) { + if (\OCP\App::isEnabled('files_encryption') && $data !== false && array_key_exists('size', $data)) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; @@ -378,7 +378,7 @@ class Proxy extends \OC_FileProxy { $size = $fileInfo['unencrypted_size']; } else { // self healing if file was removed from file cache - if (!is_array($fileInfo)) { + if (!$fileInfo) { $fileInfo = array(); } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index e55427620a6..fba608320d6 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -150,7 +150,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // check if the unencrypted file size is stored $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); @@ -308,7 +308,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -384,7 +384,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { . $this->subfolder); // check if we have a valid file info - $this->assertTrue(is_array($fileInfoSubFolder)); + $this->assertTrue($fileInfoSubFolder instanceof \OC\Files\FileInfo); // re-enable the file proxy \OC_FileProxy::$enabled = $proxyStatus; @@ -418,7 +418,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { . $this->subsubfolder . '/' . $this->filename); // check if we have fileInfos - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the file with user3 \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, OCP\PERMISSION_ALL); @@ -513,7 +513,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // check if the unencrypted file size is stored $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); @@ -589,7 +589,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // check if the unencrypted file size is stored $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); @@ -876,7 +876,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // check if the unencrypted file size is stored $this->assertGreaterThan(0, $fileInfo['unencrypted_size']); diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index b1904cbadc7..c789b9e2c10 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -328,7 +328,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); - $this->assertTrue(is_array($fileInfoUnencrypted)); + $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo); // enable file encryption again \OC_App::enable('files_encryption'); @@ -338,7 +338,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); - $this->assertTrue(is_array($fileInfoEncrypted)); + $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo); // check if mtime and etags unchanged $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); @@ -357,14 +357,14 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { $fileInfoEncrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); - $this->assertTrue(is_array($fileInfoEncrypted)); + $this->assertTrue($fileInfoEncrypted instanceof \OC\Files\FileInfo); // encrypt all unencrypted files $util->decryptAll('/' . $this->userId . '/' . 'files'); $fileInfoUnencrypted = $this->view->getFileInfo($this->userId . '/files/' . $filename); - $this->assertTrue(is_array($fileInfoUnencrypted)); + $this->assertTrue($fileInfoUnencrypted instanceof \OC\Files\FileInfo); // check if mtime and etags unchanged $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); From 94504d7265227d18c2d1abbbf76f9913c795c634 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 20 Jan 2014 14:18:10 +0100 Subject: [PATCH 17/74] undo 3rdparty change --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 3f466720839..95ab25149c4 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 3f466720839295d8607f57bf7a96b7a03d77b52b +Subproject commit 95ab25149c4903650a1113c01ccb1732fb089f14 From 3971b12768ebe4fb410724a127173c38639c0a97 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 20 Jan 2014 14:20:01 +0100 Subject: [PATCH 18/74] undo 3rdparty change --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 95ab25149c4..faeedfcc057 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 95ab25149c4903650a1113c01ccb1732fb089f14 +Subproject commit faeedfcc0573868a2f0bde81f25a67a940c100ab From 374e3475c9e2e0220cc8639a1a06f68b7f43fb2b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 21 Jan 2014 23:58:48 +0100 Subject: [PATCH 19/74] Also remove the user's home storage from the storage table when deleting a user --- lib/private/files/cache/storage.php | 13 +++++++++++++ lib/private/user.php | 3 +++ 2 files changed, 16 insertions(+) diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 5657cf06e12..6d7a1002c1b 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -70,4 +70,17 @@ class Storage { return false; } } + + /** + * remove the entry for the storage + * + * @param string $storageId + */ + public static function remove($storageId) { + if (strlen($storageId) > 64) { + $storageId = md5($storageId); + } + $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; + \OC_DB::executeAudited($sql, array($storageId)); + } } diff --git a/lib/private/user.php b/lib/private/user.php index 98ebebbe5c1..2519200d0f0 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,6 +205,9 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); + // Remove it from the Cache self::getManager()->delete($uid); } From 5a5b6f187e719e6c0bac5e64c411eb74e6d28389 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 22 Jan 2014 13:00:45 +0100 Subject: [PATCH 20/74] Use Cache->clear to cleanup the filecache for removed users --- lib/private/user.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/private/user.php b/lib/private/user.php index 2519200d0f0..7932f4aef76 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,8 +205,13 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Delete the users entry in the storage table - \OC\Files\Cache\Storage::remove('home::' . $uid); + // Cleanup the filecache + $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); + if (count($mount) > 0) { + $mount = $mount[0]; + $cache = $mount->getStorage()->getCache(); + $cache->clear(); + } // Remove it from the Cache self::getManager()->delete($uid); @@ -243,15 +248,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); + OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); - if($uid) { + if ($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); + OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); return true; } return false; From fc5f20112efe03b203978c4b1045ed70c2ce5e74 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Jan 2014 15:54:40 +0100 Subject: [PATCH 21/74] Add isReadable, isUpdateable, isDeletable, isShareable --- lib/private/files/fileinfo.php | 38 +++++++++++++++++++++++++++++++++- lib/public/files/fileinfo.php | 28 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index b80873d1d00..7edea13df96 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -122,7 +122,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { /** * @return int */ - public function getMtime() { + public function getMTime() { return $this->data['mtime']; } @@ -150,4 +150,40 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { public function getData(){ return $this->data; } + + /** + * @param int $permissions + * @return bool + */ + protected function checkPermissions($permissions) { + return ($this->getPermissions() & $permissions) === $permissions; + } + + /** + * @return bool + */ + public function isReadable() { + return $this->checkPermissions(\OCP\PERMISSION_READ); + } + + /** + * @return bool + */ + public function isUpdateable() { + return $this->checkPermissions(\OCP\PERMISSION_UPDATE); + } + + /** + * @return bool + */ + public function isDeletable() { + return $this->checkPermissions(\OCP\PERMISSION_DELETE); + } + + /** + * @return bool + */ + public function isShareable() { + return $this->checkPermissions(\OCP\PERMISSION_SHARE); + } } diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php index cbe216023da..68ce45d3fa1 100644 --- a/lib/public/files/fileinfo.php +++ b/lib/public/files/fileinfo.php @@ -107,4 +107,32 @@ interface FileInfo { * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER */ public function getType(); + + /** + * Check if the file or folder is readable + * + * @return bool + */ + public function isReadable(); + + /** + * Check if a file is writable + * + * @return bool + */ + public function isUpdateable(); + + /** + * Check if a file or folder can be deleted + * + * @return bool + */ + public function isDeletable(); + + /** + * Check if a file or folder can be shared + * + * @return bool + */ + public function isShareable(); } From c2ed8d5aa111ac537cf37bbf0d60fd503a62c24a Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Sun, 26 Jan 2014 18:46:09 +0100 Subject: [PATCH 22/74] New user agent added for the Freebox. The Freebox is the multimedia device of a french Internet provider: Free. This device provides a seedbox which uses the user agent "Mozilla/5.0". In the "Content-Disposition" header, if the "filename" key is used with the "filename*=UTF-8''" value, the seedbox does not take care about the header and saves the file name with the origin URL. This patch brings the support for the Freebox users. --- lib/private/request.php | 1 + lib/private/response.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/private/request.php b/lib/private/request.php index d9d5ae08e28..855148ac25a 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -11,6 +11,7 @@ class OC_Request { const USER_AGENT_IE = '/MSIE/'; // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; + const USER_AGENT_FREEBOX = '#Mozilla/5\.0$#'; /** * @brief Check overwrite condition diff --git a/lib/private/response.php b/lib/private/response.php index 04746437347..52dbb9d90f8 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -153,7 +153,11 @@ class OC_Response { * @param string $type disposition type, either 'attachment' or 'inline' */ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { - if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME))) { + if (OC_Request::isUserAgent(array( + OC_Request::USER_AGENT_IE, + OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME, + OC_Request::USER_AGENT_FREEBOX + ))) { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); } else { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) From 3c1ab66edac1ba2f1b398c859cd933c410ea3d8d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 27 Jan 2014 15:56:57 +0100 Subject: [PATCH 23/74] Reuse the calculated free_space in buildFileStorageStatistics --- apps/files/lib/helper.php | 8 ++++---- lib/private/helper.php | 9 ++++++--- lib/public/util.php | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index eaff28178ea..87939d26921 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -5,14 +5,14 @@ namespace OCA\Files; class Helper { public static function buildFileStorageStatistics($dir) { + // information about storage capacities + $storageInfo = \OC_Helper::getStorageInfo($dir); + $l = new \OC_L10N('files'); - $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); $maxHumanFilesize = \OCP\Util::humanFileSize($maxUploadFilesize); $maxHumanFilesize = $l->t('Upload') . ' max. ' . $maxHumanFilesize; - // information about storage capacities - $storageInfo = \OC_Helper::getStorageInfo($dir); - return array('uploadMaxFilesize' => $maxUploadFilesize, 'maxHumanFilesize' => $maxHumanFilesize, 'usedSpacePercent' => (int)$storageInfo['relative']); diff --git a/lib/private/helper.php b/lib/private/helper.php index 1c8d01c141f..12784c9a5eb 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -824,13 +824,16 @@ class OC_Helper { /** * @brief calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { + public static function maxUploadFilesize($dir, $freeSpace = null) { $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); - $freeSpace = \OC\Files\Filesystem::free_space($dir); + if (is_null($freeSpace)) { + $freeSpace = \OC\Files\Filesystem::free_space($dir); + } if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) { $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED; } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) { diff --git a/lib/public/util.php b/lib/public/util.php index 6317f10a66f..52874bcc954 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -456,10 +456,11 @@ class Util { /** * calculates the maximum upload size respecting system settings, free space and user quota * - * @param $dir the current folder where the user currently operates + * @param string $dir the current folder where the user currently operates + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly * @return number of bytes representing */ - public static function maxUploadFilesize($dir) { - return \OC_Helper::maxUploadFilesize($dir); + public static function maxUploadFilesize($dir, $free = null) { + return \OC_Helper::maxUploadFilesize($dir, $free); } } From 8507efc4273aa87e32090bcabb31b7bc5b98ec35 Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Tue, 28 Jan 2014 21:08:27 +0100 Subject: [PATCH 24/74] Unit tests added for the new Freebox user agent. --- tests/lib/request.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/lib/request.php b/tests/lib/request.php index c6401a57144..3cb58674d3e 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -118,6 +118,16 @@ class Test_Request extends PHPUnit_Framework_TestCase { ), true ), + array( + 'Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0', + OC_Request::USER_AGENT_FREEBOX, + false + ), + array( + 'Mozilla/5.0', + OC_Request::USER_AGENT_FREEBOX, + true + ), ); } } From 0f1c587e6baaa201f01683b6adac8cc907c4f3e3 Mon Sep 17 00:00:00 2001 From: Martial Saunois Date: Wed, 29 Jan 2014 10:58:34 +0100 Subject: [PATCH 25/74] The regexp of the Freebox user agent is now more strict. A new unit test has been added in consequence. --- lib/private/request.php | 2 +- tests/lib/request.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/private/request.php b/lib/private/request.php index 855148ac25a..2c5b907846e 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -11,7 +11,7 @@ class OC_Request { const USER_AGENT_IE = '/MSIE/'; // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; - const USER_AGENT_FREEBOX = '#Mozilla/5\.0$#'; + const USER_AGENT_FREEBOX = '#^Mozilla/5\.0$#'; /** * @brief Check overwrite condition diff --git a/tests/lib/request.php b/tests/lib/request.php index 3cb58674d3e..1d77acc70ae 100644 --- a/tests/lib/request.php +++ b/tests/lib/request.php @@ -128,6 +128,11 @@ class Test_Request extends PHPUnit_Framework_TestCase { OC_Request::USER_AGENT_FREEBOX, true ), + array( + 'Fake Mozilla/5.0', + OC_Request::USER_AGENT_FREEBOX, + false + ), ); } } From 229f13adc0eca770c07646e56773f1aa93fee643 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 29 Jan 2014 14:40:59 +0100 Subject: [PATCH 26/74] change order of issubdirectory() calls to avoid error messages for non-apps --- lib/private/l10n.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/l10n.php b/lib/private/l10n.php index 98665c84c55..1aa1dc5ea28 100644 --- a/lib/private/l10n.php +++ b/lib/private/l10n.php @@ -132,10 +132,10 @@ class OC_L10N implements \OCP\IL10N { $i18ndir = self::findI18nDir($app); // Localization is in /l10n, Texts are in $i18ndir // (Just no need to define date/time format etc. twice) - if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') - || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') + if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/') || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings') + || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') ) && file_exists($i18ndir.$lang.'.php')) { // Include the file, save the data from $CONFIG From c5742520e132dc072bd8e5f69e5568d5c16c3f1e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 11 Jan 2014 11:51:28 +0100 Subject: [PATCH 27/74] don't urldecode get var, php does this automatically --- apps/files_sharing/ajax/publicpreview.php | 2 +- apps/files_trashbin/ajax/preview.php | 2 +- core/ajax/preview.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php index a52f522afac..d12d212a2e6 100644 --- a/apps/files_sharing/ajax/publicpreview.php +++ b/apps/files_sharing/ajax/publicpreview.php @@ -11,7 +11,7 @@ if(!\OC_App::isEnabled('files_sharing')){ \OC_User::setIncognitoMode(true); -$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; +$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : ''; $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; diff --git a/apps/files_trashbin/ajax/preview.php b/apps/files_trashbin/ajax/preview.php index ce432f4d14e..d003a9a0791 100644 --- a/apps/files_trashbin/ajax/preview.php +++ b/apps/files_trashbin/ajax/preview.php @@ -11,7 +11,7 @@ if(!\OC_App::isEnabled('files_trashbin')){ exit; } -$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; +$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : ''; $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; diff --git a/core/ajax/preview.php b/core/ajax/preview.php index af0f0493f4c..d85dff7632f 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -7,7 +7,7 @@ */ \OC_Util::checkLoggedIn(); -$file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; +$file = array_key_exists('file', $_GET) ? (string) $_GET['file'] : ''; $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; @@ -26,6 +26,7 @@ if($maxX === 0 || $maxY === 0) { exit; } + try{ $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($file); From f7c291e2768b83176aad6dacbf0139949c2208fd Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Sat, 11 Jan 2014 11:53:56 +0100 Subject: [PATCH 28/74] remove empty line --- core/ajax/preview.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/ajax/preview.php b/core/ajax/preview.php index d85dff7632f..a1267d6f5cf 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -26,7 +26,6 @@ if($maxX === 0 || $maxY === 0) { exit; } - try{ $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($file); From d49c7ad4fb1745600f33f0acc67fa39faca3e3e4 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 30 Jan 2014 16:31:47 +0100 Subject: [PATCH 29/74] Fixed double file encoding for previews --- apps/files_sharing/templates/public.php | 2 +- apps/files_trashbin/lib/trashbin.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 3ddaf4446df..3eb84ce1672 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -35,7 +35,7 @@
- +
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 7544980e071..9b7d578c990 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -996,6 +996,6 @@ class Trashbin { } public static function preview_icon($path) { - return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); + return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 36, 'y' => 36, 'file' => $path )); } } From 8d6a3a00b47aa7d034de378f498a7d5e329a8e1d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:29:04 +0100 Subject: [PATCH 30/74] Revert "Use Cache->clear to cleanup the filecache for removed users" This reverts commit 5a5b6f187e719e6c0bac5e64c411eb74e6d28389. --- lib/private/user.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/private/user.php b/lib/private/user.php index 7932f4aef76..2519200d0f0 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -205,13 +205,8 @@ class OC_User { // Delete user files in /data/ OC_Helper::rmdirr(\OC_User::getHome($uid)); - // Cleanup the filecache - $mount = \OC\Files\Filesystem::getMountByStorageId('home::' . $uid); - if (count($mount) > 0) { - $mount = $mount[0]; - $cache = $mount->getStorage()->getCache(); - $cache->clear(); - } + // Delete the users entry in the storage table + \OC\Files\Cache\Storage::remove('home::' . $uid); // Remove it from the Cache self::getManager()->delete($uid); @@ -248,15 +243,15 @@ class OC_User { $uid = $backend->getCurrentUserId(); $run = true; - OC_Hook::emit("OC_User", "pre_login", array("run" => &$run, "uid" => $uid)); + OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); - if ($uid) { + if($uid) { session_regenerate_id(true); self::setUserId($uid); self::setDisplayName($uid); self::getUserSession()->setLoginName($uid); - OC_Hook::emit("OC_User", "post_login", array("uid" => $uid, 'password' => '')); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' )); return true; } return false; From 0ae4022fb4fc6ade3ed300205ccdcdd32863dcdc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 3 Feb 2014 16:36:21 +0100 Subject: [PATCH 31/74] Also clean up the filecache table when deleting a storage entry --- lib/private/files/cache/storage.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index 6d7a1002c1b..5b1b30176e8 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -77,10 +77,16 @@ class Storage { * @param string $storageId */ public static function remove($storageId) { + $storageCache = new Storage($storageId); + $numericId = $storageCache->getNumericId(); + if (strlen($storageId) > 64) { $storageId = md5($storageId); } $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'; \OC_DB::executeAudited($sql, array($storageId)); + + $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'; + \OC_DB::executeAudited($sql, array($numericId)); } } From d55ef442cd861d04b9ccfd4493aedf0c9a4164ff Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 4 Feb 2014 12:59:14 +0100 Subject: [PATCH 32/74] properly check if pdf and svg modules are installed --- lib/private/preview/office.php | 2 +- lib/private/preview/pdf.php | 2 +- lib/private/preview/svg.php | 2 +- lib/private/preview/unknown.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 7a4826c76ec..884b6e7dc9b 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ //both, libreoffice backend and php fallback, need imagick -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec'); // LibreOffice preview is currently not supported on Windows diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php index cc974b68818..572b8788ac9 100644 --- a/lib/private/preview/pdf.php +++ b/lib/private/preview/pdf.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { class PDF extends Provider { diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php index b49e51720fa..07a37e8f8c1 100644 --- a/lib/private/preview/svg.php +++ b/lib/private/preview/svg.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick')) { +if (extension_loaded('imagick') && count(\Imagick::queryFormats("SVG")) === 1) { class SVG extends Provider { diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 4747f9e25ed..8145c826149 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -22,7 +22,7 @@ class Unknown extends Provider { $svgPath = substr_replace($path, 'svg', -3); - if (extension_loaded('imagick') && file_exists($svgPath)) { + if (extension_loaded('imagick') && file_exists($svgPath) && count(\Imagick::queryFormats("SVG")) === 1) { // http://www.php.net/manual/de/imagick.setresolution.php#85284 $svg = new \Imagick(); From 11f46e121caa30f46250a1980e315520d68eb593 Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Tue, 4 Feb 2014 17:03:52 +0100 Subject: [PATCH 33/74] close statement in MimeType detection is executed [#7069] close statement was never executed due to it being after a return statement. --- lib/private/files/type/detection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index d7cc9ebbf4e..11e439032ce 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -72,11 +72,12 @@ class Detection { and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) ) { $info = @strtolower(finfo_file($finfo, $path)); + finfo_close($finfo); if ($info) { $mimeType = substr($info, 0, strpos($info, ';')); return empty($mimeType) ? 'application/octet-stream' : $mimeType; } - finfo_close($finfo); + } $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { From 9d9f360b7742a061586f18f7f9b2910b7ddd081d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 5 Feb 2014 12:54:31 +0100 Subject: [PATCH 34/74] Load authentication apps to get users from all backends - fixes #7019 --- apps/files/command/scan.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/command/scan.php b/apps/files/command/scan.php index 25ab70af362..f334f29a939 100644 --- a/apps/files/command/scan.php +++ b/apps/files/command/scan.php @@ -58,6 +58,7 @@ class Scan extends Command { protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('all')) { + \OC_App::loadApps('authentication'); $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); From 788c8540aa6aac50795c37b088eeaa561d44b86c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 4 Feb 2014 19:58:49 +0100 Subject: [PATCH 35/74] Added isLocal() method to storage, used for xsendfile Added isLocal() method to Storage to find out whether the storage is local or not. This method is used for the x-sendfile logic to find out whether to add the headers. --- lib/private/files.php | 2 +- lib/private/files/storage/common.php | 9 +++++++++ lib/private/files/storage/local.php | 7 +++++++ lib/private/files/storage/wrapper/wrapper.php | 8 ++++++++ lib/public/files/storage.php | 11 +++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/private/files.php b/lib/private/files.php index 8ce632013cf..24fca4a5df3 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -131,7 +131,7 @@ class OC_Files { } if ($xsendfile) { list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename)); - if ($storage instanceof \OC\Files\Storage\Local) { + if ($storage->isLocal()) { self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename)); } } diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 678bf419023..55b1471593d 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -370,4 +370,13 @@ abstract class Common implements \OC\Files\Storage\Storage { public function free_space($path) { return \OC\Files\SPACE_UNKNOWN; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + // the common implementation returns a temporary file by + // default, which is not local + return false; + } } diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php index db3c6bfca3a..fa0788f2377 100644 --- a/lib/private/files/storage/local.php +++ b/lib/private/files/storage/local.php @@ -298,5 +298,12 @@ if (\OC_Util::runningOnWindows()) { public function hasUpdated($path, $time) { return $this->filemtime($path) > $time; } + + /** + * {@inheritdoc} + */ + public function isLocal() { + return true; + } } } diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index f9adda80314..11ea9f71da7 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -432,4 +432,12 @@ class Wrapper implements \OC\Files\Storage\Storage { public function test() { return $this->storage->test(); } + + /** + * Returns the wrapped storage's value for isLocal() + * @return bool wrapped storage's isLocal() value + */ + public function isLocal() { + return $this->storage->isLocal(); + } } diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php index 194b42a6481..fe30f8f50af 100644 --- a/lib/public/files/storage.php +++ b/lib/public/files/storage.php @@ -315,4 +315,15 @@ interface Storage { * @return string */ public function getETag($path); + + /** + * Returns whether the storage is local, which means that files + * are stored on the local filesystem instead of remotely. + * Calling getLocalFile() for local storages should always + * return the local files, whereas for non-local storages + * it might return a temporary file. + * + * @return bool true if the files are stored locally, false otherwise + */ + public function isLocal(); } From 88087b21c7dad792a73a764248829e2c83faa49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 7 Feb 2014 00:40:08 +0100 Subject: [PATCH 36/74] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca7b04a925a..47778c8c932 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ A personal cloud which runs on your own server. ### Build Status on [Jenkins CI](https://ci.owncloud.org/) -Git master: [![Build Status](https://ci.owncloud.org/buildStatus/icon?job=ownCloud-Server%28master%29)](https://ci.owncloud.org/job/ownCloud-Server%28master%29/) +Git master: [![Build Status](https://ci.owncloud.org/job/server-master-linux/badge/icon)](https://ci.owncloud.org/job/server-master-linux/) +Quality: [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/owncloud/core/badges/quality-score.png?s=ce2f5ded03d4ac628e9ee5c767243fa7412e644f)](https://scrutinizer-ci.com/g/owncloud/core/) ### Installation instructions http://doc.owncloud.org/server/5.0/developer_manual/app/gettingstarted.html From b9e724d4ae7635435b3cc7793237c3ab9fe2a1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 7 Feb 2014 00:40:57 +0100 Subject: [PATCH 37/74] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 47778c8c932..3f76c1a4773 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ A personal cloud which runs on your own server. ### Build Status on [Jenkins CI](https://ci.owncloud.org/) Git master: [![Build Status](https://ci.owncloud.org/job/server-master-linux/badge/icon)](https://ci.owncloud.org/job/server-master-linux/) + Quality: [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/owncloud/core/badges/quality-score.png?s=ce2f5ded03d4ac628e9ee5c767243fa7412e644f)](https://scrutinizer-ci.com/g/owncloud/core/) ### Installation instructions From a8943ad02207afbf142ec48f4b53cbe1be943253 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 6 Feb 2014 16:01:42 +0100 Subject: [PATCH 38/74] replace 'size' with 'unencrypted_size' if encryption is enabled --- apps/files_sharing/lib/cache.php | 15 +++++++++++++-- apps/files_sharing/lib/share/file.php | 9 ++++++++- lib/public/share.php | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 86e324409fe..1b102f9e5f8 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -92,12 +92,11 @@ class Shared_Cache extends Cache { } else { $query = \OC_DB::prepare( 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,' - .' `size`, `mtime`, `encrypted`' + .' `size`, `mtime`, `encrypted`, `unencrypted_size`' .' FROM `*PREFIX*filecache` WHERE `fileid` = ?'); $result = $query->execute(array($file)); $data = $result->fetchRow(); $data['fileid'] = (int)$data['fileid']; - $data['size'] = (int)$data['size']; $data['mtime'] = (int)$data['mtime']; $data['storage_mtime'] = (int)$data['storage_mtime']; $data['encrypted'] = (bool)$data['encrypted']; @@ -106,6 +105,12 @@ class Shared_Cache extends Cache { if ($data['storage_mtime'] === 0) { $data['storage_mtime'] = $data['mtime']; } + if ($data['encrypted'] or ($data['unencrypted_size'] > 0 and $data['mimetype'] === 'httpd/unix-directory')) { + $data['encrypted_size'] = (int)$data['size']; + $data['size'] = (int)$data['unencrypted_size']; + } else { + $data['size'] = (int)$data['size']; + } return $data; } return false; @@ -334,6 +339,12 @@ class Shared_Cache extends Cache { } $row['mimetype'] = $this->getMimetype($row['mimetype']); $row['mimepart'] = $this->getMimetype($row['mimepart']); + if ($row['encrypted'] or ($row['unencrypted_size'] > 0 and $row['mimetype'] === 'httpd/unix-directory')) { + $row['encrypted_size'] = $row['size']; + $row['size'] = $row['unencrypted_size']; + } else { + $row['size'] = $row['size']; + } $files[] = $row; } } diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index c956c55a1df..ec0f368386f 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -91,10 +91,17 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { $file['name'] = basename($item['file_target']); $file['mimetype'] = $item['mimetype']; $file['mimepart'] = $item['mimepart']; - $file['size'] = $item['size']; $file['mtime'] = $item['mtime']; $file['encrypted'] = $item['encrypted']; $file['etag'] = $item['etag']; + $storage = \OC\Files\Filesystem::getStorage('/'); + $cache = $storage->getCache(); + if ($item['encrypted'] or ($item['unencrypted_size'] > 0 and $cache->getMimetype($item['mimetype']) === 'httpd/unix-directory')) { + $file['size'] = $item['unencrypted_size']; + $file['encrypted_size'] = $item['size']; + } else { + $file['size'] = $item['size']; + } $files[] = $file; } return $files; diff --git a/lib/public/share.php b/lib/public/share.php index f832d04a70f..ae7d29e8b87 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1152,7 +1152,7 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `unencrypted_size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, From af7366cd30f0df27cc1043f2c2b55def836d03db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Feb 2014 12:53:42 +0100 Subject: [PATCH 39/74] Only add files to file list when uploading to current directory Fix Issue #6683 --- apps/files/ajax/upload.php | 6 ++++-- apps/files/js/filelist.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 8f6c42d6620..754c34ef088 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -139,7 +139,8 @@ if (strpos($dir, '..') === false) { 'originalname' => $files['tmp_name'][$i], 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, - 'permissions' => $meta['permissions'] & $allowedPermissions + 'permissions' => $meta['permissions'] & $allowedPermissions, + 'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)), ); } @@ -166,7 +167,8 @@ if (strpos($dir, '..') === false) { 'originalname' => $files['tmp_name'][$i], 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, - 'permissions' => $meta['permissions'] & $allowedPermissions + 'permissions' => $meta['permissions'] & $allowedPermissions, + 'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)), ); } } diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index f538af10362..e6aefd33c96 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -924,8 +924,8 @@ $(document).ready(function() { data.context.find('td.filesize').text(humanFileSize(size)); } else { - // only append new file if dragged onto current dir's crumb (last) - if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('last')) { + // only append new file if uploaded into the current folder + if (file.directory !== FileList.getCurrentDirectory()) { return; } From cd3ef0bb9d6585dcc07e7ca62285032245283106 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 7 Feb 2014 14:03:39 +0100 Subject: [PATCH 40/74] Add caching to appconfig --- lib/private/appconfig.php | 61 +++++++++++++++++++++-------- lib/private/db/statementwrapper.php | 3 ++ 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index ff47f08d485..71aa8307316 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -47,6 +47,10 @@ class AppConfig implements \OCP\IAppConfig { */ protected $conn; + private $cache = array(); + + private $appsLoaded = array(); + /** * @param \OC\DB\Connection $conn */ @@ -54,6 +58,32 @@ class AppConfig implements \OCP\IAppConfig { $this->conn = $conn; } + /** + * @param string $app + * @return string[] + */ + private function getAppCache($app) { + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + return $this->cache[$app]; + } + + private function getAppValues($app) { + $appCache = $this->getAppCache($app); + if (array_search($app, $this->appsLoaded) === false) { + $query = 'SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`' + . ' WHERE `appid` = ?'; + $result = $this->conn->executeQuery($query, array($app)); + while ($row = $result->fetch()) { + $appCache[$row['configkey']] = $row['configvalue']; + } + $this->appsLoaded[] = $app; + } + $this->cache[$app] = $appCache; + return $appCache; + } + /** * @brief Get all apps using the config * @return array with app ids @@ -81,15 +111,8 @@ class AppConfig implements \OCP\IAppConfig { * not returned. */ public function getKeys($app) { - $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; - $result = $this->conn->executeQuery($query, array($app)); - - $keys = array(); - while ($key = $result->fetchColumn()) { - $keys[] = $key; - } - - return $keys; + $values = $this->getAppValues($app); + return array_keys($values); } /** @@ -103,11 +126,9 @@ class AppConfig implements \OCP\IAppConfig { * not exist the default value will be returned */ public function getValue($app, $key, $default = null) { - $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' - . ' WHERE `appid` = ? AND `configkey` = ?'; - $row = $this->conn->fetchAssoc($query, array($app, $key)); - if ($row) { - return $row['configvalue']; + $values = $this->getAppValues($app); + if (isset($values[$key])) { + return $values[$key]; } else { return $default; } @@ -120,8 +141,8 @@ class AppConfig implements \OCP\IAppConfig { * @return bool */ public function hasKey($app, $key) { - $exists = $this->getKeys($app); - return in_array($key, $exists); + $values = $this->getAppValues($app); + return isset($values[$key]); } /** @@ -151,6 +172,10 @@ class AppConfig implements \OCP\IAppConfig { ); $this->conn->update('*PREFIX*appconfig', $data, $where); } + if (!isset($this->cache[$app])) { + $this->cache[$app] = array(); + } + $this->cache[$app][$key] = $value; } /** @@ -167,6 +192,9 @@ class AppConfig implements \OCP\IAppConfig { 'configkey' => $key, ); $this->conn->delete('*PREFIX*appconfig', $where); + if (isset($this->cache[$app]) and isset($this->cache[$app][$key])) { + unset($this->cache[$app][$key]); + } } /** @@ -181,6 +209,7 @@ class AppConfig implements \OCP\IAppConfig { 'appid' => $app, ); $this->conn->delete('*PREFIX*appconfig', $where); + unset($this->cache[$app]); } /** diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index 5e89261d936..a71df315e2f 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -31,6 +31,9 @@ class OC_DB_StatementWrapper { /** * make execute return the result instead of a bool + * + * @param array $input + * @return \OC_DB_StatementWrapper | int */ public function execute($input=array()) { if(OC_Config::getValue( "log_query", false)) { From 4cdf83e6d257c57ebad60e60dec474faa83a51d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 7 Feb 2014 14:03:57 +0100 Subject: [PATCH 41/74] Remove the Test_AppConfig_Object tests as they no longer make sense with caching --- tests/lib/appconfig.php | 180 ---------------------------------------- 1 file changed, 180 deletions(-) diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 29b29778fd2..5cbdf80502f 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -131,183 +131,3 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $values); } } - -class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { - public function testGetApps() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`')) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $apps = $appconfig->getApps(); - $this->assertEquals(array('foo'), $apps); - } - - public function testGetKeys() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $keys = $appconfig->getKeys('bar'); - $this->assertEquals(array('foo'), $keys); - } - - public function testGetValue() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('fetchAssoc') - ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'), - $this->equalTo(array('bar', 'red'))) - ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null)); - - $appconfig = new OC\AppConfig($connectionMock); - $value = $appconfig->getValue('bar', 'red'); - $this->assertEquals('foo', $value); - $value = $appconfig->getValue('bar', 'red', 'def'); - $this->assertEquals('def', $value); - } - - public function testHasKey() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(3)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false, false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $this->assertTrue($appconfig->hasKey('bar', 'foo')); - $this->assertFalse($appconfig->hasKey('bar', 'foo')); - } - - public function testSetValue() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(4)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false, 'foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - $connectionMock->expects($this->once()) - ->method('insert') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'appid' => 'bar', - 'configkey' => 'moo', - 'configvalue' => 'v1', - ) - )); - $connectionMock->expects($this->once()) - ->method('update') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'configvalue' => 'v2', - )), - $this->equalTo( - array( - 'appid' => 'bar', - 'configkey' => 'foo', - ) - )); - - $appconfig = new OC\AppConfig($connectionMock); - $appconfig->setValue('bar', 'moo', 'v1'); - $appconfig->setValue('bar', 'foo', 'v2'); - } - - public function testDeleteKey() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('delete') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'appid' => 'bar', - 'configkey' => 'foo', - ) - )); - - $appconfig = new OC\AppConfig($connectionMock); - $appconfig->deleteKey('bar', 'foo'); - } - - public function testDeleteApp() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('delete') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'appid' => 'bar', - ) - )); - - $appconfig = new OC\AppConfig($connectionMock); - $appconfig->deleteApp('bar'); - } - - public function testGetValues() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(4)) - ->method('fetch') - ->with(\PDO::FETCH_ASSOC) - ->will($this->onConsecutiveCalls( - array('configvalue' =>'bar', 'configkey' => 'x'), - false, - array('configvalue' =>'foo', 'appid' => 'y'), - false - )); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->at(0)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('foo'))) - ->will($this->returnValue($statementMock)); - $connectionMock->expects($this->at(1)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $values = $appconfig->getValues('foo', false); - $this->assertEquals(array('x'=> 'bar'), $values); - $values = $appconfig->getValues(false, 'bar'); - $this->assertEquals(array('y'=> 'foo'), $values); - $values = $appconfig->getValues(false, false); - $this->assertEquals(false, $values); - $values = $appconfig->getValues('x', 'x'); - $this->assertEquals(false, $values); - } -} From dc53c83e7bdbadeb24c74fe1c7794de54811c264 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 28 Jan 2014 17:42:26 +0100 Subject: [PATCH 42/74] getData() always needs to return an array --- lib/private/ocs/result.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/private/ocs/result.php b/lib/private/ocs/result.php index 84f06fa01c7..9f14e8da7e8 100644 --- a/lib/private/ocs/result.php +++ b/lib/private/ocs/result.php @@ -29,7 +29,13 @@ class OC_OCS_Result{ * @param $data mixed the data to return */ public function __construct($data=null, $code=100, $message=null) { - $this->data = $data; + if ($data === null) { + $this->data = array(); + } elseif (!is_array($data)) { + $this->data = array($this->data); + } else { + $this->data = $data; + } $this->statusCode = $code; $this->message = $message; } @@ -49,7 +55,7 @@ class OC_OCS_Result{ public function setItemsPerPage(int $items) { $this->perPage = $items; } - + /** * get the status code * @return int @@ -57,7 +63,7 @@ class OC_OCS_Result{ public function getStatusCode() { return $this->statusCode; } - + /** * get the meta data for the result * @return array @@ -76,15 +82,15 @@ class OC_OCS_Result{ return $meta; } - + /** * get the result data - * @return array|string|int + * @return array */ public function getData() { return $this->data; } - + /** * return bool if the method succedded * @return bool From dbec143f09f32832a52fb507ababb84518721370 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Feb 2014 16:09:31 +0100 Subject: [PATCH 43/74] Change MySQL to MySQL/MariaDB in the frontend Fix issue #6269 --- core/setup/controller.php | 2 +- lib/private/setup/mysql.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 58ed4d28dc0..697408cfb57 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -91,7 +91,7 @@ class Controller { $databases['sqlite'] = 'SQLite'; } if ($hasMySQL) { - $databases['mysql'] = 'MySQL'; + $databases['mysql'] = 'MySQL/MariaDB'; } if ($hasPostgreSQL) { $databases['pgsql'] = 'PostgreSQL'; diff --git a/lib/private/setup/mysql.php b/lib/private/setup/mysql.php index d97b6d2602f..b2c28173b1c 100644 --- a/lib/private/setup/mysql.php +++ b/lib/private/setup/mysql.php @@ -3,13 +3,13 @@ namespace OC\Setup; class MySQL extends AbstractDatabase { - public $dbprettyname = 'MySQL'; + public $dbprettyname = 'MySQL/MariaDB'; public function setupDatabase($username) { //check if the database user has admin right $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword); if(!$connection) { - throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), + throw new \DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.')); } $oldUser=\OC_Config::getValue('dbuser', false); @@ -82,14 +82,14 @@ class MySQL extends AbstractDatabase { $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'localhost' exists already.", array($name)), - $this->trans->t("Drop this user from MySQL", array($name))); + throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'localhost' exists already.", array($name)), + $this->trans->t("Drop this user from MySQL/MariaDB", array($name))); } $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'%%' already exists", array($name)), - $this->trans->t("Drop this user from MySQL.")); + throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'%%' already exists", array($name)), + $this->trans->t("Drop this user from MySQL/MariaDB.")); } } } From 13fa0e2a9d3f89e4479f30b847c7c197276e5537 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Fri, 7 Feb 2014 17:47:42 +0100 Subject: [PATCH 44/74] Fix implied evals and doubled definition of variable fixes #7119 fixes #7120 fixes #7121 fixes #7122 --- apps/files/js/filelist.js | 10 ++++------ apps/files/js/files.js | 2 +- settings/js/personal.js | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index f538af10362..2883218b2cc 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -435,10 +435,9 @@ window.FileList={ tr.attr('data-file', newname); var path = td.children('a.name').attr('href'); td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname))); + var basename = newname; if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { - var basename=newname.substr(0,newname.lastIndexOf('.')); - } else { - var basename=newname; + basename = newname.substr(0,newname.lastIndexOf('.')); } td.find('a.name span.nametext').text(basename); if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { @@ -544,10 +543,9 @@ window.FileList={ td.children('a.name .span').text(newName); var path = td.children('a.name').attr('href'); td.children('a.name').attr('href', path.replace(encodeURIComponent(oldName), encodeURIComponent(newName))); + var basename = newName; if (newName.indexOf('.') > 0) { - var basename = newName.substr(0, newName.lastIndexOf('.')); - } else { - var basename = newName; + basename = newName.substr(0, newName.lastIndexOf('.')); } td.children('a.name').empty(); var span = $(''); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a535700c1b3..1ec4c4ec7ab 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -405,7 +405,7 @@ $(document).ready(function() { Files.resizeBreadcrumbs(width, true); // display storage warnings - setTimeout ( "Files.displayStorageWarnings()", 100 ); + setTimeout(Files.displayStorageWarnings, 100); OC.Notification.setDefault(Files.displayStorageWarnings); // only possible at the moment if user is logged in diff --git a/settings/js/personal.js b/settings/js/personal.js index e6e1d538a19..3b876467756 100644 --- a/settings/js/personal.js +++ b/settings/js/personal.js @@ -158,7 +158,7 @@ $(document).ready(function(){ if(typeof timeout !== 'undefined'){ clearTimeout(timeout); } - timeout = setTimeout('changeDisplayName()',1000); + timeout = setTimeout(changeDisplayName, 1000); } }); @@ -173,7 +173,7 @@ $(document).ready(function(){ if(typeof timeout !== 'undefined'){ clearTimeout(timeout); } - timeout = setTimeout('changeEmailAddress()',1000); + timeout = setTimeout(changeEmailAddress, 1000); } }); From 91254c304d454b6f7977037dbd5dd2db5e00ff9f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 7 Feb 2014 15:57:13 +0100 Subject: [PATCH 45/74] name users after test --- apps/files_encryption/tests/hooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index c26cba6406d..44525791743 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -36,8 +36,8 @@ use OCA\Encryption; */ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase { - const TEST_ENCRYPTION_HOOKS_USER1 = "test-proxy-user1"; - const TEST_ENCRYPTION_HOOKS_USER2 = "test-proxy-user2"; + const TEST_ENCRYPTION_HOOKS_USER1 = "test-encryption-hooks-user1"; + const TEST_ENCRYPTION_HOOKS_USER2 = "test-encryption-hooks-user2"; /** * @var \OC_FilesystemView From 828985dc6092808bbb1a3cb07f637e6da0dfeb65 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Feb 2014 18:12:01 +0100 Subject: [PATCH 46/74] Make google drive client secret and dropbox api secret a password field Fix issue #5794 --- apps/files_external/lib/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 01d588b3721..48fc4dfe46e 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -61,7 +61,7 @@ class OC_Mount_Config { 'configuration' => array( 'configured' => '#configured', 'app_key' => 'App key', - 'app_secret' => 'App secret', + 'app_secret' => '*App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'); @@ -80,7 +80,7 @@ class OC_Mount_Config { 'configuration' => array( 'configured' => '#configured', 'client_id' => 'Client ID', - 'client_secret' => 'Client secret', + 'client_secret' => '*Client secret', 'token' => '#token'), 'custom' => 'google'); From 050e84a08fa8eee14e52f4dbbee572596ba002ce Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 10 Feb 2014 10:56:11 +0100 Subject: [PATCH 47/74] refuse login as long as the initial encryption is running --- apps/files_encryption/hooks/hooks.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 4c4b3f2040f..83abf3ba9de 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -80,8 +80,15 @@ class Hooks { // Check if first-run file migration has already been performed $ready = false; - if ($util->getMigrationStatus() === Util::MIGRATION_OPEN) { + $migrationStatus = $util->getMigrationStatus(); + if ($migrationStatus === Util::MIGRATION_OPEN) { $ready = $util->beginMigration(); + } elseif ($migrationStatus === Util::MIGRATION_IN_PROGRESS) { + // refuse login as long as the initial encryption is running + while ($migrationStatus === Util::MIGRATION_IN_PROGRESS) { + sleep(60); + $migrationStatus = $util->getMigrationStatus(); + } } // If migration not yet done From bc17b40650875102521214d5f8b7580c3193b8df Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 4 Feb 2014 17:56:53 +0100 Subject: [PATCH 48/74] LDAP: extend LDAP wrapper search method for sizelimit, improves performance in wizard --- apps/user_ldap/lib/ildapwrapper.php | 4 +++- apps/user_ldap/lib/ldap.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/user_ldap/lib/ildapwrapper.php b/apps/user_ldap/lib/ildapwrapper.php index 20587cba7db..e60cf5ec63f 100644 --- a/apps/user_ldap/lib/ildapwrapper.php +++ b/apps/user_ldap/lib/ildapwrapper.php @@ -145,9 +145,11 @@ interface ILDAPWrapper { * @param $baseDN The DN of the entry to read from * @param $filter An LDAP filter * @param $attr array of the attributes to read + * @param $attrsonly optional, 1 if only attribute types shall be returned + * @param $limit optional, limits the result entries * @return an LDAP search result resource, false on error */ - public function search($link, $baseDN, $filter, $attr); + public function search($link, $baseDN, $filter, $attr, $attrsonly = 0, $limit = 0); /** * @brief Sets the value of the specified option to be $value diff --git a/apps/user_ldap/lib/ldap.php b/apps/user_ldap/lib/ldap.php index dda8533c41f..a99c6480121 100644 --- a/apps/user_ldap/lib/ldap.php +++ b/apps/user_ldap/lib/ldap.php @@ -85,9 +85,9 @@ class LDAP implements ILDAPWrapper { return $this->invokeLDAPMethod('read', $link, $baseDN, $filter, $attr); } - public function search($link, $baseDN, $filter, $attr) { - return $this->invokeLDAPMethod('search', $link, $baseDN, - $filter, $attr); + public function search($link, $baseDN, $filter, $attr, $attrsonly = 0, $limit = 0) { + return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, + $attr, $attrsonly, $limit); } public function setOption($link, $option, $value) { From a908bd56953edb94f48dc483278f5427d51c17b2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 4 Feb 2014 19:37:40 +0100 Subject: [PATCH 49/74] throw an info message, when base dn test failed --- apps/user_ldap/lib/wizard.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index b70ede8599c..30ce455274b 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -567,6 +567,10 @@ class Wizard extends LDAPUtility { //get a result set > 0 on a proper base $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); if(!$this->ldap->isResource($rr)) { + $errorNo = $this->ldap->errno($cr); + $errorMsg = $this->ldap->error($cr); + \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. + ' Error '.$errorNo.': '.$errorMsg, \OCP\Util::INFO); return false; } $entries = $this->ldap->countEntries($cr, $rr); From e825a008c9b99199bc91b87cb0e5ca88109aa202 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 10:29:09 +0100 Subject: [PATCH 50/74] Wizard: disable LDAP referrals, fixes #6670 --- apps/user_ldap/lib/wizard.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 30ce455274b..00623b74fb1 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -1014,6 +1014,7 @@ class Wizard extends LDAPUtility { $this->configuration->ldapPort); $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); + $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); if($this->configuration->ldapTLS === 1) { $this->ldap->startTls($cr); From a76840d20650b09d1a403c3f8e78dbf398a46fda Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 10:30:56 +0100 Subject: [PATCH 51/74] Wizard: enable base DN for editing, if not base DN could have been detected. Also part of fix for #6670 --- apps/user_ldap/js/settings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js index acf88ef58a4..792638f2b58 100644 --- a/apps/user_ldap/js/settings.js +++ b/apps/user_ldap/js/settings.js @@ -240,6 +240,7 @@ var LdapWizard = { LdapWizard.hideSpinner('#ldap_base'); LdapWizard.showInfoBox('Please specify a Base DN'); LdapWizard.showInfoBox('Could not determine Base DN'); + $('#ldap_base').prop('disabled', false); } ); } From e156f85bfb7ea1b6d74227a49507e1a3b0e0e374 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 10:33:44 +0100 Subject: [PATCH 52/74] Rephrase and clarify log message --- apps/user_ldap/lib/access.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 72f9c740921..b619f62f296 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -729,7 +729,7 @@ class Access extends LDAPUtility { } } else { if(!is_null($limit)) { - \OCP\Util::writeLog('user_ldap', 'Paged search failed :(', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', 'Paged search was not available', \OCP\Util::INFO); } } } From 299d37154b749855915c8dbc7ab8a123c4aa27f2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 7 Feb 2014 15:55:35 +0100 Subject: [PATCH 53/74] LDAP: add documentation info in info.xml --- apps/user_ldap/appinfo/info.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/user_ldap/appinfo/info.xml b/apps/user_ldap/appinfo/info.xml index 148a72cecbb..9cc908e8522 100644 --- a/apps/user_ldap/appinfo/info.xml +++ b/apps/user_ldap/appinfo/info.xml @@ -14,4 +14,7 @@ + + http://doc.owncloud.org/server/6.0/go.php?to=admin-ldap + From 18e1a10e96a341e3333d0d8453dd270e62192b4d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 6 Feb 2014 22:18:38 +0100 Subject: [PATCH 54/74] LDAP: also try MS AD's thumbnailPhoto when looking for an avatar image --- apps/user_ldap/user_ldap.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index a19af86086c..8b6521010f1 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -85,15 +85,14 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface { return; } - $jpegPhoto = $this->access->readAttribute($dn, 'jpegPhoto'); - \OCP\Config::setUserValue($uid, 'user_ldap', 'lastJpegPhotoLookup', time()); - if(!$jpegPhoto || !is_array($jpegPhoto) || !isset($jpegPhoto[0])) { + $avatarImage = $this->getAvatarImage($uid, $dn); + if($avatarImage === false) { //not set, nothing left to do; return; } $image = new \OCP\Image(); - $image->loadFromBase64(base64_encode($jpegPhoto[0])); + $image->loadFromBase64(base64_encode($avatarImage)); if(!$image->valid()) { \OCP\Util::writeLog('user_ldap', 'jpegPhoto data invalid for '.$dn, @@ -128,8 +127,7 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface { if(!$dn) { return false; } - $jpegPhoto = $this->access->readAttribute($dn, 'jpegPhoto'); - if(!$jpegPhoto || !is_array($jpegPhoto) || !isset($jpegPhoto[0])) { + if($this->getAvatarImage($uid, $dn) === false) { //The user is allowed to change his avatar in ownCloud only if no //avatar is provided by LDAP return true; @@ -137,6 +135,26 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface { return false; } + /** + * @brief reads the image from LDAP that shall be used as Avatar + * @param $uid string, the ownCloud user name + * @param $dn string, the user DN + * @return image data (provided by LDAP) | false + */ + private function getAvatarImage($uid, $dn) { + $attributes = array('jpegPhoto', 'thumbnailPhoto'); + foreach($attributes as $attribute) { + $result = $this->access->readAttribute($dn, $attribute); + \OCP\Config::setUserValue($uid, 'user_ldap', 'lastJpegPhotoLookup', + time()); + if($result !== false && is_array($result) && isset($result[0])) { + return $result[0]; + } + } + + return false; + } + /** * @brief Check if the password is correct * @param $uid The username From 14d1abf63f88943d376b29e31ac04265456db2a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 7 Feb 2014 08:42:38 +0100 Subject: [PATCH 55/74] LDAP: improve debug message --- apps/user_ldap/user_ldap.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 8b6521010f1..619a992bd12 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -256,7 +256,8 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface { } //check if user really still exists by reading its entry if(!is_array($this->access->readAttribute($dn, ''))) { - \OCP\Util::writeLog('user_ldap', 'LDAP says no user '.$dn, \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', 'LDAP says no user '.$dn.' on '. + $this->access->connection->ldapHost, \OCP\Util::DEBUG); $this->access->connection->writeToCache('userExists'.$uid, false); return false; } From 71e4d965a1d468ac01b404f233397def3b580ab2 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 13:26:08 +0100 Subject: [PATCH 56/74] on filtering the share box users and groups whose name begins with the search term shall appear on top, fixes #6430 --- core/ajax/share.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/ajax/share.php b/core/ajax/share.php index 8b48effb458..784b2528f40 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -354,8 +354,32 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; } } + usort($shareWith, 'sortSearchFirst'); OC_JSON::success(array('data' => $shareWith)); } break; } } + + +/** + * User and Group names matching the search term at the beginning shall appear + * on top of the share dialog. + * Callback function for usort. http://php.net/usort + */ +function sortSearchFirst($a, $b) { + $enc = 'UTF-8'; + $nameA = mb_strtolower($a['label'], $enc); + $nameB = mb_strtolower($b['label'], $enc); + $term = mb_strtolower($_GET['search'], $enc); + $i = mb_strpos($nameA, $term, 0, 'UTF-8'); + $j = mb_strpos($nameB, $term, 0, 'UTF-8'); + + if($i === $j) { + return 0; + } else if ($i === 0) { + return -1; + } else { + return 1; + } +} From 1d0a2365631955944d746b4567cac85eb10a80db Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 14:02:18 +0100 Subject: [PATCH 57/74] respect coding guidelines --- core/ajax/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 784b2528f40..5c2dbc6654d 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -377,7 +377,7 @@ function sortSearchFirst($a, $b) { if($i === $j) { return 0; - } else if ($i === 0) { + } elseif ($i === 0) { return -1; } else { return 1; From 41e8d44cf7261e05a40842ab56d4d4c3f61cf083 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 17:55:05 +0100 Subject: [PATCH 58/74] move sorter into a class --- core/ajax/share.php | 27 ++---------- lib/private/share/searchresultsorter.php | 53 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 lib/private/share/searchresultsorter.php diff --git a/core/ajax/share.php b/core/ajax/share.php index 5c2dbc6654d..21e320a4732 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -354,32 +354,11 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo break; } } - usort($shareWith, 'sortSearchFirst'); + $sorter = new \OC\Share\SearchResultSorter($_GET['search'], + 'label'); + usort($shareWith, array($sorter, 'sort')); OC_JSON::success(array('data' => $shareWith)); } break; } } - - -/** - * User and Group names matching the search term at the beginning shall appear - * on top of the share dialog. - * Callback function for usort. http://php.net/usort - */ -function sortSearchFirst($a, $b) { - $enc = 'UTF-8'; - $nameA = mb_strtolower($a['label'], $enc); - $nameB = mb_strtolower($b['label'], $enc); - $term = mb_strtolower($_GET['search'], $enc); - $i = mb_strpos($nameA, $term, 0, 'UTF-8'); - $j = mb_strpos($nameB, $term, 0, 'UTF-8'); - - if($i === $j) { - return 0; - } elseif ($i === 0) { - return -1; - } else { - return 1; - } -} diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php new file mode 100644 index 00000000000..27f94a694ac --- /dev/null +++ b/lib/private/share/searchresultsorter.php @@ -0,0 +1,53 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ +namespace OC\Share; + +class SearchResultSorter { + private $search; + private $encoding; + private $key; + + /** + * @param $search the search term as was given by the user + * @param $key the array key containing the value that should be compared + * against + * @param $encoding optional, encoding to use, defaults to UTF-8 + */ + public function __construct($search, $key, $encoding = 'UTF-8') { + $this->encoding = $encoding; + $this->key = $key; + $this->search = mb_strtolower($search, $this->encoding); + } + + /** + * User and Group names matching the search term at the beginning shall appear + * on top of the share dialog. + * Callback function for usort. http://php.net/usort + */ + public function sort($a, $b) { + if(!isset($a[$this->key]) || !isset($b[$this->key])) { + \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'. + 'array key', \OC_Log::ERROR); + return 0; + } + $nameA = mb_strtolower($a[$this->key], $this->encoding); + $nameB = mb_strtolower($b[$this->key], $this->encoding); + $i = mb_strpos($nameA, $this->search, 0, $this->encoding); + $j = mb_strpos($nameB, $this->search, 0, $this->encoding); + + if($i === $j) { + return 0; + } elseif ($i === 0) { + return -1; + } else { + return 1; + } + } +} + From 82716ced48c256ef5e2f8ca9b7a4e3ab20e146cd Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 18:19:20 +0100 Subject: [PATCH 59/74] sort following entries in alphabetical order --- lib/private/share/searchresultsorter.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index 27f94a694ac..f64a4766ade 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -27,7 +27,7 @@ class SearchResultSorter { /** * User and Group names matching the search term at the beginning shall appear - * on top of the share dialog. + * on top of the share dialog. Following entries in alphabetical order. * Callback function for usort. http://php.net/usort */ public function sort($a, $b) { @@ -41,8 +41,9 @@ class SearchResultSorter { $i = mb_strpos($nameA, $this->search, 0, $this->encoding); $j = mb_strpos($nameB, $this->search, 0, $this->encoding); - if($i === $j) { - return 0; + if($i === $j || $i > 0 && $j > 0) { + return strcmp(mb_strtolower($nameA, $this->encoding), + mb_strtolower($nameB, $this->encoding)); } elseif ($i === 0) { return -1; } else { From 9a39cd3b38837421a5ac476a78207402e4c6c91c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 18:26:06 +0100 Subject: [PATCH 60/74] test for share dialoge sorter --- tests/lib/share/searchresultsorter.php | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/lib/share/searchresultsorter.php diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php new file mode 100644 index 00000000000..f24e40ea059 --- /dev/null +++ b/tests/lib/share/searchresultsorter.php @@ -0,0 +1,40 @@ + +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see . +*/ + +class Test_Share_Search extends \PHPUnit_Framework_TestCase { + public function testSort() { + $search = 'lin'; + $sorter = new \OC\Share\SearchResultSorter($search, 'foobar'); + + $result = array( + array('foobar' => 'woot'), + array('foobar' => 'linux'), + array('foobar' => 'Linus'), + array('foobar' => 'Bicyclerepairwoman'), + ); + + usort($result, array($sorter, 'sort')); + $this->assertTrue($result[0]['foobar'] === 'Linus'); + $this->assertTrue($result[1]['foobar'] === 'linux'); + $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman'); + $this->assertTrue($result[3]['foobar'] === 'woot'); + } +} From 20bfbb0fd9316be0cbba9c2202a9b45ce7eea7f8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jan 2014 10:30:18 +0100 Subject: [PATCH 61/74] wrong tld --- lib/private/share/searchresultsorter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index f64a4766ade..4f8799494f5 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -1,6 +1,6 @@ + * Copyright (c) 2014 Arthur Schiwon * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. From 32afdcbefec5793fb28162c456919d2b0be5cfe9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jan 2014 11:00:22 +0100 Subject: [PATCH 62/74] Inject logger --- lib/private/share/searchresultsorter.php | 9 ++++++--- tests/lib/share/searchresultsorter.php | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index 4f8799494f5..f81a94c749d 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -12,16 +12,19 @@ class SearchResultSorter { private $search; private $encoding; private $key; + private $log; /** * @param $search the search term as was given by the user * @param $key the array key containing the value that should be compared * against * @param $encoding optional, encoding to use, defaults to UTF-8 + * @param $log optional, an \OC\Log instance */ - public function __construct($search, $key, $encoding = 'UTF-8') { + public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) { $this->encoding = $encoding; $this->key = $key; + $this->log = is_null($log) ? new \OC\Log() : $log; $this->search = mb_strtolower($search, $this->encoding); } @@ -32,8 +35,8 @@ class SearchResultSorter { */ public function sort($a, $b) { if(!isset($a[$this->key]) || !isset($b[$this->key])) { - \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'. - 'array key', \OC_Log::ERROR); + $this->log->error('Sharing dialogue: cannot sort due to missing array key', + array('app' => 'core')); return 0; } $nameA = mb_strtolower($a[$this->key], $this->encoding); diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php index f24e40ea059..efc3e1b7aa3 100644 --- a/tests/lib/share/searchresultsorter.php +++ b/tests/lib/share/searchresultsorter.php @@ -37,4 +37,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase { $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman'); $this->assertTrue($result[3]['foobar'] === 'woot'); } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testSortWrongLog() { + $sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar'); + } } From af781bdea7509c3ecd9a7b4902fb7a266dc62c80 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 17:05:56 +0100 Subject: [PATCH 63/74] fix DI --- core/ajax/share.php | 3 ++- lib/private/share/searchresultsorter.php | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/ajax/share.php b/core/ajax/share.php index 21e320a4732..c251f8e7bae 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -355,7 +355,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo } } $sorter = new \OC\Share\SearchResultSorter($_GET['search'], - 'label'); + 'label', + new \OC\Log()); usort($shareWith, array($sorter, 'sort')); OC_JSON::success(array('data' => $shareWith)); } diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index f81a94c749d..fbf77179097 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -21,10 +21,10 @@ class SearchResultSorter { * @param $encoding optional, encoding to use, defaults to UTF-8 * @param $log optional, an \OC\Log instance */ - public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) { + public function __construct($search, $key, \OC\Log $log = null, $encoding = 'UTF-8') { $this->encoding = $encoding; $this->key = $key; - $this->log = is_null($log) ? new \OC\Log() : $log; + $this->log = $log; $this->search = mb_strtolower($search, $this->encoding); } @@ -35,8 +35,10 @@ class SearchResultSorter { */ public function sort($a, $b) { if(!isset($a[$this->key]) || !isset($b[$this->key])) { - $this->log->error('Sharing dialogue: cannot sort due to missing array key', - array('app' => 'core')); + if(!is_null($this->log)) { + $this->log->error('Sharing dialogue: cannot sort due to ' . + 'missing array key', array('app' => 'core')); + } return 0; } $nameA = mb_strtolower($a[$this->key], $this->encoding); From 72f134cfce05eb089a6d8271e73d6eb95cbe94a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 17:12:17 +0100 Subject: [PATCH 64/74] intendation --- tests/lib/share/searchresultsorter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php index efc3e1b7aa3..eaf93400a7d 100644 --- a/tests/lib/share/searchresultsorter.php +++ b/tests/lib/share/searchresultsorter.php @@ -25,11 +25,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase { $sorter = new \OC\Share\SearchResultSorter($search, 'foobar'); $result = array( - array('foobar' => 'woot'), - array('foobar' => 'linux'), - array('foobar' => 'Linus'), - array('foobar' => 'Bicyclerepairwoman'), - ); + array('foobar' => 'woot'), + array('foobar' => 'linux'), + array('foobar' => 'Linus'), + array('foobar' => 'Bicyclerepairwoman'), + ); usort($result, array($sorter, 'sort')); $this->assertTrue($result[0]['foobar'] === 'Linus'); From 50cc6a85e5d4c817235aee58e9d461e4034df27b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 11 Feb 2014 14:26:40 +0100 Subject: [PATCH 65/74] Add explicit sorting --- lib/private/appconfig.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index 71aa8307316..a47e1ad49e6 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -92,7 +92,7 @@ class AppConfig implements \OCP\IAppConfig { * entry in the appconfig table. */ public function getApps() { - $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'; + $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig` ORDER BY `appid`'; $result = $this->conn->executeQuery($query); $apps = array(); @@ -112,7 +112,9 @@ class AppConfig implements \OCP\IAppConfig { */ public function getKeys($app) { $values = $this->getAppValues($app); - return array_keys($values); + $keys = array_keys($values); + sort($keys); + return $keys; } /** From 9619459e37dce3723eb912e1ea9f149dc3f5de49 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Feb 2014 11:43:34 +0100 Subject: [PATCH 66/74] Send correct path on file upload when using public app Fix issue #7152 --- apps/files/ajax/upload.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 754c34ef088..145f40c50da 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -22,6 +22,7 @@ if (empty($_POST['dirToken'])) { } else { // return only read permissions for public upload $allowedPermissions = OCP\PERMISSION_READ; + $public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/'; $linkItem = OCP\Share::getShareByToken($_POST['dirToken']); if ($linkItem === false) { @@ -45,7 +46,7 @@ if (empty($_POST['dirToken'])) { $dir = sprintf( "/%s/%s", $path, - isset($_POST['subdir']) ? $_POST['subdir'] : '' + $public_directory ); if (!$dir || empty($dir) || $dir === false) { @@ -112,7 +113,14 @@ if (strpos($dir, '..') === false) { } else { $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]); } - + + $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir)); + if (isset($public_directory)) { + // If we are uploading from the public app, + // we want to send the relative path in the ajax request. + $directory = $public_directory; + } + if ( ! \OC\Files\Filesystem::file_exists($target) || (isset($_POST['resolution']) && $_POST['resolution']==='replace') ) { @@ -140,7 +148,7 @@ if (strpos($dir, '..') === false) { 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, 'permissions' => $meta['permissions'] & $allowedPermissions, - 'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)), + 'directory' => $directory, ); } @@ -168,7 +176,7 @@ if (strpos($dir, '..') === false) { 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, 'permissions' => $meta['permissions'] & $allowedPermissions, - 'directory' => \OC\Files\Filesystem::normalizePath(stripslashes($dir)), + 'directory' => $directory, ); } } From 658af627ce3add85282a73fa711f28745041694d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Feb 2014 18:18:09 +0100 Subject: [PATCH 67/74] External FTP Storage should request hostname instead of URL Fix issue #6277 --- apps/files_external/lib/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 48fc4dfe46e..8c85c5fbde8 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -69,7 +69,7 @@ class OC_Mount_Config { if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array( 'backend' => 'FTP', 'configuration' => array( - 'host' => 'URL', + 'host' => 'Hostname', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', From 6e17d71a0df5d36253afa26d84e89dcf3331c6c5 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Thu, 13 Feb 2014 10:39:38 +0100 Subject: [PATCH 68/74] remove forced lowercase from extension, fix #4747, also coding style fixes --- apps/files/css/files.css | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 5526abaf6e2..27fa75ebc59 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -84,9 +84,26 @@ background-color: rgb(240,240,240); } tbody a { color:#000; } -span.extension, span.uploading, td.date { color:#999; } -span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70); opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; } -tr:hover span.extension { -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; filter:alpha(opacity=100); opacity:1; color:#777; } + +span.extension, span.uploading, td.date { + color: #999; +} +span.extension { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; + filter: alpha(opacity=70); + opacity: .7; + -webkit-transition: opacity 300ms; + -moz-transition: opacity 300ms; + -o-transition: opacity 300ms; + transition: opacity 300ms; +} +tr:hover span.extension { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); + opacity: 1; + color: #777; +} + table tr.mouseOver td { background-color:#eee; } table th { height:24px; padding:0 8px; color:#999; } table th .name { From 3b1df2931818b90b734c8bc3a6e0dbdf1517feaf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 13 Feb 2014 13:56:02 +0100 Subject: [PATCH 69/74] sort expected result in tests --- tests/lib/appconfig.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 5cbdf80502f..6ae790a9edd 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -42,6 +42,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while ($row = $result->fetchRow()) { $expected[] = $row['appid']; } + sort($expected); $apps = \OC_Appconfig::getApps(); $this->assertEquals($expected, $apps); } @@ -53,6 +54,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while($row = $result->fetchRow()) { $expected[] = $row["configkey"]; } + sort($expected); $keys = \OC_Appconfig::getKeys('testapp'); $this->assertEquals($expected, $keys); } From f62f1658ceba6ad02ada0823243d779a698f5f7f Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 14 Feb 2014 11:23:39 +0100 Subject: [PATCH 70/74] suppress error msg caused by php bug --- lib/private/preview/office.php | 2 +- lib/private/preview/pdf.php | 2 +- lib/private/preview/svg.php | 2 +- lib/private/preview/unknown.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 884b6e7dc9b..02bb22e9b94 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ //both, libreoffice backend and php fallback, need imagick -if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec'); // LibreOffice preview is currently not supported on Windows diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php index 572b8788ac9..d390b4fc677 100644 --- a/lib/private/preview/pdf.php +++ b/lib/private/preview/pdf.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { class PDF extends Provider { diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php index 07a37e8f8c1..9a73fff9467 100644 --- a/lib/private/preview/svg.php +++ b/lib/private/preview/svg.php @@ -7,7 +7,7 @@ */ namespace OC\Preview; -if (extension_loaded('imagick') && count(\Imagick::queryFormats("SVG")) === 1) { +if (extension_loaded('imagick') && count(@\Imagick::queryFormats("SVG")) === 1) { class SVG extends Provider { diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 8145c826149..2d3b5c5655e 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -22,7 +22,7 @@ class Unknown extends Provider { $svgPath = substr_replace($path, 'svg', -3); - if (extension_loaded('imagick') && file_exists($svgPath) && count(\Imagick::queryFormats("SVG")) === 1) { + if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) { // http://www.php.net/manual/de/imagick.setresolution.php#85284 $svg = new \Imagick(); From 0ba0596341779100db37e25e59ac34f5a57bd2c3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 14:25:45 +0100 Subject: [PATCH 71/74] remove duplicate call to groupExists --- lib/private/group/manager.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index bf469d51d12..29453c5da14 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -76,12 +76,7 @@ class Manager extends PublicEmitter { if (isset($this->cachedGroups[$gid])) { return $this->cachedGroups[$gid]; } - foreach ($this->backends as $backend) { - if ($backend->groupExists($gid)) { - return $this->getGroupObject($gid); - } - } - return null; + return $this->getGroupObject($gid); } protected function getGroupObject($gid) { @@ -91,6 +86,9 @@ class Manager extends PublicEmitter { $backends[] = $backend; } } + if (count($backends) === 0) { + return null; + } $this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this); return $this->cachedGroups[$gid]; } From b35f679483f2b8f1dab56b903ca2e942ac4606ff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 15:07:08 +0100 Subject: [PATCH 72/74] Fix test cases for group manager --- lib/private/group/manager.php | 4 ++-- tests/lib/group/manager.php | 37 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 29453c5da14..9b433b64fd4 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -108,8 +108,8 @@ class Manager extends PublicEmitter { public function createGroup($gid) { if (!$gid) { return false; - } else if ($this->groupExists($gid)) { - return $this->get($gid); + } else if ($group = $this->get($gid)) { + return $group; } else { $this->emit('\OC\Group', 'preCreate', array($gid)); foreach ($this->backends as $backend) { diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index 9d3adf51a0c..90f0e1b35e2 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend */ + $backendGroupCreated = false; $backend = $this->getMock('\OC_Group_Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') - ->will($this->returnValue(false)); + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + return $backendGroupCreated; + })); $backend->expects($this->once()) ->method('implementsActions') ->will($this->returnValue(true)); $backend->expects($this->once()) - ->method('createGroup'); + ->method('createGroup') + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + $backendGroupCreated = true; + }));; /** * @var \OC\User\Manager $userManager @@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->once()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group12', 'group1'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 2, 1) ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 1, 0) ->will($this->returnValue(array('group12'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 */ @@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1', 'group2'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager From 29336683555b9ce8e4c365d6d0b02a135815b5f2 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 14 Feb 2014 18:05:59 +0100 Subject: [PATCH 73/74] fileinfo is no longer a array --- apps/files_encryption/tests/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index 44525791743..7d926caea1b 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -203,7 +203,7 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase { $fileInfo = $this->user1View->getFileInfo($this->filename); // check if we have a valid file info - $this->assertTrue(is_array($fileInfo)); + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); // share the file with user2 \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2, OCP\PERMISSION_ALL); From 09502fcb368c6b18a936b0b0aeb0e685829ad570 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 19:24:12 +0100 Subject: [PATCH 74/74] remove the JsonSerializable interface from \OC\Files\FileInfo --- lib/private/files/fileinfo.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php index 7edea13df96..c77571cd2a7 100644 --- a/lib/private/files/fileinfo.php +++ b/lib/private/files/fileinfo.php @@ -8,7 +8,7 @@ namespace OC\Files; -class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { +class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { /** * @var array $data */ @@ -52,10 +52,6 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable { return $this->data[$offset]; } - public function jsonSerialize() { - return $this->data; - } - /** * @return string */