diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-11-15 00:57:30 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-11-15 00:57:30 +0100 |
commit | cbcd9ba84ada830d91a6f1d7bee0ac59762835ed (patch) | |
tree | b5c71d4d517f915d5c22979947796aba06021ce6 /lib/files/cache | |
parent | bf2ac9f113d41dc944f42d1516649a3a72e88a65 (diff) | |
download | nextcloud-server-cbcd9ba84ada830d91a6f1d7bee0ac59762835ed.tar.gz nextcloud-server-cbcd9ba84ada830d91a6f1d7bee0ac59762835ed.zip |
allow storage backends to implement custom permission management
Diffstat (limited to 'lib/files/cache')
-rw-r--r-- | lib/files/cache/permissions.php | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php index dd7233abc70..d0968337f02 100644 --- a/lib/files/cache/permissions.php +++ b/lib/files/cache/permissions.php @@ -10,13 +10,29 @@ namespace OC\Files\Cache; class Permissions { /** + * @var string $storageId + */ + private $storageId; + + /** + * @param \OC\Files\Storage\Storage|string $storage + */ + public function __construct($storage){ + if($storage instanceof \OC\Files\Storage\Storage){ + $this->storageId = $storage->getId(); + }else{ + $this->storageId = $storage; + } + } + + /** * get the permissions for a single file * * @param int $fileId * @param string $user * @return int (-1 if file no permissions set) */ - static public function get($fileId, $user) { + public function get($fileId, $user) { $query = \OC_DB::prepare('SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?'); $result = $query->execute(array($user, $fileId)); if ($row = $result->fetchRow()) { @@ -33,7 +49,7 @@ class Permissions { * @param string $user * @param int $permissions */ - static public function set($fileId, $user, $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` = ?'); } else { @@ -49,7 +65,7 @@ class Permissions { * @param string $user * @return int[] */ - static public function getMultiple($fileIds, $user) { + public function getMultiple($fileIds, $user) { if (count($fileIds) === 0) { return array(); } @@ -72,17 +88,15 @@ class Permissions { * @param int $fileId * @param string $user */ - static public function remove($fileId, $user) { + public function remove($fileId, $user) { $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?'); $query->execute(array($fileId, $user)); } - static public function removeMultiple($fileIds, $user) { - $params = $fileIds; - $params[] = $user; - $inPart = implode(', ', array_fill(0, count($fileIds), '?')); - - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` IN (' . $inPart . ') AND `user` = ?'); - $query->execute($params); + public function removeMultiple($fileIds, $user) { + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?'); + foreach($fileIds as $fileId){ + $query->execute(array($fileId, $user)); + } } } |