From: Matthias Schmidt Date: Sat, 3 Nov 2012 12:01:51 +0000 (+0100) Subject: Makes cronjob descriptions multilingual X-Git-Tag: 2.0.0_Beta_1~821^2~2^2~1^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=099c2fd26f560feb05833abca1aa369ee528afb9;p=GitHub%2FWoltLab%2FWCF.git Makes cronjob descriptions multilingual --- diff --git a/com.woltlab.wcf/cronjob.xml b/com.woltlab.wcf/cronjob.xml index c94b823ff0..2e62fd179c 100644 --- a/com.woltlab.wcf/cronjob.xml +++ b/com.woltlab.wcf/cronjob.xml @@ -3,7 +3,8 @@ wcf\system\cronjob\GetUpdateInfoCronjob - Gets update package information + + 0 2 */2 @@ -16,7 +17,8 @@ wcf\system\cronjob\RefreshSearchRobotsCronjob - Refreshes list of search robots + + 0 3 1 @@ -29,7 +31,8 @@ wcf\system\cronjob\DailyCleanUpCronjob - Daily Cleanup + + 0 1 * @@ -42,7 +45,8 @@ wcf\system\cronjob\HourlyCleanUpCronjob - Hourly Cleanup + + 0 * * @@ -55,7 +59,8 @@ wcf\system\cronjob\SessionCleanUpCronjob - Deletes expired sessions + + */30 * * diff --git a/wcfsetup/install/files/acp/templates/cronjobAdd.tpl b/wcfsetup/install/files/acp/templates/cronjobAdd.tpl index 5a26b8746d..68347f4fc7 100644 --- a/wcfsetup/install/files/acp/templates/cronjobAdd.tpl +++ b/wcfsetup/install/files/acp/templates/cronjobAdd.tpl @@ -1,5 +1,7 @@ {include file='header' pageTitle='wcf.acp.cronjob.'|concat:$action} +{include file='multipleLanguageInputJavascript' elementIdentifier='description'} +

{lang}wcf.acp.cronjob.{$action}{/lang}

@@ -50,10 +52,19 @@ -
+
+ {if $errorField == 'description'} + + {if $errorType == 'empty' || $errorType == 'multilingual'} + {lang}wcf.global.form.error.{@$errorType}{/lang} + {else} + {lang}wcf.acp.cronjob.className.error.{@$errorType}{/lang} + {/if} + + {/if}
diff --git a/wcfsetup/install/files/acp/templates/cronjobList.tpl b/wcfsetup/install/files/acp/templates/cronjobList.tpl index 3376813380..dde82b51a9 100644 --- a/wcfsetup/install/files/acp/templates/cronjobList.tpl +++ b/wcfsetup/install/files/acp/templates/cronjobList.tpl @@ -113,11 +113,11 @@

{$cronjob->startDom|truncate:30:' ...'}

{$cronjob->startMonth|truncate:30:' ...'}

{$cronjob->startDow|truncate:30:' ...'}

- + {if $cronjob->isEditable()} -

{$cronjob->description|truncate:50:" ..."}

+

{$cronjob->description|language|truncate:50:" …"}

{else} -

{$cronjob->description|truncate:50:' ...'}

+

{$cronjob->description|language|truncate:50:' …'}

{/if} diff --git a/wcfsetup/install/files/acp/templates/cronjobLogList.tpl b/wcfsetup/install/files/acp/templates/cronjobLogList.tpl index cedd17c771..6c27ee2fd6 100644 --- a/wcfsetup/install/files/acp/templates/cronjobLogList.tpl +++ b/wcfsetup/install/files/acp/templates/cronjobLogList.tpl @@ -35,7 +35,7 @@

{@$cronjobLog->cronjobID}

{$cronjobLog->className}

-

{$cronjobLog->description}

+

{$cronjobLog->description|language}

{if $cronjobLog->success}

{@$cronjobLog->execTime|time} {lang}wcf.acp.cronjob.log.success{/lang}

{elseif $cronjobLog->error} @@ -46,7 +46,7 @@ {else} {/if} - + {event name='columns'} {/foreach} diff --git a/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php b/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php index 86565d9b75..512d963aef 100755 --- a/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php @@ -1,8 +1,10 @@ register('description'); + } + /** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); + I18nHandler::getInstance()->readValues(); + if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']); if (isset($_POST['description'])) $this->description = StringUtil::trim($_POST['description']); if (isset($_POST['startMinute'])) $this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']); @@ -106,6 +119,16 @@ class CronjobAddForm extends ACPForm { throw new UserInputException('className', 'doesNotExist'); } + // validate description + if (!I18nHandler::getInstance()->validateValue('description')) { + if (I18nHandler::getInstance()->isPlainValue('description')) { + throw new UserInputException('description'); + } + else { + throw new UserInputException('description', 'multilingual'); + } + } + try { CronjobUtil::validate($this->startMinute, $this->startHour, $this->startDom, $this->startMonth, $this->startDow); } @@ -140,6 +163,19 @@ class CronjobAddForm extends ACPForm { $this->objectAction = new CronjobAction(array(), 'create', array('data' => $data)); $this->objectAction->executeAction(); + + if (!I18nHandler::getInstance()->isPlainValue('description')) { + $returnValues = $this->objectAction->getReturnValues(); + $cronjobID = $returnValues['returnValues']->cronjobID; + I18nHandler::getInstance()->save('description', 'wcf.acp.cronjob.description.cronjob'.$cronjobID, 'wcf.acp.cronjob', $this->packageID); + + // update group name + $cronjobEditor = new CronjobEditor($returnValues['returnValues']); + $cronjobEditor->update(array( + 'description' => 'wcf.acp.cronjob.description.cronjob'.$cronjobID + )); + } + $this->saved(); // reset values @@ -158,6 +194,8 @@ class CronjobAddForm extends ACPForm { public function assignVariables() { parent::assignVariables(); + I18nHandler::getInstance()->assignVariables(); + WCF::getTPL()->assign(array( 'className' => $this->className, 'description' => $this->description, diff --git a/wcfsetup/install/files/lib/acp/form/CronjobEditForm.class.php b/wcfsetup/install/files/lib/acp/form/CronjobEditForm.class.php index db972ab3db..f63a31aecf 100755 --- a/wcfsetup/install/files/lib/acp/form/CronjobEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/CronjobEditForm.class.php @@ -3,6 +3,7 @@ namespace wcf\acp\form; use wcf\data\cronjob\Cronjob; use wcf\data\cronjob\CronjobAction; use wcf\system\exception\IllegalLinkException; +use wcf\system\language\I18nHandler; use wcf\system\WCF; /** @@ -59,6 +60,15 @@ class CronjobEditForm extends CronjobAddForm { public function save() { ACPForm::save(); + $this->description = 'wcf.acp.cronjob.description.cronjob'.$this->cronjob->cronjobID; + if (I18nHandler::getInstance()->isPlainValue('description')) { + I18nHandler::getInstance()->remove($this->description, 1); + $this->description = I18nHandler::getInstance()->getValue('description'); + } + else { + I18nHandler::getInstance()->save('description', $this->description, 'wcf.acp.cronjob', $this->cronjob->packageID); + } + // update cronjob $data = array( 'className' => $this->className, @@ -88,6 +98,8 @@ class CronjobEditForm extends CronjobAddForm { parent::readData(); if (empty($_POST)) { + I18nHandler::getInstance()->setOptions('description', $this->cronjob->packageID, $this->cronjob->description, 'wcf.acp.cronjob.description.cronjob\d+'); + $this->className = $this->cronjob->className; $this->description = $this->cronjob->description; $this->startMinute = $this->cronjob->startMinute; @@ -104,6 +116,8 @@ class CronjobEditForm extends CronjobAddForm { public function assignVariables() { parent::assignVariables(); + I18nHandler::getInstance()->assignVariables(!empty($_POST)); + WCF::getTPL()->assign(array( 'cronjobID' => $this->cronjobID, 'action' => 'edit' diff --git a/wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php b/wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php index 3e8de06bf4..56f5ca4194 100644 --- a/wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php +++ b/wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php @@ -1,13 +1,16 @@ * @package com.woltlab.wcf @@ -20,6 +23,90 @@ class CronjobEditor extends DatabaseObjectEditor implements IEditableCachedObjec */ protected static $baseClass = 'wcf\data\cronjob\Cronjob'; + /** + * @see wcf\data\IEditableObject::create() + */ + public static function create(array $parameters = array()) { + $descriptions = array(); + if (isset($parameters['description']) && is_array($parameters['description'])) { + if (count($parameters['description']) > 1) { + $descriptions = $parameters['description']; + $parameters['description'] = ''; + } + else { + $parameters['description'] = reset($parameters['description']); + } + } + + $cronjob = parent::create($parameters); + + // save cronjob description + if (!empty($descriptions)) { + // set default value + if (isset($descriptions[''])) { + $defaultValue = $descriptions['']; + } + else if (isset($descriptions['en'])) { + // fallback to English + $defaultValue = $descriptions['en']; + } + else if (isset($descriptions[WCF::getLanguage()->getFixedLanguageCode()])) { + // fallback to the language of the current user + $defaultValue = $descriptions[WCF::getLanguage()->getFixedLanguageCode()]; + } + else { + // fallback to first description + $defaultValue = reset($descriptions); + } + + // fetch data directly from database during framework installation + if (!PACKAGE_ID) { + $sql = "SELECT * + FROM wcf".WCF_N."_language_category + WHERE languageCategory = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array('wcf.acp.cronjob')); + $languageCategory = $statement->fetchObject('wcf\data\language\category\LanguageCategory'); + + $languages = new LanguageList(); + $languages->sqlLimit = 0; + $languages->readObjects(); + } + else { + $languages = LanguageFactory::getInstance()->getLanguages(); + $languageCategory = LanguageFactory::getInstance()->getCategory('wcf.acp.cronjob'); + } + + $sql = "INSERT INTO wcf".WCF_N."_language_item + (languageID, languageItem, languageItemValue, languageCategoryID, packageID) + VALUES (?, ?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + foreach ($languages as $language) { + $value = $defaultValue; + if (isset($descriptions[$language->languageCode])) { + $value = $descriptions[$language->languageCode]; + } + + $statement->execute(array( + $language->languageID, + 'wcf.acp.cronjob.description.cronjob'.$cronjob->cronjobID, + $value, + $languageCategory->languageCategoryID, + $cronjob->packageID + )); + } + + // update cronjob + $cronjobEditor = new CronjobEditor($cronjob); + $cronjobEditor->update(array( + 'description' => 'wcf.acp.cronjob.description.cronjob'.$cronjob->cronjobID + )); + } + + return $cronjob; + } + /** * @see wcf\data\IEditableCachedObject::resetCache() */ diff --git a/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php index e7ab80b13c..d4898e0a76 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php @@ -19,6 +19,22 @@ class CronjobPackageInstallationPlugin extends AbstractXMLPackageInstallationPlu */ public $className = 'wcf\data\cronjob\CronjobEditor'; + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::getElement() + */ + protected function getElement(\DOMXpath $xpath, array &$elements, \DOMElement $element) { + if ($element->tagName == 'description') { + if (!isset($elements['description'])) { + $elements['description'] = array(); + } + + $elements['description'][$element->getAttribute('language')] = $element->nodeValue; + } + else { + parent::getElement($xpath, $elements, $element); + } + } + /** * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete() */