[TASK] Use Environment API instead of PATH_site in indexed_search 31/57231/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 13:54:42 +0000 (15:54 +0200)
committerJan Helke <typo3@helke.de>
Fri, 15 Jun 2018 15:26:27 +0000 (17:26 +0200)
Resolves: #85273
Releases: master
Change-Id: If2a643843532d14f2b7263c66b22ad1bc0402c33
Reviewed-on: https://review.typo3.org/57231
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/indexed_search/Classes/Hook/CrawlerHook.php
typo3/sysext/indexed_search/Classes/Indexer.php
typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php

index fa6ee48..26b4a79 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\IndexedSearch\Hook;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -359,7 +360,7 @@ class CrawlerHook
                         }
                     }
                 }
-                $files = GeneralUtility::removePrefixPathFromList($files, PATH_site);
+                $files = GeneralUtility::removePrefixPathFromList($files, Environment::getPublicPath() . '/');
                 // traverse the items and create log entries:
                 foreach ($files as $path) {
                     $this->instanceCounter++;
index 098aea3..701155f 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\IndexedSearch;
 
 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
@@ -802,7 +803,7 @@ class Indexer
                 if (GeneralUtility::isAllowedAbsPath($linkSource)) {
                     $localFile = $linkSource;
                 } else {
-                    $localFile = GeneralUtility::getFileAbsFileName(PATH_site . $linkSource);
+                    $localFile = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $linkSource);
                 }
                 if ($localFile && @is_file($localFile)) {
                     // Index local file:
@@ -1013,7 +1014,7 @@ class Indexer
         $baseURLLength = strlen($baseURL);
         if (substr($sourcePath, 0, $baseURLLength) == $baseURL) {
             $sourcePath = substr($sourcePath, $baseURLLength);
-            $localPath = PATH_site . $sourcePath;
+            $localPath = Environment::getPublicPath() . '/' . $sourcePath;
             if (!self::isAllowedLocalFile($localPath)) {
                 $localPath = '';
             }
@@ -1036,7 +1037,7 @@ class Indexer
             $absRefPrefixLength = strlen($absRefPrefix);
             if ($absRefPrefixLength > 0 && substr($sourcePath, 0, $absRefPrefixLength) == $absRefPrefix) {
                 $sourcePath = substr($sourcePath, $absRefPrefixLength);
-                $localPath = PATH_site . $sourcePath;
+                $localPath = Environment::getPublicPath() . '/' . $sourcePath;
                 if (!self::isAllowedLocalFile($localPath)) {
                     $localPath = '';
                 }
@@ -1057,7 +1058,7 @@ class Indexer
         $localPath = '';
         if ($sourcePath[0] === '/') {
             $sourcePath = substr($sourcePath, 1);
-            $localPath = PATH_site . $sourcePath;
+            $localPath = Environment::getPublicPath() . '/' . $sourcePath;
             if (!self::isAllowedLocalFile($localPath)) {
                 $localPath = '';
             }
@@ -1075,7 +1076,7 @@ class Indexer
     {
         $localPath = '';
         if (self::isRelativeURL($sourcePath)) {
-            $localPath = PATH_site . $sourcePath;
+            $localPath = Environment::getPublicPath() . '/' . $sourcePath;
             if (!self::isAllowedLocalFile($localPath)) {
                 $localPath = '';
             }
@@ -1104,7 +1105,7 @@ class Indexer
     protected static function isAllowedLocalFile($filePath)
     {
         $filePath = GeneralUtility::resolveBackPath($filePath);
-        $insideWebPath = substr($filePath, 0, strlen(PATH_site)) == PATH_site;
+        $insideWebPath = substr($filePath, 0, strlen(Environment::getPublicPath())) === Environment::getPublicPath();
         $isFile = is_file($filePath);
         return $insideWebPath && $isFile;
     }
@@ -1115,9 +1116,9 @@ class Indexer
      *
      ******************************************/
     /**
-     * Indexing a regular document given as $file (relative to PATH_site, local file)
+     * Indexing a regular document given as $file (relative to public web path, local file)
      *
-     * @param string $file Relative Filename, relative to PATH_site. It can also be an absolute path as long as it is inside the lockRootPath (validated with \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath()). Finally, if $contentTmpFile is set, this value can be anything, most likely a URL
+     * @param string $file Relative Filename, relative to public web path. It can also be an absolute path as long as it is inside the lockRootPath (validated with \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath()). Finally, if $contentTmpFile is set, this value can be anything, most likely a URL
      * @param bool $force If set, indexing is forced (despite content hashes, mtime etc).
      * @param string $contentTmpFile Temporary file with the content to read it from (instead of $file). Used when the $file is a URL.
      * @param string $altExtension File extension for temporary file.
@@ -1130,8 +1131,8 @@ class Indexer
         // Create abs-path:
         if (!$contentTmpFile) {
             if (!GeneralUtility::isAbsPath($file)) {
-                // Relative, prepend PATH_site:
-                $absFile = GeneralUtility::getFileAbsFileName(PATH_site . $file);
+                // Relative, prepend public web path:
+                $absFile = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $file);
             } else {
                 // Absolute, pass-through:
                 $absFile = $file;
index 7694601..8cc3558 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\IndexedSearch\Tests\Unit;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\IndexedSearch\Indexer;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
@@ -50,7 +51,7 @@ class IndexerTest extends UnitTestCase
      */
     public function extractHyperLinksReturnsCorrectFileUsingT3Vars()
     {
-        $temporaryFileName = tempnam(PATH_site . 'typo3temp/var/tests/', 't3unit-');
+        $temporaryFileName = tempnam(Environment::getVarPath() . '/tests/', 't3unit-');
         $this->testFilesToDelete[] = $temporaryFileName;
         $html = 'test <a href="testfile">test</a> test';
         $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = [
@@ -65,14 +66,14 @@ class IndexerTest extends UnitTestCase
     /**
      * @test
      */
-    public function extractHyperLinksRecurnsCorrectPathWithBaseUrl()
+    public function extractHyperLinksReturnsCorrectPathWithBaseUrl()
     {
         $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
         $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
         $subject = new Indexer();
         $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -84,7 +85,7 @@ class IndexerTest extends UnitTestCase
         $subject = new Indexer();
         $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -92,12 +93,11 @@ class IndexerTest extends UnitTestCase
      */
     public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory()
     {
-        $path = substr(PATH_typo3, strlen(PATH_site) - 1);
-        $html = 'test <a href="' . $path . 'index.php">test</a> test';
+        $html = 'test <a href="typo3/index.php">test</a> test';
         $subject = new Indexer();
         $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/typo3/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -117,7 +117,7 @@ class IndexerTest extends UnitTestCase
         $subject = new Indexer();
         $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**