merge changes for files_encryption

This commit is contained in:
Florin Peter 2013-05-15 10:20:19 +02:00
parent 807740a07a
commit 751487ded7

View file

@ -133,83 +133,83 @@ 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, $removeDuplicates = true) {
$path_parts = explode(DIRECTORY_SEPARATOR, trim($path, DIRECTORY_SEPARATOR));
$path = '';
$shares = array();
$view = new \OC\Files\View('/'.$user.'/files/');
$publicShare = false;
$view = new \OC\Files\View('/' . $user . '/files/');
foreach ($path_parts as $p) {
$path .= '/'.$p;
$path .= '/' . $p;
$meta = $view->getFileInfo(\OC_Filesystem::normalizePath($path));
$source = $meta['fileid'];
// Fetch all shares of this file path from DB
$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_USER ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
$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() ) {
while ($row = $result->fetchRow()) {
$shares[] = $row['share_with'];
}
// We also need to take group shares into account
$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_GROUP ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
$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() ) {
while ($row = $result->fetchRow()) {
$usersInGroup = \OC_Group::usersInGroup($row['share_with']);
$shares = array_merge($shares, $usersInGroup);
}
//check for public link shares
$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 ) );
if ( \OC_DB::isError( $result ) ) {
\OC_Log::write( 'OCP\Share', \OC_DB::getErrorMessage($result), \OC_Log::ERROR );
$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()) {
$shares[] = "owncloud";
$publicShare = true;
}
}
// Include owner in list of users, if requested
if ( $includeOwner ) {
if ($includeOwner) {
$shares[] = $user;
}
return array_unique($shares);
return array("users" => array_unique($shares), "public" => $publicShare);
}
/**
@ -514,6 +514,7 @@ class Share {
'fileSource' => $item['file_source'],
'shareType' => $shareType,
'shareWith' => $shareWith,
'itemParent' => $item['parent'],
));
self::delete($item['id']);
\OC_Hook::emit('OCP\Share', 'post_unshare', array(
@ -521,6 +522,7 @@ class Share {
'itemSource' => $itemSource,
'shareType' => $shareType,
'shareWith' => $shareWith,
'itemParent' => $item['parent'],
));
return true;
}