[BUGFIX] Correction of Filelink of FAL in linkvalidator 64/39464/4
authorPierre Boivin <pierreboivin85@gmail.com>
Mon, 11 May 2015 20:00:10 +0000 (16:00 -0400)
committerFrans Saris <franssaris@gmail.com>
Mon, 29 Jun 2015 16:25:42 +0000 (18:25 +0200)
Add a fetchType function for linkvalidator to take
FileLinktype class for "file:XXX" media instead of internalLink class.

Make a first validation with "retrieveFileOrFolderObject" to
check if file exist in a database.

Make a second validation on the file "physically" on the server.

Resolves: #66895
Releases: master, 6.2
Change-Id: Ife0ab588e0ac4eb932cca3d6545f243bbcddc7ae
Reviewed-on: http://review.typo3.org/39464
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/linkvalidator/Classes/Linktype/FileLinktype.php

index 3b7fc8b..3695bfa 100644 (file)
@@ -14,7 +14,10 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
  * The TYPO3 project - inspiring people to share!
  */
 
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * This class provides Check File Links plugin implementation
 
 /**
  * This class provides Check File Links plugin implementation
@@ -24,6 +27,20 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class FileLinktype extends AbstractLinktype {
 
  */
 class FileLinktype extends AbstractLinktype {
 
+       /**
+        * Type fetching method, based on the type that softRefParserObj returns
+        *
+        * @param array $value Reference properties
+        * @param string $type Current type
+        * @param string $key Validator hook name
+        * @return string fetched type
+        */
+       public function fetchType($value, $type, $key) {
+               if (StringUtility::beginswith(strtolower($value['tokenValue']), 'file:')) {
+                       $type = 'file';
+               }
+               return $type;
+       }
        /**
         * Checks a given URL + /path/filename.ext for validity
         *
        /**
         * Checks a given URL + /path/filename.ext for validity
         *
@@ -33,7 +50,13 @@ class FileLinktype extends AbstractLinktype {
         * @return bool TRUE on success or FALSE on error
         */
        public function checkLink($url, $softRefEntry, $reference) {
         * @return bool TRUE on success or FALSE on error
         */
        public function checkLink($url, $softRefEntry, $reference) {
-               return @file_exists(PATH_site . rawurldecode($url));
+               $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
+               try {
+                       $file = $resourceFactory->retrieveFileOrFolderObject($url);
+               } catch (FileDoesNotExistException $e) {
+                       return FALSE;
+               }
+               return !$file->isMissing();
        }
 
        /**
        }
 
        /**