Fixes a bug for application with no lang vars
authorMatthias Schmidt <gravatronics@live.com>
Thu, 8 Mar 2012 14:33:07 +0000 (15:33 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 8 Mar 2012 14:33:07 +0000 (15:33 +0100)
This bug should also occur if the active application supports less languages than installed and the installed package supports languages that are installed but not supported by the active application.

In those cases, the localized package infos weren't saved since the language array way empty (or not all localizations were saved). Now all languages are fetched and now this also happens at the very end of the installation which makes it possible to save the localized data in a new language that was delivered by the installed package (though this seems to be not supported yet).

wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

index eb2c7bc2b9361fbe6ba94a5eb61900af63f05596..464fef37a1e52036fb336e9e58a83486702d55a8 100644 (file)
@@ -130,9 +130,11 @@ class PackageInstallationDispatcher {
                $node = $this->nodeBuilder->getNextNode($node);
                $step->setNode($node);
                
-               // update options.inc.php if installation is completed
+               // update options.inc.php and save localized package infos
                if ($node == '') {
                        OptionEditor::resetCache();
+                       
+                       $this->saveLocalizedPackageInfos();
                }
                
                return $step;
@@ -211,39 +213,6 @@ class PackageInstallationDispatcher {
                        // create package entry
                        $package = PackageEditor::create($nodeData);
                        
-                       // localize package information
-                       $sql = "INSERT INTO     wcf".WCF_N."_language_item
-                                               (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
-                               VALUES          (?, ?, ?, ?, ?)";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       
-                       // workaround for WCFSetup
-                       if (!PACKAGE_ID) {
-                               $sql = "SELECT  *
-                                       FROM    wcf".WCF_N."_language_category
-                                       WHERE   languageCategory = ?";
-                               $statement2 = WCF::getDB()->prepareStatement($sql);
-                               $statement2->execute(array('wcf.acp.package'));
-                               $languageCategory = $statement2->fetchObject('wcf\data\language\category\LanguageCategory');
-                       }
-                       else {
-                               $languageCategory = LanguageFactory::getInstance()->getCategory('wcf.acp.package');
-                       }
-                       
-                       // save package name
-                       $this->saveLocalizedPackageInfo($statement, $languageCategory, $package, 'packageName');
-                       
-                       // save package description
-                       $this->saveLocalizedPackageInfo($statement, $languageCategory, $package, 'packageDescription');
-                       
-                       // todo: license and readme
-                       
-                       $packageEditor = new PackageEditor($package);
-                       $packageEditor->update(array(
-                               'packageDescription' => 'wcf.acp.package.packageDescription.package'.$package->packageID,
-                               'packageName' => 'wcf.acp.package.packageName.package'.$package->packageID
-                       ));
-                       
                        // update package id for current queue
                        $queueEditor = new PackageInstallationQueueEditor($this->queue);
                        $queueEditor->update(array(
@@ -329,15 +298,62 @@ class PackageInstallationDispatcher {
                return $installationStep;
        }
        
+       /**
+        * Saves the localized package infos.
+        * 
+        * @todo        license and readme
+        */
+       protected function saveLocalizedPackageInfos() {
+               $package = new Package($this->queue->packageID);
+               
+               // localize package information
+               $sql = "INSERT INTO     wcf".WCF_N."_language_item
+                                       (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
+                       VALUES          (?, ?, ?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               
+               // get language list
+               $languageList = new LanguageList();
+               $languageList->sqlLimit = 0;
+               $languageList->readObjects();
+               
+               // workaround for WCFSetup
+               if (!PACKAGE_ID) {
+                       $sql = "SELECT  *
+                               FROM    wcf".WCF_N."_language_category
+                               WHERE   languageCategory = ?";
+                       $statement2 = WCF::getDB()->prepareStatement($sql);
+                       $statement2->execute(array('wcf.acp.package'));
+                       $languageCategory = $statement2->fetchObject('wcf\data\language\category\LanguageCategory');
+               }
+               else {
+                       $languageCategory = LanguageFactory::getInstance()->getCategory('wcf.acp.package');
+               }
+               
+               // save package name
+               $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageName');
+               
+               // save package description
+               $this->saveLocalizedPackageInfo($statement, $languageList, $languageCategory, $package, 'packageDescription');
+               
+               // update description and name
+               $packageEditor = new PackageEditor($package);
+               $packageEditor->update(array(
+                       'packageDescription' => 'wcf.acp.package.packageDescription.package'.$this->queue->packageID,
+                       'packageName' => 'wcf.acp.package.packageName.package'.$this->queue->packageID
+               ));
+       }
+       
        /**
         * Saves a localized package info.
         * 
         * @param       wcf\system\database\statement\PreparedStatement         $statement
+        * @param       wcf\data\language\LanguageList                          $languageList
         * @param       wcf\data\language\category\LanguageCategory             $languageCategory
         * @param       wcf\data\package\Package                                $package
         * @param       string                                                  $infoName
         */
-       protected function saveLocalizedPackageInfo(PreparedStatement $statement, LanguageCategory $languageCategory, Package $package, $infoName) {
+       protected function saveLocalizedPackageInfo(PreparedStatement $statement, $languageList, LanguageCategory $languageCategory, Package $package, $infoName) {
                $infoValues = $this->getArchive()->getPackageInfo($infoName);
                
                // get default value for languages without specified information
@@ -358,18 +374,7 @@ class PackageInstallationDispatcher {
                        $defaultValue = $this->archive->getPackageInfo('name');
                }
                
-               // workaround for WCFSetup
-               if (!PACKAGE_ID) {
-                       $languageList = new LanguageList();
-                       $languageList->sqlLimit = 0;
-                       $languageList->readObjects();
-                       $languages = $languageList->getObjects();
-               }
-               else {
-                       $languages = LanguageFactory::getInstance()->getLanguages();
-               }
-               
-               foreach ($languages as $language) {
+               foreach ($languageList as $language) {
                        $value = $defaultValue;
                        if (isset($infoValues[$language->languageCode])) {
                                $value = $infoValues[$language->languageCode];