From: Matthias Schmidt Date: Fri, 2 Mar 2012 13:45:55 +0000 (+0100) Subject: Localized package infos stay localized after installation X-Git-Tag: 2.0.0_Beta_1~1257^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a2ad7897726aa074bee95a2059fed85f8c94b342;p=GitHub%2FWoltLab%2FWCF.git Localized package infos stay localized after installation --- diff --git a/com.woltlab.wcf/package.xml b/com.woltlab.wcf/package.xml index 4af67e4785..9ada6fc3de 100644 --- a/com.woltlab.wcf/package.xml +++ b/com.woltlab.wcf/package.xml @@ -3,6 +3,7 @@ WoltLab Community Framework Free web-framework, designed and developed for complex community applications. + Freies Web-Framework, das für komplexe Community-Anwendungen entworfen und entwickelt wurde. 1 1 2.0.0 Alpha 1 diff --git a/wcfsetup/install/files/acp/templates/acpSessionLog.tpl b/wcfsetup/install/files/acp/templates/acpSessionLog.tpl index 95f3b5456c..a37b574c3c 100644 --- a/wcfsetup/install/files/acp/templates/acpSessionLog.tpl +++ b/wcfsetup/install/files/acp/templates/acpSessionLog.tpl @@ -39,7 +39,7 @@

{@$sessionAccessLog->sessionAccessLogID}

ipAddress != $sessionLog->ipAddress} style="color: red"{/if}>

{$sessionAccessLog->ipAddress}

{@$sessionAccessLog->time|time}

-

{$sessionAccessLog->packageName}

+

{$sessionAccessLog->packageName|language}

{$sessionAccessLog->className}

{if !$sessionAccessLog->hasProtectedURI()}{$sessionAccessLog->requestURI|truncate:50}{else}{$sessionAccessLog->requestURI|truncate:50}{/if}

{$sessionAccessLog->requestMethod}

diff --git a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl index b55c4b5784..1d2c354e13 100644 --- a/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl +++ b/wcfsetup/install/files/acp/templates/packageInstallationConfirm.tpl @@ -12,8 +12,8 @@
-

{$archive->getPackageInfo('packageName')}

-

{$archive->getPackageInfo('packageDescription')}

+

{$archive->getLocalizedPackageInfo('packageName')}

+

{$archive->getLocalizedPackageInfo('packageDescription')}

diff --git a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl index 2ab9815061..423143c3e0 100644 --- a/wcfsetup/install/files/acp/templates/packageListDetailed.tpl +++ b/wcfsetup/install/files/acp/templates/packageListDetailed.tpl @@ -81,7 +81,7 @@ {/if} - + {$package->getName()}{if $package->instanceNo > 1 && $package->instanceName == ''} (#{#$package->instanceNo}){/if}

{if $package->authorURL}{$package->author}{else}{$package->author}{/if}

diff --git a/wcfsetup/install/files/acp/templates/packageListPlugins.tpl b/wcfsetup/install/files/acp/templates/packageListPlugins.tpl index 09048fac87..d374d736fd 100644 --- a/wcfsetup/install/files/acp/templates/packageListPlugins.tpl +++ b/wcfsetup/install/files/acp/templates/packageListPlugins.tpl @@ -3,7 +3,7 @@

{$package->getName()}

- {$package->packageDescription|truncate:150} + {$package->packageDescription|language|truncate:150}
diff --git a/wcfsetup/install/files/acp/templates/packageUninstallationDependencies.tpl b/wcfsetup/install/files/acp/templates/packageUninstallationDependencies.tpl index f3690a938d..5babddce45 100644 --- a/wcfsetup/install/files/acp/templates/packageUninstallationDependencies.tpl +++ b/wcfsetup/install/files/acp/templates/packageUninstallationDependencies.tpl @@ -12,7 +12,7 @@

{lang}wcf.acp.package.uninstall{/lang}: {$packageObj->getName()}

-

{$packageObj->packageDescription}

+

{$packageObj->packageDescription|language}

@@ -115,7 +115,7 @@ {/if} -

{$package.packageName}{if $package.instanceNo > 1 && $package.instanceName == ''} (#{#$package.instanceNo}){/if}

+

{$package.packageName|language}{if $package.instanceNo > 1 && $package.instanceName == ''} (#{#$package.instanceNo}){/if}

{if $package.authorURL}{$package.author}{else}{$package.author}{/if}

{$package.packageVersion}

{@$package.packageDate|date}

diff --git a/wcfsetup/install/files/acp/templates/packageView.tpl b/wcfsetup/install/files/acp/templates/packageView.tpl index beab616587..d66141cc0c 100644 --- a/wcfsetup/install/files/acp/templates/packageView.tpl +++ b/wcfsetup/install/files/acp/templates/packageView.tpl @@ -12,7 +12,7 @@

{$package->getName()}

-

{$package->packageDescription}

+

{$package->packageDescription|language}

@@ -85,12 +85,12 @@ {event name='propertyFields'} - {if $package->packageDescription} + {if $package->packageDescription|language}

{lang}wcf.acp.package.description{/lang}

-

{$package->packageDescription}

+

{$package->packageDescription|language}

{/if} @@ -153,10 +153,17 @@ {/if} +<<<<<<< HEAD

{$requiredPackage->packageName}{if $requiredPackage->instanceNo > 1 && $requiredPackage->instanceName == ''} (#{#$requiredPackage->instanceNo}){/if}

{if $requiredPackage->authorURL}

{$requiredPackage->author}{else}{$requiredPackage->author}

{/if}

{$requiredPackage->packageVersion}

{@$requiredPackage->packageDate|date}

+======= +

{$requiredPackage.packageName|language}{if $requiredPackage.instanceNo > 1 && $requiredPackage.instanceName == ''} (#{#$requiredPackage.instanceNo}){/if}

+ {if $requiredPackage.authorURL}

{$requiredPackage.author}{else}{$requiredPackage.author}

{/if} +

{$requiredPackage.packageVersion}

+

{@$requiredPackage.packageDate|date}

+>>>>>>> Localized package infos stay localized after installation {event name='requirementColumns'} @@ -213,8 +220,8 @@ {/if} -

{$dependentPackage->packageName}{if $dependentPackage->instanceNo > 1 && $dependentPackage->instanceName == ''} (#{#$dependentPackage->instanceNo}){/if}

- {if $dependentPackage->authorURL}

{$dependentPackage->author}{else}{$dependentPackage->author}

{/if} +

{$dependentPackage->packageName|language}{if $dependentPackage->instanceNo > 1 && $dependentPackage->instanceName == ''} (#{#$dependentPackage->instanceNo}){/if}

+ {if $dependentPackage->authorURL}

{$dependentPackage->author}{else}{$dependentPackage->author}

{/if}

{$dependentPackage->packageVersion}

{@$dependentPackage->packageDate|date}

diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index 5fac5d04b8..f9f53937a3 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -221,7 +221,7 @@ class PackageStartInstallForm extends ACPForm { 'processNo' => $processNo, 'userID' => WCF::getUser()->userID, 'package' => $this->archive->getPackageInfo('name'), - 'packageName' => $this->archive->getPackageInfo('packageName'), + 'packageName' => $this->archive->getLocalizedPackageInfo('packageName'), 'packageID' => $packageID, 'archive' => (!empty($this->uploadPackage['tmp_name']) ? $this->uploadPackage['name'] : $this->downloadPackage), 'action' => ($this->package != null ? 'update' : 'install'), diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index dd1ddb58b7..1849e31251 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -87,7 +87,7 @@ class Package extends DatabaseObject { * @return string */ public function getName() { - return ($this->instanceName ? $this->instanceName : $this->packageName); + return WCF::getLanguage()->get($this->instanceName ? $this->instanceName : $this->packageName); } /** diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index df27e792e3..f4ff2638a4 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -1046,7 +1046,7 @@ class WCFSetup extends WCF { 'processNo' => $processNo, 'userID' => $admin->userID, 'package' => $packageName, - 'packageName' => $archive->getPackageInfo('packageName'), + 'packageName' => $archive->getLocalizedPackageInfo('packageName'), 'archive' => TMP_DIR.'install/packages/'.$packageFile )); } @@ -1107,7 +1107,7 @@ class WCFSetup extends WCF { try { $archive = new PackageArchive(TMP_DIR.'install/packages/'.$packageFile); $archive->openArchive(); - self::$setupPackageName = $archive->getPackageInfo('packageName'); + self::$setupPackageName = $archive->getLocalizedPackageInfo('packageName'); $archive->getTar()->close(); break; } diff --git a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php index 7be3c9a433..ca56bf10b7 100644 --- a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php @@ -380,47 +380,12 @@ class PackageArchive { if (!isset($this->packageInfo['plugin'])) $this->packageInfo['plugin'] = ''; if (!isset($this->packageInfo['packageURL'])) $this->packageInfo['packageURL'] = ''; - // get package name in selected language - $this->getLocalizedInformation('packageName'); - - // get package description in selected language - if (isset($this->packageInfo['packageDescription'])) { - $this->getLocalizedInformation('packageDescription'); - } - - // get package license in selected language - if (isset($this->packageInfo['license'])) { - $this->getLocalizedInformation('license'); - } - - // get package information in selected language - if (isset($this->packageInfo['readme'])) { - $this->getLocalizedInformation('readme'); - } - // add plugin to requirements if ($this->packageInfo['plugin'] && !isset($this->requirements[$this->packageInfo['plugin']])) { $this->requirements[$this->packageInfo['plugin']] = array('name' => $this->packageInfo['plugin']); } } - /** - * Gets localized package information strings. - * - * @param string $key - */ - protected function getLocalizedInformation($key) { - if (isset($this->packageInfo[$key][WCF::getLanguage()->getFixedLanguageCode()])) { - $this->packageInfo[$key] = $this->packageInfo[$key][WCF::getLanguage()->getFixedLanguageCode()]; - } - else if (isset($this->packageInfo[$key]['default'])) { - $this->packageInfo[$key] = $this->packageInfo[$key]['default']; - } - else { - $this->packageInfo[$key] = array_shift($this->packageInfo[$key]); - } - } - /** * Downloads the package archive. * @@ -583,6 +548,23 @@ class PackageArchive { return null; } + /** + * Returns a localized information about this package. + * + * @param string $name + * @return mixed + */ + public function getLocalizedPackageInfo($name) { + if (isset($this->packageInfo[$name][WCF::getLanguage()->getFixedLanguageCode()])) { + return $this->packageInfo[$name][WCF::getLanguage()->getFixedLanguageCode()]; + } + else if (isset($this->packageInfo[$name]['default'])) { + return $this->packageInfo[$name]['default']; + } + + return $this->getPackageInfo($name); + } + /** * Returns a list of all requirements of this package. * diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 106bbc0250..eb2c7bc2b9 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -2,18 +2,22 @@ namespace wcf\system\package; use wcf\data\application\Application; use wcf\data\application\ApplicationEditor; +use wcf\data\language\category\LanguageCategory; use wcf\data\language\LanguageEditor; +use wcf\data\language\LanguageList; use wcf\data\option\OptionEditor; use wcf\data\package\installation\queue\PackageInstallationQueue; use wcf\data\package\installation\queue\PackageInstallationQueueEditor; use wcf\data\package\Package; use wcf\data\package\PackageEditor; use wcf\system\cache\CacheHandler; +use wcf\system\database\statement\PreparedStatement; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\SystemException; use wcf\system\form\container; use wcf\system\form\element; use wcf\system\form\FormDocument; +use wcf\system\language\LanguageFactory; use wcf\system\menu\acp\ACPMenu; use wcf\system\request\LinkHandler; use wcf\system\request\RouteHandler; @@ -207,6 +211,39 @@ 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( @@ -292,6 +329,62 @@ class PackageInstallationDispatcher { return $installationStep; } + /** + * Saves a localized package info. + * + * @param wcf\system\database\statement\PreparedStatement $statement + * @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) { + $infoValues = $this->getArchive()->getPackageInfo($infoName); + + // get default value for languages without specified information + $defaultValue = ''; + if (isset($infoValues['default'])) { + $defaultValue = $infoValues['default']; + } + else if (isset($infoValues['en'])) { + // fallback to English + $defaultValue = $infoValues['en']; + } + else if (isset($infoValues[WCF::getLanguage()->getFixedLanguageCode()])) { + // fallback to the language of the current user + $defaultValue = $infoValues[WCF::getLanguage()->getFixedLanguageCode()]; + } + else if ($infoName == 'packageName') { + // fallback to the package identifier for the package name + $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) { + $value = $defaultValue; + if (isset($infoValues[$language->languageCode])) { + $value = $infoValues[$language->languageCode]; + } + + $statement->execute(array( + $language->languageID, + 'wcf.acp.package.'.$infoName.'.package'.$package->packageID, + $value, + $languageCategory->languageCategoryID, + 1 + )); + } + } + /** * Sets parent package and rebuilds dependencies for both. */ @@ -706,7 +799,7 @@ class PackageInstallationDispatcher { if (empty($this->queue->packageName)) { $queueEditor = new PackageInstallationQueueEditor($this->queue); $queueEditor->update(array( - 'packageName' => $this->getArchive()->getPackageInfo('packageName') + 'packageName' => $this->getArchive()->getLocalizedPackageInfo('packageName') )); // reload queue diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php index 5592cfedd6..ef3bafe78f 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php @@ -393,9 +393,9 @@ class PackageInstallationNodeBuilder { 'package', serialize(array( 'package' => $this->installation->getArchive()->getPackageInfo('name'), - 'packageName' => $this->installation->getArchive()->getPackageInfo('packageName'), + 'packageName' => $this->installation->getArchive()->getLocalizedPackageInfo('packageName'), 'instanceNo' => $instanceNo, - 'packageDescription' => $this->installation->getArchive()->getPackageInfo('packageDescription'), + 'packageDescription' => $this->installation->getArchive()->getLocalizedPackageInfo('packageDescription'), 'packageVersion' => $this->installation->getArchive()->getPackageInfo('version'), 'packageDate' => $this->installation->getArchive()->getPackageInfo('date'), 'packageURL' => $this->installation->getArchive()->getPackageInfo('packageURL'), @@ -458,7 +458,7 @@ class PackageInstallationNodeBuilder { 'processNo' => $queue->processNo, 'userID' => WCF::getUser()->userID, 'package' => $archive->getPackageInfo('name'), - 'packageName' => $archive->getPackageInfo('packageName'), + 'packageName' => $archive->getLocalizedPackageInfo('packageName'), 'archive' => $fileName, 'action' => $queue->action )); @@ -561,7 +561,7 @@ class PackageInstallationNodeBuilder { $packages[] = array( 'archive' => $fileName, 'package' => $archive->getPackageInfo('name'), - 'packageName' => $archive->getPackageInfo('packageName'), + 'packageName' => $archive->getLocalizedPackageInfo('packageName'), 'selected' => 0 ); } diff --git a/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php index 08478aad3f..7831e55c5d 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUninstallationDispatcher.class.php @@ -91,6 +91,16 @@ class PackageUninstallationDispatcher extends PackageInstallationDispatcher { protected function uninstallPackage(array $nodeData) { PackageEditor::deleteAll(array($this->queue->packageID)); + // remove localized package infos + // todo: license/readme + $sql = "DELETE FROM wcf".WCF_N."_language_item + WHERE languageItem IN (?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + 'wcf.acp.package.packageName.package'.$this->queue->packageID, + 'wcf.acp.package.packageDescription.package'.$this->queue->packageID + )); + // reset package cache CacheHandler::getInstance()->clearResource('packages');