From: Andreas Fischer Date: Mon, 23 Sep 2013 20:56:15 +0000 (+0200) Subject: Deduplicate expiration date check into a method. X-Git-Tag: v6.0.0beta3~21^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa56aec4b88dd44f7ffd2e80c2518a7ec8ce9126;p=nextcloud-server.git Deduplicate expiration date check into a method. --- diff --git a/lib/public/share.php b/lib/public/share.php index 48dedd07c0c..cde141fc4f9 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -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::unshareItem($row); - return false; - } + if (self::expireItem($row)) { + return false; } - return $row; } @@ -833,6 +826,23 @@ 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) @@ -1208,12 +1218,8 @@ class Share { } } } - if (isset($row['expiration'])) { - $time = new \DateTime(); - if ($row['expiration'] < date('Y-m-d H:i', $time->format('U') - $time->getOffset())) { - self::unshareItem($row); - continue; - } + if (self::expireItem($row)) { + continue; } // Check if resharing is allowed, if not remove share permission if (isset($row['permissions']) && !self::isResharingAllowed()) {