|
|
|
@ -345,16 +345,9 @@ class Share { |
|
|
|
|
\OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR); |
|
|
|
|
} |
|
|
|
|
$row = $result->fetchRow(); |
|
|
|
|
|
|
|
|
|
if (!empty($row['expiration'])) { |
|
|
|
|
$now = new \DateTime(); |
|
|
|
|
$expirationDate = new \DateTime($row['expiration'], new \DateTimeZone('UTC')); |
|
|
|
|
if ($now > $expirationDate) { |
|
|
|
|
self::delete($row['id']); |
|
|
|
|
if (self::expireItem($row)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $row; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -634,23 +627,7 @@ class Share { |
|
|
|
|
public static function unshare($itemType, $itemSource, $shareType, $shareWith) { |
|
|
|
|
if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), |
|
|
|
|
self::FORMAT_NONE, null, 1)) { |
|
|
|
|
// Pass all the vars we have for now, they may be useful |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'pre_unshare', array( |
|
|
|
|
'itemType' => $itemType, |
|
|
|
|
'itemSource' => $itemSource, |
|
|
|
|
'fileSource' => $item['file_source'], |
|
|
|
|
'shareType' => $shareType, |
|
|
|
|
'shareWith' => $shareWith, |
|
|
|
|
'itemParent' => $item['parent'], |
|
|
|
|
)); |
|
|
|
|
self::delete($item['id']); |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'post_unshare', array( |
|
|
|
|
'itemType' => $itemType, |
|
|
|
|
'itemSource' => $itemSource, |
|
|
|
|
'shareType' => $shareType, |
|
|
|
|
'shareWith' => $shareWith, |
|
|
|
|
'itemParent' => $item['parent'], |
|
|
|
|
)); |
|
|
|
|
self::unshareItem($item); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
@ -665,19 +642,16 @@ class Share { |
|
|
|
|
public static function unshareAll($itemType, $itemSource) { |
|
|
|
|
if ($shares = self::getItemShared($itemType, $itemSource)) { |
|
|
|
|
// Pass all the vars we have for now, they may be useful |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'pre_unshareAll', array( |
|
|
|
|
$hookParams = array( |
|
|
|
|
'itemType' => $itemType, |
|
|
|
|
'itemSource' => $itemSource, |
|
|
|
|
'shares' => $shares |
|
|
|
|
)); |
|
|
|
|
'shares' => $shares, |
|
|
|
|
); |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'pre_unshareAll', $hookParams); |
|
|
|
|
foreach ($shares as $share) { |
|
|
|
|
self::delete($share['id']); |
|
|
|
|
self::unshareItem($share); |
|
|
|
|
} |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'post_unshareAll', array( |
|
|
|
|
'itemType' => $itemType, |
|
|
|
|
'itemSource' => $itemSource, |
|
|
|
|
'shares' => $shares |
|
|
|
|
)); |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'post_unshareAll', $hookParams); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
@ -852,6 +826,44 @@ class Share { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks whether a share has expired, calls unshareItem() if yes. |
|
|
|
|
* @param array $item Share data (usually database row) |
|
|
|
|
* @return bool True if item was expired, false otherwise. |
|
|
|
|
*/ |
|
|
|
|
protected static function expireItem(array $item) { |
|
|
|
|
if (!empty($item['expiration'])) { |
|
|
|
|
$now = new \DateTime(); |
|
|
|
|
$expirationDate = new \DateTime($item['expiration'], new \DateTimeZone('UTC')); |
|
|
|
|
if ($now > $expirationDate) { |
|
|
|
|
self::unshareItem($item); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unshares a share given a share data array |
|
|
|
|
* @param array $item Share data (usually database row) |
|
|
|
|
* @return null |
|
|
|
|
*/ |
|
|
|
|
protected static function unshareItem(array $item) { |
|
|
|
|
// Pass all the vars we have for now, they may be useful |
|
|
|
|
$hookParams = array( |
|
|
|
|
'itemType' => $item['item_type'], |
|
|
|
|
'itemSource' => $item['item_source'], |
|
|
|
|
'shareType' => $item['share_type'], |
|
|
|
|
'shareWith' => $item['share_with'], |
|
|
|
|
'itemParent' => $item['parent'], |
|
|
|
|
); |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams + array( |
|
|
|
|
'fileSource' => $item['file_source'], |
|
|
|
|
)); |
|
|
|
|
self::delete($item['id']); |
|
|
|
|
\OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the backend class for the specified item type |
|
|
|
|
* @param string $itemType |
|
|
|
@ -1079,7 +1091,7 @@ class Share { |
|
|
|
|
// TODO Optimize selects |
|
|
|
|
if ($format == self::FORMAT_STATUSES) { |
|
|
|
|
if ($itemType == 'file' || $itemType == 'folder') { |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' |
|
|
|
|
.' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; |
|
|
|
|
} else { |
|
|
|
|
$select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; |
|
|
|
@ -1087,7 +1099,7 @@ class Share { |
|
|
|
|
} else { |
|
|
|
|
if (isset($uidOwner)) { |
|
|
|
|
if ($itemType == 'file' || $itemType == 'folder') { |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' |
|
|
|
|
.' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' |
|
|
|
|
.' `expiration`, `token`, `storage`, `mail_send`'; |
|
|
|
|
} else { |
|
|
|
@ -1100,7 +1112,7 @@ class Share { |
|
|
|
|
&& $format == \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS |
|
|
|
|
|| $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT |
|
|
|
|
) { |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' |
|
|
|
|
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`, `uid_owner`, ' |
|
|
|
|
.'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' |
|
|
|
|
.'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' |
|
|
|
|
.'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; |
|
|
|
@ -1206,13 +1218,9 @@ class Share { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (isset($row['expiration'])) { |
|
|
|
|
$time = new \DateTime(); |
|
|
|
|
if ($row['expiration'] < date('Y-m-d H:i', $time->format('U') - $time->getOffset())) { |
|
|
|
|
self::delete($row['id']); |
|
|
|
|
if (self::expireItem($row)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Check if resharing is allowed, if not remove share permission |
|
|
|
|
if (isset($row['permissions']) && !self::isResharingAllowed()) { |
|
|
|
|
$row['permissions'] &= ~PERMISSION_SHARE; |
|
|
|
|