From 7a0c592f935268b515e6b16b4119a5088ebfd064 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 21 May 2013 20:21:19 -0400 Subject: Fix undefined index for share mount point retrieval --- lib/public/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index a561319e9bd..f9d3d810200 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -877,7 +877,7 @@ class Share { if (!isset($mounts[$row['storage']])) { $mountPoints = \OC\Files\Filesystem::getMountByNumericId($row['storage']); if (is_array($mountPoints)) { - $mounts[$row['storage']] = $mountPoints[key($mountPoints)]; + $mounts[$row['storage']] = current($mountPoints); } } if ($mounts[$row['storage']]) { -- cgit v1.2.3 From b44192f3668ae2e8e9685479fa62a78cfc5500ba Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 13:10:26 +0200 Subject: check list of users with access to the file from the bottom to the top. This way we avoid calling getFileInfo() on every dir, which creates a lot of overhead, especially for external storages --- apps/files_encryption/lib/util.php | 4 ++-- lib/public/share.php | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'lib/public/share.php') diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 2452f4c6ae3..0ff76e60580 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1028,7 +1028,7 @@ class Util { if ($sharingEnabled) { // Find out who, if anyone, is sharing the file - $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, true, true, true); + $result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, true); $userIds = $result['users']; if ($result['public']) { $userIds[] = $this->publicShareKeyId; @@ -1457,7 +1457,7 @@ class Util { // Find out who, if anyone, is sharing the file if ($sharingEnabled) { - $result = \OCP\Share::getUsersSharingFile($file, $this->userId, true, true, true); + $result = \OCP\Share::getUsersSharingFile($file, $this->userId, true); $userIds = $result['users']; $userIds[] = $this->recoveryKeyId; if ($result['public']) { diff --git a/lib/public/share.php b/lib/public/share.php index 03d662676c6..58e6131af58 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -133,17 +133,16 @@ class Share { * @note $path needs to be relative to user data dir, e.g. 'file.txt' * not '/admin/data/file.txt' */ - public static function getUsersSharingFile($path, $user, $includeOwner = false, $removeDuplicates = true) { + public static function getUsersSharingFile($path, $user, $includeOwner = false) { - $path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR)); - $path = ''; $shares = array(); $publicShare = false; $view = new \OC\Files\View('/' . $user . '/files/'); - foreach ($path_parts as $p) { - $path .= '/' . $p; - $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); - $source = $meta['fileid']; + $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); + $source = $meta['fileid']; + $cache = new \OC\Files\Cache\Cache($meta['storage']); + + while ($path !== 'files') { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( @@ -203,6 +202,13 @@ class Share { if ($result->fetchRow()) { $publicShare = true; } + + // let's get the parent for the next round + $meta = $cache->get((int)$source); + $parent = $meta['parent']; + $parentMeta = $cache->get((int)$parent); + $path = $parentMeta['path']; + $source = $parent; } // Include owner in list of users, if requested if ($includeOwner) { -- cgit v1.2.3 From 672811c103a352ecb4bc33c2071b9b4493398b30 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 13:12:30 +0200 Subject: if one public link share was found, we don't have to check it for the other folders --- lib/public/share.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 58e6131af58..558efb49c0b 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -185,24 +185,26 @@ class Share { } //check for public link shares - $query = \OC_DB::prepare( - 'SELECT share_with + if (!$publicShare) { + $query = \OC_DB::prepare( + 'SELECT share_with FROM `*PREFIX*share` WHERE item_source = ? AND share_type = ?' - ); + ); - $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); + $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); - if (\OC_DB::isError($result)) { - \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); - } + if (\OC_DB::isError($result)) { + \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); + } - if ($result->fetchRow()) { - $publicShare = true; + if ($result->fetchRow()) { + $publicShare = true; + } } - + // let's get the parent for the next round $meta = $cache->get((int)$source); $parent = $meta['parent']; -- cgit v1.2.3 From 893a1ed6f57966dcf5270837f121118c5e13c457 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 14:19:18 +0200 Subject: for external storages we never reach the path 'files', instead we need to leave the loop if no further parent exists --- lib/public/share.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 558efb49c0b..19f7b2a20a9 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -140,9 +140,10 @@ class Share { $view = new \OC\Files\View('/' . $user . '/files/'); $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); $source = $meta['fileid']; + $parent = $meta['parent']; $cache = new \OC\Files\Cache\Cache($meta['storage']); - while ($path !== 'files') { + while ($path !== 'files' && $parent !== '-1') { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( -- cgit v1.2.3 From 63a2bec6e53e0a7db70599334914625a72015f08 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 14:40:47 +0200 Subject: use public API for error handling; improved while condition --- lib/public/share.php | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 19f7b2a20a9..2b7bf59219f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -143,7 +143,7 @@ class Share { $parent = $meta['parent']; $cache = new \OC\Files\Cache\Cache($meta['storage']); - while ($path !== 'files' && $parent !== '-1') { + while ($parent !== '-1') { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( @@ -156,14 +156,13 @@ class Share { $result = $query->execute(array($source, self::SHARE_TYPE_USER)); - if (\OC_DB::isError($result)) { - \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); - } - - while ($row = $result->fetchRow()) { - $shares[] = $row['share_with']; + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); + } else { + while ($row = $result->fetchRow()) { + $shares[] = $row['share_with']; + } } - // We also need to take group shares into account $query = \OC_DB::prepare( @@ -176,13 +175,13 @@ class Share { $result = $query->execute(array($source, self::SHARE_TYPE_GROUP)); - if (\OC_DB::isError($result)) { - \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); - } - - while ($row = $result->fetchRow()) { - $usersInGroup = \OC_Group::usersInGroup($row['share_with']); - $shares = array_merge($shares, $usersInGroup); + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); + } else { + while ($row = $result->fetchRow()) { + $usersInGroup = \OC_Group::usersInGroup($row['share_with']); + $shares = array_merge($shares, $usersInGroup); + } } //check for public link shares @@ -197,20 +196,18 @@ class Share { $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); - if (\OC_DB::isError($result)) { - \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); - } - - if ($result->fetchRow()) { - $publicShare = true; + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR); + } else { + if ($result->fetchRow()) { + $publicShare = true; + } } } // let's get the parent for the next round $meta = $cache->get((int)$source); $parent = $meta['parent']; - $parentMeta = $cache->get((int)$parent); - $path = $parentMeta['path']; $source = $parent; } // Include owner in list of users, if requested -- cgit v1.2.3 From 8587f565d2a7f72ec0244e508370447810199bfe Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 15:14:15 +0200 Subject: remove unnecessary variable --- lib/public/share.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 2b7bf59219f..8508eb96e5e 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -207,8 +207,7 @@ class Share { // let's get the parent for the next round $meta = $cache->get((int)$source); - $parent = $meta['parent']; - $source = $parent; + $source = $meta['parent']; } // Include owner in list of users, if requested if ($includeOwner) { -- cgit v1.2.3 From ae0f37e9e20a540ed93b99814f4eb066bd26aa88 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Wed, 29 May 2013 15:37:27 +0200 Subject: fix indention --- lib/public/share.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 8508eb96e5e..f7ab92ef018 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -187,11 +187,11 @@ class Share { //check for public link shares if (!$publicShare) { $query = \OC_DB::prepare( - 'SELECT share_with - FROM - `*PREFIX*share` - WHERE - item_source = ? AND share_type = ?' + 'SELECT share_with + FROM + `*PREFIX*share` + WHERE + item_source = ? AND share_type = ?' ); $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); -- cgit v1.2.3 From c8d1cd224ddb7cd3c554d0a601e1215968817be4 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 29 May 2013 19:58:05 +0200 Subject: fix $parent/$source typo --- lib/public/share.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index f7ab92ef018..bc0e3f15c53 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -140,10 +140,9 @@ class Share { $view = new \OC\Files\View('/' . $user . '/files/'); $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); $source = $meta['fileid']; - $parent = $meta['parent']; $cache = new \OC\Files\Cache\Cache($meta['storage']); - while ($parent !== '-1') { + while ($source !== '-1') { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( -- cgit v1.2.3 From 353d19d183b00132204de8a1798aa7f9d9caa4d9 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 29 May 2013 20:11:13 +0200 Subject: fixes if cache returns false --- lib/public/share.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index bc0e3f15c53..9a24192b4c8 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -123,25 +123,31 @@ class Share { return $path; } - + /** * @brief Find which users can access a shared item * @param $path to the file * @param $user owner of the file * @param include owner to the list of users with access to the file * @return array - * @note $path needs to be relative to user data dir, e.g. 'file.txt' + * @note $path needs to be relative to user data dir, e.g. 'file.txt' * not '/admin/data/file.txt' */ public static function getUsersSharingFile($path, $user, $includeOwner = false) { $shares = array(); $publicShare = false; + $source = '-1'; + $cache = false; + $view = new \OC\Files\View('/' . $user . '/files/'); $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); - $source = $meta['fileid']; - $cache = new \OC\Files\Cache\Cache($meta['storage']); - + + if($meta !== false) { + $source = $meta['fileid']; + $cache = new \OC\Files\Cache\Cache($meta['storage']); + } + while ($source !== '-1') { // Fetch all shares of this file path from DB @@ -206,7 +212,11 @@ class Share { // let's get the parent for the next round $meta = $cache->get((int)$source); - $source = $meta['parent']; + if($meta !== false) { + $source = $meta['parent']; + } else { + $source = '-1'; + } } // Include owner in list of users, if requested if ($includeOwner) { -- cgit v1.2.3 From f1b884aa5db1fe81eb97a9d9dcd1323c8a18bd4b Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 29 May 2013 20:15:04 +0200 Subject: changed deprecated class --- lib/public/share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 9a24192b4c8..1eb0faf0973 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -141,7 +141,7 @@ class Share { $cache = false; $view = new \OC\Files\View('/' . $user . '/files/'); - $meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path)); + $meta = $view->getFileInfo(\OC\Files\Filesystem::normalizePath($path)); if($meta !== false) { $source = $meta['fileid']; -- cgit v1.2.3 From 1337f48d64cd6ac99b28a0d6bfc20509ea9e6bff Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Wed, 29 May 2013 20:41:07 +0200 Subject: fixes for pgsql --- lib/public/share.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 1eb0faf0973..6c93139b107 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -137,7 +137,7 @@ class Share { $shares = array(); $publicShare = false; - $source = '-1'; + $source = -1; $cache = false; $view = new \OC\Files\View('/' . $user . '/files/'); @@ -148,7 +148,7 @@ class Share { $cache = new \OC\Files\Cache\Cache($meta['storage']); } - while ($source !== '-1') { + while ($source !== -1) { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( @@ -213,9 +213,9 @@ class Share { // let's get the parent for the next round $meta = $cache->get((int)$source); if($meta !== false) { - $source = $meta['parent']; + $source = (int)$meta['parent']; } else { - $source = '-1'; + $source = -1; } } // Include owner in list of users, if requested -- cgit v1.2.3 From 124f34422c3b488869e0348c97d87aa0a69a3fe9 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 10 Jun 2013 09:53:29 +0200 Subject: add missing backticks all over the place --- apps/files_encryption/lib/util.php | 8 ++++---- lib/files/cache/backgroundwatcher.php | 4 ++-- lib/files/cache/cache.php | 6 +++--- lib/public/share.php | 12 ++++++------ tests/lib/db.php | 22 +++++++++++----------- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'lib/public/share.php') diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 04bd4dc8aca..a6711880c20 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -289,7 +289,7 @@ class Util { */ public function recoveryEnabledForUser() { - $sql = 'SELECT `recovery_enabled` FROM `*PREFIX*encryption` WHERE uid = ?'; + $sql = 'SELECT `recovery_enabled` FROM `*PREFIX*encryption` WHERE `uid` = ?'; $args = array($this->userId); @@ -347,7 +347,7 @@ class Util { // Create a new record instead } else { - $sql = 'UPDATE `*PREFIX*encryption` SET recovery_enabled = ? WHERE uid = ?'; + $sql = 'UPDATE `*PREFIX*encryption` SET `recovery_enabled` = ? WHERE `uid` = ?'; $args = array( $enabled, @@ -1060,7 +1060,7 @@ class Util { */ public function setMigrationStatus($status) { - $sql = 'UPDATE `*PREFIX*encryption` SET migration_status = ? WHERE uid = ?'; + $sql = 'UPDATE `*PREFIX*encryption` SET `migration_status` = ? WHERE `uid` = ?'; $args = array( $status, @@ -1089,7 +1089,7 @@ class Util { */ public function getMigrationStatus() { - $sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE uid = ?'; + $sql = 'SELECT `migration_status` FROM `*PREFIX*encryption` WHERE `uid` = ?'; $args = array($this->userId); diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php index 8933101577d..8e68f41cf44 100644 --- a/lib/files/cache/backgroundwatcher.php +++ b/lib/files/cache/backgroundwatcher.php @@ -59,9 +59,9 @@ class BackgroundWatcher { */ static private function getNextFileId($previous, $folder) { if ($folder) { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype = ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` = ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); } else { - $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype != ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); + $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` != ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1); } $result = $query->execute(array($previous)); if ($row = $result->fetchRow()) { diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index cae2e63e4dc..6c2ef71098b 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -241,7 +241,7 @@ class Cache { $params[] = $id; $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?' - . ' WHERE fileid = ?'); + . ' WHERE `fileid` = ?'); $query->execute($params); } @@ -385,10 +385,10 @@ class Cache { * remove all entries for files that are stored on the storage from the cache */ public function clear() { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?'); + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?'); $query->execute(array($this->getNumericStorageId())); - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?'); + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE `id` = ?'); $query->execute(array($this->storageId)); } diff --git a/lib/public/share.php b/lib/public/share.php index 81f5515bb4b..6a26101a1ce 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -152,11 +152,11 @@ class Share { // Fetch all shares of this file path from DB $query = \OC_DB::prepare( - 'SELECT share_with + 'SELECT `share_with` FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ?' + `item_source` = ? AND `share_type` = ?' ); $result = $query->execute(array($source, self::SHARE_TYPE_USER)); @@ -171,11 +171,11 @@ class Share { // We also need to take group shares into account $query = \OC_DB::prepare( - 'SELECT share_with + 'SELECT `share_with` FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ?' + `item_source` = ? AND `share_type` = ?' ); $result = $query->execute(array($source, self::SHARE_TYPE_GROUP)); @@ -192,11 +192,11 @@ class Share { //check for public link shares if (!$publicShare) { $query = \OC_DB::prepare( - 'SELECT share_with + 'SELECT `share_with` FROM `*PREFIX*share` WHERE - item_source = ? AND share_type = ?' + `item_source` = ? AND `share_type` = ?' ); $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); diff --git a/tests/lib/db.php b/tests/lib/db.php index 440f3fb6bfd..eff01bd9065 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -33,15 +33,15 @@ class Test_DB extends PHPUnit_Framework_TestCase { } public function testQuotes() { - $query = OC_DB::prepare('SELECT `fullname` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); $row = $result->fetchRow(); $this->assertFalse($row); - $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (?,?)'); + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); $this->assertTrue((bool)$result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); $row = $result->fetchRow(); @@ -52,19 +52,19 @@ class Test_DB extends PHPUnit_Framework_TestCase { } public function testNOW() { - $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (NOW(),?)'); + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (NOW(),?)'); $result = $query->execute(array('uri_2')); $this->assertTrue((bool)$result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_2')); $this->assertTrue((bool)$result); } public function testUNIX_TIMESTAMP() { - $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)'); + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)'); $result = $query->execute(array('uri_3')); $this->assertTrue((bool)$result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_3')); $this->assertTrue((bool)$result); } @@ -88,7 +88,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertTrue((bool)$result); } - $query = OC_DB::prepare('SELECT * FROM *PREFIX*'.$this->table3); + $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); $result = $query->execute(); $this->assertTrue((bool)$result); $this->assertEquals('4', $result->numRows()); @@ -100,10 +100,10 @@ class Test_DB extends PHPUnit_Framework_TestCase { $carddata = 'This is a vCard'; // Normal test to have same known data inserted. - $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)'); + $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)'); $result = $query->execute(array($fullname, $uri, $carddata)); $this->assertTrue((bool)$result); - $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array($uri)); $this->assertTrue((bool)$result); $row = $result->fetchRow(); @@ -119,7 +119,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { )); $this->assertTrue((bool)$result); - $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array($uri)); $this->assertTrue((bool)$result); $row = $result->fetchRow(); -- cgit v1.2.3 From 961a001af3bc69eec8770ddc00ace3553e5c6ee0 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 14 Jun 2013 12:18:20 +0200 Subject: add missing backticks, use executeAudited in post_deleteGroup and post_removeFromGroup --- lib/public/share.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/public/share.php') diff --git a/lib/public/share.php b/lib/public/share.php index 6a26101a1ce..122ab3fa030 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1586,10 +1586,10 @@ class Share { public static function post_removeFromGroup($arguments) { // TODO Don't call if user deleted? - $query = \OC_DB::prepare('SELECT `id`, `share_type` FROM `*PREFIX*share`' - .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)'); - $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'], self::$shareTypeGroupUserUnique, - $arguments['uid'])); + $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`' + .' WHERE (`share_type` = ? AND `share_with` = ?) OR (`share_type` = ? AND `share_with` = ?)'; + $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'], + self::$shareTypeGroupUserUnique, $arguments['uid'])); while ($item = $result->fetchRow()) { if ($item['share_type'] == self::SHARE_TYPE_GROUP) { // Delete all reshares by this user of the group share @@ -1601,8 +1601,8 @@ class Share { } public static function post_deleteGroup($arguments) { - $query = \OC_DB::prepare('SELECT id FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); - $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid'])); + $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'; + $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'])); while ($item = $result->fetchRow()) { self::delete($item['id']); } -- cgit v1.2.3