Cache: add option to delete file from permissions cache for all users

This commit is contained in:
Robin Appelman 2013-02-28 17:04:34 +01:00
parent 93e713d378
commit f7a43391a7
1 changed files with 15 additions and 10 deletions

View File

@ -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));
}
}