* @return \DateTime|null The expiration date or null if $expireDate was null and it is not required
* @throws \OC\HintException
*/
- protected function validateExpirationDate($expirationDate) {
+ protected function validateExpirationDate(\OCP\Share\IShare $share) {
+
+ $expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
//Make sure the expiration date is a date
$message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
throw new \OC\HintException($message, $message, 404);
}
-
- return $expirationDate;
}
// If expiredate is empty set a default one if there is a default
if ($expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
- $date = new \DateTime();
- $date->setTime(0,0,0);
- $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
- return $date;
+ $expirationDate = new \DateTime();
+ $expirationDate->setTime(0,0,0);
+ $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
+ }
+
+ $accepted = true;
+ $message = '';
+ \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [
+ 'expirationDate' => &$expirationDate,
+ 'accepted' => &$accepted,
+ 'message' => &$message,
+ 'passwordSet' => $share->getPassword() === null,
+ ]);
+
+ if (!$accepted) {
+ throw new \Exception($message);
}
+ $share->setExpirationDate($expirationDate);
+
return $expirationDate;
}
);
//Verify the expiration date
- $share->setExpirationDate($this->validateExpirationDate($share->getExpirationDate()));
+ $this->validateExpirationDate($share);
//Verify the password
$this->verifyPassword($share->getPassword());
if ($share->getExpirationDate() !== $originalShare->getExpirationDate()) {
//Verify the expiration date
- $share->setExpirationDate($this->validateExpirationDate($share->getExpirationDate()));
+ $this->validateExpirationDate($share);
$expirationDateUpdated = true;
}
}