[BUGFIX] Catch exceptions thrown in davPropFind function 19/19219/4
authorNicole Cordes <typo3@cordes.co>
Sat, 23 Mar 2013 14:18:08 +0000 (15:18 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Sun, 24 Mar 2013 13:33:59 +0000 (14:33 +0100)
If any error occurs (e.g. authentication data or URL is wrong) SabreDAV
throws an exception. In the driver function this exception should be
caught and logged but should prevent backend modules to break.

Change-Id: I0d741b84d5a786672529d2a56241b4632f796bda
Fixes: #46597
Reviewed-on: https://review.typo3.org/19219
Reviewed-by: Andreas Wolf
Tested-by: Andreas Wolf
Classes/Driver/WebDavDriver.php

index 87d3d3c..2fc8912 100644 (file)
@@ -210,13 +210,25 @@ class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
         * @return array
         */
        protected function davPropFind($url) {
-               return $this->davClient->propfind($url, array(
-                       '{DAV:}resourcetype',
-                       '{DAV:}creationdate',
-                       '{DAV:}getcontentlength',
-                       '{DAV:}getlastmodified'
-               ), 1);
-               // TODO throw exception on error
+               try {
+                       return $this->davClient->propfind($url, array(
+                               '{DAV:}resourcetype',
+                               '{DAV:}creationdate',
+                               '{DAV:}getcontentlength',
+                               '{DAV:}getlastmodified'
+                       ), 1);
+               } catch (\Sabre_DAV_Exception_NotFound $exception) {
+                       // If a file is not found, we have to deal with that on a higher level, so throw the exception again
+                       throw $exception;
+               } catch (\Sabre_DAV_Exception $exception) {
+                       // log all other exceptions
+                       $this->logger->error(sprintf(
+                               'Error while executing DAV PROPFIND request. Original message: "%s" (Exception %s, id: %u)',
+                               $exception->getMessage(), get_class($exception), $exception->getCode()
+                       ));
+                       $this->storage->markAsTemporaryOffline();
+                       return array();
+               }
        }
 
        /**
@@ -494,7 +506,7 @@ class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                                'identifier' => $identifier,
                                'storage' => $this->storage->getUid()
                        );
-               } catch (\Exception $exception) {
+               } catch (\Sabre_DAV_Exception $exception) {
                        $fileInfo = array(
                                'name' => basename($identifier),
                                'identifier' => $identifier,
@@ -545,6 +557,7 @@ class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                $folderIdentifier = $parentFolder->getIdentifier() . $name . '/';
                return $this->getFolder($folderIdentifier);
        }
+
        /**
         * Generic handler method for directory listings - gluing together the listing items is done
         *
@@ -577,6 +590,12 @@ class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                        // TODO set cache lifetime
                        $this->directoryListingCache->set($cacheKey, $properties);
                }
+
+               // if we have only one entry, this is the folder we are currently in, so there are no items -> return an empty array
+               if (count($properties) == 1) {
+                       return array();
+               }
+
                $propertyIterator = new \ArrayIterator($properties);
 
                // TODO handle errors
@@ -585,11 +604,6 @@ class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                        $path = '/' . trim($path, '/') . '/';
                }
 
-                       // if we have only one entry, this is the folder we are currently in, so there are no items -> return an empty array
-               if (count($properties) == 1) {
-                       return array();
-               }
-
                $c = $numberOfItems > 0 ? $numberOfItems : $propertyIterator->count();
                $propertyIterator->seek($start);