diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-03 15:15:04 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-06-06 15:47:37 +0200 |
commit | f15d7dfec06ff895b8956741277f5ec8d6f4fa92 (patch) | |
tree | 1787f0964bea33d9b1dad4dfdc7377ea77f2a388 /lib | |
parent | 933c05566e21c27e4f2d4b4e9c2d54e7b363d304 (diff) | |
download | nextcloud-server-f15d7dfec06ff895b8956741277f5ec8d6f4fa92.tar.gz nextcloud-server-f15d7dfec06ff895b8956741277f5ec8d6f4fa92.zip |
only expire link shares
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share/helper.php | 12 | ||||
-rw-r--r-- | lib/private/share/share.php | 103 |
2 files changed, 79 insertions, 36 deletions
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php index c92aa15b4bf..71c6d8517a9 100644 --- a/lib/private/share/helper.php +++ b/lib/private/share/helper.php @@ -200,6 +200,18 @@ class Helper extends \OC\Share\Constants { return $defaultExpireSettings; } + public static function calcExpireDate() { + $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; + $expireAt = time() + $expireAfter; + $date = new \DateTime(); + $date->setTimestamp($expireAt); + $date->setTime(0, 0, 0); + //$dateString = $date->format('Y-m-d') . ' 00:00:00'; + + return $date; + + } + /** * calculate expire date * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' diff --git a/lib/private/share/share.php b/lib/private/share/share.php index f02eacfed74..883fbd1b298 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -606,6 +606,7 @@ class Share extends \OC\Share\Constants { $oldPermissions = $checkExists['permissions']; //delete the old share Helper::delete($checkExists['id']); + $updateExistingShare = true; } // Generate hash of password - same method as user passwords @@ -628,6 +629,12 @@ class Share extends \OC\Share\Constants { throw new \Exception($message_t); } + if (!empty($updateExistingShare) && + self::isDefaultExpireDateEnabled() && + empty($expirationDate)) { + $expirationDate = Helper::calcExpireDate(); + } + // Generate token if (isset($oldToken)) { $token = $oldToken; @@ -886,28 +893,33 @@ class Share extends \OC\Share\Constants { */ public static function setExpirationDate($itemType, $itemSource, $date) { $user = \OC_User::getUser(); - $items = self::getItems($itemType, $itemSource, null, null, $user, self::FORMAT_NONE, null, -1, false); - if (!empty($items)) { - if ($date == '') { - $date = null; - } else { - $date = new \DateTime($date); - } - $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); - $query->bindValue(1, $date, 'datetime'); - foreach ($items as $item) { - $query->bindValue(2, (int) $item['id']); - $query->execute(); - \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', array( - 'itemType' => $itemType, - 'itemSource' => $itemSource, - 'date' => $date, - 'uidOwner' => $user - )); - } - return true; + + if ($date == '') { + $date = null; + } else { + $date = new \DateTime($date); } - return false; + $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); + $query->bindValue(1, $date, 'datetime'); + $query->bindValue(2, $itemType); + $query->bindValue(3, $itemSource); + $query->bindValue(4, $user); + $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); + + $result = $query->execute(); + + if ($result === 1) { + \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', array( + 'itemType' => $itemType, + 'itemSource' => $itemSource, + 'date' => $date, + 'uidOwner' => $user + )); + } else { + \OCP\Util::writeLog('sharing', "Couldn't set expire date'", \OCP\Util::ERROR); + } + + return ($result === 1) ? true : false; } /** @@ -917,29 +929,34 @@ class Share extends \OC\Share\Constants { */ protected static function expireItem(array $item) { - // calculate expire date - if (!empty($item['expiration'])) { - $userDefinedExpire = new \DateTime($item['expiration']); - $expires = $userDefinedExpire->getTimestamp(); - } else { - $expires = null; - } + $result = false; // only use default expire date for link shares - if((int)$item['share_type'] === self::SHARE_TYPE_LINK) { + if ((int) $item['share_type'] === self::SHARE_TYPE_LINK) { + + // calculate expire date + if (!empty($item['expiration'])) { + $userDefinedExpire = new \DateTime($item['expiration']); + $expires = $userDefinedExpire->getTimestamp(); + } else { + $expires = null; + } + + // get default expire settings $defaultSettings = Helper::getDefaultExpireSetting(); $expires = Helper::calculateExpireDate($defaultSettings, $item['stime'], $expires); - } - if (is_int($expires)) { - $now = time(); - if ($now > $expires) { - self::unshareItem($item); - return true; + + if (is_int($expires)) { + $now = time(); + if ($now > $expires) { + self::unshareItem($item); + $result = true; + } } } - return false; + return $result; } /** @@ -1865,4 +1882,18 @@ class Share extends \OC\Share\Constants { return ($value === 'yes') ? true : false; } + public static function isDefaultExpireDateEnabled() { + $defaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); + return ($defaultExpireDateEnabled === "yes") ? true : false; + } + + public static function enforceDefaultExpireDate() { + $enforceDefaultExpireDate = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); + return ($enforceDefaultExpireDate === "yes") ? true : false; + } + + public static function getExpireInterval() { + return (int)\OCP\Config::getAppValue('core', 'shareapi_expire_after_n_days', '7'); + } + } |