summaryrefslogtreecommitdiffstats
path: root/lib/public/share.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2013-09-23 22:56:15 +0200
committerMorris Jobke <morris.jobke@gmail.com>2013-11-03 12:34:38 +0100
commitfa56aec4b88dd44f7ffd2e80c2518a7ec8ce9126 (patch)
treefaa4ffd0d24ce79aab1c01ae055753bf0883a766 /lib/public/share.php
parent779b87d46aff59205cebe058bf66cd5b3acb22e4 (diff)
downloadnextcloud-server-fa56aec4b88dd44f7ffd2e80c2518a7ec8ce9126.tar.gz
nextcloud-server-fa56aec4b88dd44f7ffd2e80c2518a7ec8ce9126.zip
Deduplicate expiration date check into a method.
Diffstat (limited to 'lib/public/share.php')
-rw-r--r--lib/public/share.php36
1 files changed, 21 insertions, 15 deletions
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;
}
@@ -834,6 +827,23 @@ class Share {
}
/**
+ * 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
@@ -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()) {