[BUGFIX] Correction of Filelink of FAL in linkvalidator 63/39463/3
authorPierre Boivin <pierreboivin85@gmail.com>
Mon, 11 May 2015 20:00:10 +0000 (16:00 -0400)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 30 Jun 2015 23:03:37 +0000 (01:03 +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/39463
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/linkvalidator/Classes/Linktype/FileLinktype.php

index 202b0fc..fb97859 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
+
 /**
  * This class provides Check File Links plugin implementation
  *
@@ -23,6 +26,21 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
 class FileLinktype extends \TYPO3\CMS\Linkvalidator\Linktype\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 (GeneralUtility::isFirstPartOfStr(strtolower($value['tokenValue']), 'file:')) {
+                       $type = 'file';
+               }
+               return $type;
+       }
+
+       /**
         * Checks a given URL + /path/filename.ext for validity
         *
         * @param string $url Url to check
@@ -31,10 +49,13 @@ class FileLinktype extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktype {
         * @return boolean TRUE on success or FALSE on error
         */
        public function checkLink($url, $softRefEntry, $reference) {
-               if (!@file_exists((PATH_site . rawurldecode($url)))) {
+               $resourceFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+               try {
+                       $file = $resourceFactory->retrieveFileOrFolderObject($url);
+               } catch (FileDoesNotExistException $e) {
                        return FALSE;
                }
-               return TRUE;
+               return !$file->isMissing();
        }
 
        /**