]> source.dussan.org Git - nextcloud-server.git/commitdiff
Deduplicate expiration date check into a method.
authorAndreas Fischer <bantu@owncloud.com>
Mon, 23 Sep 2013 20:56:15 +0000 (22:56 +0200)
committerMorris Jobke <morris.jobke@gmail.com>
Sun, 3 Nov 2013 11:34:38 +0000 (12:34 +0100)
lib/public/share.php

index 48dedd07c0c80edd5c213a22f03efceb4d78d1dd..cde141fc4f92c6c6f667210be676e88e65ba2301 100644 (file)
@@ -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()) {