[CLEANUP] InstallStatusReport 93/36093/4
authorOliver Klee <typo3-coding@oliverklee.de>
Sun, 18 Jan 2015 12:01:35 +0000 (13:01 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 18 Jan 2015 21:02:53 +0000 (22:02 +0100)
- reduce code duplication
- add some @var
- add a missing default case in a switch
- small code formatting fixes
- shorten types
- polish some comments
- add an accessor for $GLOBALS['LANG']
- move an onvertVersionNumberToInteger call out of a loop

Resolves: #64340
Releases: master
Change-Id: Iec21be743d684628b2a5845f3e3574d4a7256678
Reviewed-on: http://review.typo3.org/36093
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Report/InstallStatusReport.php

index ee86441..8129930 100644 (file)
@@ -16,16 +16,19 @@ namespace TYPO3\CMS\Install\Report;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Reports\Status;
 use TYPO3\CMS\Install\Service\Exception;
 
 /**
- * Provides an installation status report
+ * Provides an installation status report.
  *
  * @author Ingo Renner <ingo@typo3.org>
  */
 class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface {
-
+       /**
+        * @var string
+        */
        protected $reportList = 'FileSystem,RemainingUpdates,NewVersion';
 
        /**
@@ -45,10 +48,11 @@ class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
        /**
         * Checks for several directories being writable.
         *
-        * @return \TYPO3\CMS\Reports\Status Indicates status of the file system
+        * @return Status Indicates status of the file system
         */
        protected function getFileSystemStatus() {
-               $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
+               $languageService = $this->getLanguageService();
+               $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_writable');
                $message = '';
                $severity = Status::OK;
                // Requirement level
@@ -72,27 +76,27 @@ class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
                        'uploads/pics/' => 0,
                        'uploads/media/' => 0,
                        $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] => -1,
-                       $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0
+                       $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '_temp_/' => 0,
                );
                foreach ($checkWritable as $relPath => $requirementLevel) {
-                       if (!@is_dir((PATH_site . $relPath))) {
+                       if (!@is_dir(PATH_site . $relPath)) {
                                // If the directory is missing, try to create it
                                GeneralUtility::mkdir(PATH_site . $relPath);
                        }
-                       if (!@is_dir((PATH_site . $relPath))) {
+                       if (!@is_dir(PATH_site . $relPath)) {
                                if ($requirementLevel > 0) {
                                        // directory is required
-                                       $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
-                                       $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
+                                       $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_missingDirectory');
+                                       $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExistCouldNotCreate'), $relPath) . '<br />';
                                        $severity = Status::ERROR;
                                } else {
-                                       $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
+                                       $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryDoesNotExist'), $relPath);
                                        if ($requirementLevel == 0) {
-                                               $message .= ' ' . $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
+                                               $message .= ' ' . $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldAlsoBeWritable');
                                        }
                                        $message .= '<br />';
                                        if ($severity < Status::WARNING) {
-                                               $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
+                                               $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_nonExistingDirectory');
                                                $severity = Status::WARNING;
                                        }
                                }
@@ -100,99 +104,114 @@ class InstallStatusReport implements \TYPO3\CMS\Reports\StatusProviderInterface
                                if (!is_writable((PATH_site . $relPath))) {
                                        switch ($requirementLevel) {
                                                case 0:
-                                                       $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
+                                                       $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryShouldBeWritable'), (PATH_site . $relPath)) . '<br />';
                                                        if ($severity < Status::WARNING) {
-                                                               $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
+                                                               $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_recommendedWritableDirectory');
                                                                $severity = Status::WARNING;
                                                        }
                                                        break;
                                                case 2:
-                                                       $value = $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
-                                                       $message .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
+                                                       $value = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_requiredWritableDirectory');
+                                                       $message .= sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_directoryMustBeWritable'), (PATH_site . $relPath)) . '<br />';
                                                        $severity = Status::ERROR;
                                                        break;
+                                               default:
                                        }
                                }
                        }
                }
-               return GeneralUtility::makeInstance(Status::class, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
+               return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_fileSystem'), $value, $message, $severity);
        }
 
        /**
         * Checks if there are still updates to perform
         *
-        * @return \TYPO3\CMS\Reports\Status Represents whether the installation is completely updated yet
+        * @return Status Represents whether the installation is completely updated yet
         */
        protected function getRemainingUpdatesStatus() {
-               $value = $GLOBALS['LANG']->getLL('status_updateComplete');
+               $languageService = $this->getLanguageService();
+               $value = $languageService->getLL('status_updateComplete');
                $message = '';
                $severity = Status::OK;
 
                // check if there are update wizards left to perform
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'])) {
+                       $versionAsInt = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
-                               $versionAsInt = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
                                $updateObject = GeneralUtility::makeInstance($className, $identifier, $versionAsInt, NULL, $this);
                                if ($updateObject->shouldRenderWizard()) {
                                        // at least one wizard was found
-                                       $value = $GLOBALS['LANG']->getLL('status_updateIncomplete');
+                                       $value = $languageService->getLL('status_updateIncomplete');
                                        $severity = Status::WARNING;
                                        $url = BackendUtility::getModuleUrl('system_InstallInstall');
-                                       $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
+                                       $message = sprintf($languageService->sL('LLL:EXT:lang/locallang_core.xlf:warning.install_update'), '<a href="' . htmlspecialchars($url) . '">', '</a>');
                                        break;
                                }
                        }
                }
 
-               return GeneralUtility::makeInstance(Status::class, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
+               return GeneralUtility::makeInstance(Status::class, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remainingUpdates'), $value, $message, $severity);
        }
 
 
        /**
-        * Checks if there is a new minor TYPO3 version to update to
+        * Checks if there is a new minor TYPO3 version to update to.
         *
-        * @return \TYPO3\CMS\Reports\Status Represents whether there is a new version available online
+        * @return Status Represents whether there is a new version available online
         */
        protected function getNewVersionStatus() {
+               $languageService = $this->getLanguageService();
+               /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
                $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
                /** @var \TYPO3\CMS\Install\Service\CoreVersionService $coreVersionService */
                $coreVersionService = $objectManager->get(\TYPO3\CMS\Install\Service\CoreVersionService::class);
 
                // No updates for development versions
                if (!$coreVersionService->isInstalledVersionAReleasedVersion()) {
-                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
+                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_isDevelopmentVersion'), Status::NOTICE);
                }
 
                // If fetching version matrix fails we can not do anything except print out the current version
                try {
                        $coreVersionService->updateVersionMatrix();
                } catch (Exception\RemoteFetchException $remoteFetchException) {
-                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'), Status::NOTICE);
+                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_remoteFetchException'), Status::NOTICE);
                }
 
                try {
                        $isUpdateAvailable = $coreVersionService->isYoungerPatchReleaseAvailable();
                        $isMaintainedVersion = $coreVersionService->isVersionActivelyMaintained();
                } catch (Exception\CoreVersionServiceException $coreVersionServiceException) {
-                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_patchLevelNotFoundInReleaseMatrix'), Status::WARNING);
+                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_patchLevelNotFoundInReleaseMatrix'), Status::WARNING);
                }
 
                if (!$isUpdateAvailable && $isMaintainedVersion) {
                        // Everything is fine, working with the latest version
-                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, '', Status::OK);
+                       $message = '';
+                       $status = Status::OK;
                } elseif ($isUpdateAvailable) {
                        // There is an update available
                        $newVersion = $coreVersionService->getYoungestPatchRelease();
                        if ($coreVersionService->isUpdateSecurityRelevant()) {
-                               return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion), Status::ERROR);
+                               $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersionSecurityRelevant'), $newVersion);
+                               $status = Status::ERROR;
                        } else {
-                               return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, sprintf($GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion), Status::WARNING);
+                               $message = sprintf($languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_newVersion'), $newVersion);
+                               $status = Status::WARNING;
                        }
                } else {
                        // Version is not maintained
-                       return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $GLOBALS['LANG']->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_versionOutdated'), Status::ERROR);
+                       $message = $languageService->sL('LLL:EXT:install/Resources/Private/Language/Report/locallang.xlf:status_versionOutdated');
+                       $status = Status::ERROR;
                }
 
+               return GeneralUtility::makeInstance(Status::class, 'TYPO3', TYPO3_version, $message, $status);
        }
 
+       /**
+        * @return LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
 }