@@ -261,7 +261,14 @@ protected function validateExpirationDate(\OCP\Share\IShare $share) {
261261 }
262262
263263 // If expiredate is empty set a default one if there is a default
264- if ($ expirationDate === null && $ this ->shareApiLinkDefaultExpireDate ()) {
264+ $ fullId = null ;
265+ try {
266+ $ fullId = $ share ->getFullId ();
267+ } catch (\UnexpectedValueException $ e ) {
268+ // This is a new share
269+ }
270+
271+ if ($ fullId === null && $ expirationDate === null && $ this ->shareApiLinkDefaultExpireDate ()) {
265272 $ expirationDate = new \DateTime ();
266273 $ expirationDate ->setTime (0 ,0 ,0 );
267274 $ expirationDate ->add (new \DateInterval ('P ' .$ this ->shareApiLinkDefaultExpireDays ().'D ' ));
@@ -315,8 +322,12 @@ protected function userCreateChecks(\OCP\Share\IShare $share) {
315322 $ existingShares = $ provider ->getSharesByPath ($ share ->getNode ());
316323 foreach ($ existingShares as $ existingShare ) {
317324 // Ignore if it is the same share
318- if ($ existingShare ->getFullId () === $ share ->getFullId ()) {
319- continue ;
325+ try {
326+ if ($ existingShare ->getFullId () === $ share ->getFullId ()) {
327+ continue ;
328+ }
329+ } catch (\UnexpectedValueException $ e ) {
330+ //Shares are not identical
320331 }
321332
322333 // Identical share already existst
@@ -360,8 +371,12 @@ protected function groupCreateChecks(\OCP\Share\IShare $share) {
360371 $ provider = $ this ->factory ->getProviderForType (\OCP \Share::SHARE_TYPE_GROUP );
361372 $ existingShares = $ provider ->getSharesByPath ($ share ->getNode ());
362373 foreach ($ existingShares as $ existingShare ) {
363- if ($ existingShare ->getFullId () === $ share ->getFullId ()) {
364- continue ;
374+ try {
375+ if ($ existingShare ->getFullId () === $ share ->getFullId ()) {
376+ continue ;
377+ }
378+ } catch (\UnexpectedValueException $ e ) {
379+ //It is a new share so just continue
365380 }
366381
367382 if ($ existingShare ->getSharedWith () === $ share ->getSharedWith ()) {
@@ -558,7 +573,11 @@ public function updateShare(\OCP\Share\IShare $share) {
558573 throw new \Exception ('The Share API is disabled ' );
559574 }
560575
561- $ originalShare = $ this ->getShareById ($ share ->getFullId ());
576+ try {
577+ $ originalShare = $ this ->getShareById ($ share ->getFullId ());
578+ } catch (\UnexpectedValueException $ e ) {
579+ throw new \InvalidArgumentException ('Share does not have a full id ' );
580+ }
562581
563582 // We can't change the share type!
564583 if ($ share ->getShareType () !== $ originalShare ->getShareType ()) {
@@ -673,10 +692,15 @@ protected function deleteChildren(\OCP\Share\IShare $share) {
673692 *
674693 * @param \OCP\Share\IShare $share
675694 * @throws ShareNotFound
695+ * @throws \InvalidArgumentException
676696 */
677697 public function deleteShare (\OCP \Share \IShare $ share ) {
678698 // Just to make sure we have all the info
679- $ share = $ this ->getShareById ($ share ->getFullId ());
699+ try {
700+ $ share = $ this ->getShareById ($ share ->getFullId ());
701+ } catch (\UnexpectedValueException $ e ) {
702+ throw new \InvalidArgumentException ('Share does not have a full id ' );
703+ }
680704
681705 $ formatHookParams = function (\OCP \Share \IShare $ share ) {
682706 // Prepare hook
0 commit comments