summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoricewind1991 <icewind1991@gmail.com>2013-02-28 10:24:20 -0800
committericewind1991 <icewind1991@gmail.com>2013-02-28 10:24:20 -0800
commita86761e1e720af148da6cbc3fd641da6b57fab5b (patch)
tree777f5a399f22bfc368a06653880c4fe652f1fec4
parent1cc7e6d31a0ed8a590543cfb44cf1f31799d3dde (diff)
parentee1eb98d4aadf980297ae81017e213d7c22e1c25 (diff)
downloadnextcloud-server-a86761e1e720af148da6cbc3fd641da6b57fab5b.tar.gz
nextcloud-server-a86761e1e720af148da6cbc3fd641da6b57fab5b.zip
Merge pull request #1988 from owncloud/permissionscache_clean
Clean permissions cache when deleting file
-rw-r--r--lib/files/cache/cache.php3
-rw-r--r--lib/files/cache/permissions.php25
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 01e6e788263..f288919df74 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -313,6 +313,9 @@ class Cache {
}
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?');
$query->execute(array($entry['fileid']));
+
+ $permissionsCache = new Permissions($this->storageId);
+ $permissionsCache->remove($entry['fileid']);
}
/**
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index e1735831b94..a5c9c144054 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -17,10 +17,10 @@ class Permissions {
/**
* @param \OC\Files\Storage\Storage|string $storage
*/
- public function __construct($storage){
- if($storage instanceof \OC\Files\Storage\Storage) {
+ public function __construct($storage) {
+ if ($storage instanceof \OC\Files\Storage\Storage) {
$this->storageId = $storage->getId();
- }else{
+ } else {
$this->storageId = $storage;
}
}
@@ -52,10 +52,10 @@ class Permissions {
public function set($fileId, $user, $permissions) {
if (self::get($fileId, $user) !== -1) {
$query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ?'
- .' WHERE `user` = ? AND `fileid` = ?');
+ . ' WHERE `user` = ? AND `fileid` = ?');
} else {
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`)'
- .' VALUES(?, ?,? )');
+ . ' VALUES(?, ?,? )');
}
$query->execute(array($permissions, $user, $fileId));
}
@@ -76,7 +76,7 @@ class Permissions {
$inPart = implode(', ', array_fill(0, count($fileIds), '?'));
$query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
- .' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
+ . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
$result = $query->execute($params);
$filePermissions = array();
while ($row = $result->fetchRow()) {
@@ -91,14 +91,19 @@ class Permissions {
* @param int $fileId
* @param string $user
*/
- public function remove($fileId, $user) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
- $query->execute(array($fileId, $user));
+ public function remove($fileId, $user = null) {
+ if (is_null($user)) {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?');
+ $query->execute(array($fileId));
+ } else {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
+ $query->execute(array($fileId, $user));
+ }
}
public function removeMultiple($fileIds, $user) {
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
- foreach($fileIds as $fileId){
+ foreach ($fileIds as $fileId) {
$query->execute(array($fileId, $user));
}
}