[BUGFIX] Keep linktype on core update 45/36345/5
authorFrederic Gaus <gaus@flagbit.de>
Thu, 29 Jan 2015 09:59:20 +0000 (10:59 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 2 Feb 2015 20:56:30 +0000 (21:56 +0100)
Keep the linktype of the symlink pointing to the TYPO3 core. Currently
the CoreUpdateService always creates an absolute link even if the
link was relative before. This patch checks for the correct link type
during a core update. This could be important in some environments,
e.g. in a chrooted environemnt.

Change-Id: I47bbe0d54a88853adc4160937a21d641b756f20f
Resolves: #58000
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/36345
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Göran Bodenschatz <coding@46halbe.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/install/Classes/Service/CoreUpdateService.php

index 1061849..bd0cc70 100644 (file)
@@ -425,6 +425,7 @@ class CoreUpdateService {
                        $message->setTitle('TYPO3 source directory (typo3_src) is not a link');
                        $messages[] = $message;
                } else {
+                       $isCurrentCoreSymlinkAbsolute = PathUtility::isAbsolutePath(readlink($this->symlinkToCoreFiles));
                        $unlinkResult = unlink($this->symlinkToCoreFiles);
                        if (!$unlinkResult) {
                                $success = FALSE;
@@ -433,6 +434,9 @@ class CoreUpdateService {
                                $message->setTitle('Removing old symlink failed');
                                $messages[] = $message;
                        } else {
+                               if (!$isCurrentCoreSymlinkAbsolute) {
+                                       $newCoreLocation = $this->getRelativePath($newCoreLocation);
+                               }
                                $symlinkResult = symlink($newCoreLocation, $this->symlinkToCoreFiles);
                                if ($symlinkResult) {
                                        OpcodeCacheUtility::clearAllActive();
@@ -460,4 +464,20 @@ class CoreUpdateService {
                return $this->downloadTargetPath . $version . '.tar.gz';
        }
 
+       /**
+        * Get relative path to TYPO3 source directory from webroot
+        *
+        * @param string $absolutePath to TYPO3 source directory
+        * @return string relative path to TYPO3 source directory
+        */
+       protected function getRelativePath($absolutePath) {
+               $sourcePath = explode(DIRECTORY_SEPARATOR, rtrim(PATH_site, DIRECTORY_SEPARATOR));
+               $targetPath = explode(DIRECTORY_SEPARATOR, rtrim($absolutePath, DIRECTORY_SEPARATOR));
+               while (count($sourcePath) && count($targetPath) && $sourcePath[0] === $targetPath[0]) {
+                       array_shift($sourcePath);
+                       array_shift($targetPath);
+               }
+               return str_pad('', count($sourcePath) * 3, '..' . DIRECTORY_SEPARATOR) . implode(DIRECTORY_SEPARATOR, $targetPath);
+       }
+
 }