Makes cronjob descriptions multilingual
authorMatthias Schmidt <gravatronics@live.com>
Sat, 3 Nov 2012 12:01:51 +0000 (13:01 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 3 Nov 2012 12:01:51 +0000 (13:01 +0100)
com.woltlab.wcf/cronjob.xml
wcfsetup/install/files/acp/templates/cronjobAdd.tpl
wcfsetup/install/files/acp/templates/cronjobList.tpl
wcfsetup/install/files/acp/templates/cronjobLogList.tpl
wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php
wcfsetup/install/files/lib/acp/form/CronjobEditForm.class.php
wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php
wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php

index c94b823ff036a3f8954924a691d71f870143d686..2e62fd179c90414b91a8653cc7b1c1e317bcd805 100644 (file)
@@ -3,7 +3,8 @@
        <import>
                <cronjob>
                        <classname>wcf\system\cronjob\GetUpdateInfoCronjob</classname>
-                       <description>Gets update package information</description>
+                       <description><![CDATA[Updates package information]]></description>
+                       <description language="de"><![CDATA[Aktualisiert Paket-Informationen]]></description>
                        <startminute>0</startminute>
                        <starthour>2</starthour>
                        <startdom>*/2</startdom>
@@ -16,7 +17,8 @@
                
                <cronjob>
                        <classname>wcf\system\cronjob\RefreshSearchRobotsCronjob</classname>
-                       <description>Refreshes list of search robots</description>
+                       <description><![CDATA[Refreshes list of search robots]]></description>
+                       <description language="de"><![CDATA[Aktualisiert die Liste der Suchroboter]]></description>
                        <startminute>0</startminute>
                        <starthour>3</starthour>
                        <startdom>1</startdom>
@@ -29,7 +31,8 @@
                
                <cronjob>
                        <classname>wcf\system\cronjob\DailyCleanUpCronjob</classname>
-                       <description>Daily Cleanup</description>
+                       <description><![CDATA[Executes daily Cleanup]]></description>
+                       <description language="de"><![CDATA[Führt tägliche Aufräumarbeiten aus]]></description>
                        <startminute>0</startminute>
                        <starthour>1</starthour>
                        <startdom>*</startdom>
@@ -42,7 +45,8 @@
                
                <cronjob>
                        <classname>wcf\system\cronjob\HourlyCleanUpCronjob</classname>
-                       <description>Hourly Cleanup</description>
+                       <description><![CDATA[Executes hourly Cleanup]]></description>
+                       <description language="de"><![CDATA[Führt stündliche Aufräumarbeiten aus]]></description>
                        <startminute>0</startminute>
                        <starthour>*</starthour>
                        <startdom>*</startdom>
@@ -55,7 +59,8 @@
                
                <cronjob>
                        <classname>wcf\system\cronjob\SessionCleanUpCronjob</classname>
-                       <description>Deletes expired sessions</description>
+                       <description><![CDATA[Deletes expired sessions]]></description>
+                       <description language="de"><![CDATA[Löscht abgelaufene Sessions]]></description>
                        <startminute>*/30</startminute>
                        <starthour>*</starthour>
                        <startdom>*</startdom>
index 5a26b8746dd7b758e37107a0b48c556d6a4add4b..68347f4fc7ff70c8c8bb37bba64b8aced8110b63 100644 (file)
@@ -1,5 +1,7 @@
 {include file='header' pageTitle='wcf.acp.cronjob.'|concat:$action}
 
+{include file='multipleLanguageInputJavascript' elementIdentifier='description'}
+
 <header class="boxHeadline">
        <hgroup>
                <h1>{lang}wcf.acp.cronjob.{$action}{/lang}</h1>
                                </dd>
                        </dl>
                        
-                       <dl>
+                       <dl{if $errorField == 'description'} class="formError"{/if}>
                                <dt><label for="description">{lang}wcf.acp.cronjob.description{/lang}</label></dt>
                                <dd>
                                        <input type="text" id="description" name="description" value="{$description}" class="long" />
+                                       {if $errorField == 'description'}
+                                               <small class="innerError">
+                                                       {if $errorType == 'empty' || $errorType == 'multilingual'}
+                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
+                                                       {else}
+                                                               {lang}wcf.acp.cronjob.className.error.{@$errorType}{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
                                </dd>
                        </dl>
                        
index 3376813380254a6252e327c785759f580ea8dee2..dde82b51a93061741c8aa5add98f31509c17ea9b 100644 (file)
                                                        <td class="columnDate columnStartDom"><p>{$cronjob->startDom|truncate:30:' ...'}</p></td>
                                                        <td class="columnDate columnStartMonth"><p>{$cronjob->startMonth|truncate:30:' ...'}</p></td>
                                                        <td class="columnDate columnStartDow"><p>{$cronjob->startDow|truncate:30:' ...'}</p></td>
-                                                       <td class="columnText columnDescription" title="{$cronjob->description}">
+                                                       <td class="columnText columnDescription" title="{$cronjob->description|language}">
                                                                {if $cronjob->isEditable()}
-                                                                       <p><a title="{lang}wcf.acp.cronjob.edit{/lang}" href="{link controller='CronjobEdit' id=$cronjob->cronjobID}{/link}">{$cronjob->description|truncate:50:" ..."}</a></p>
+                                                                       <p><a title="{lang}wcf.acp.cronjob.edit{/lang}" href="{link controller='CronjobEdit' id=$cronjob->cronjobID}{/link}">{$cronjob->description|language|truncate:50:" …"}</a></p>
                                                                {else}
-                                                                       <p>{$cronjob->description|truncate:50:' ...'}</p>
+                                                                       <p>{$cronjob->description|language|truncate:50:' …'}</p>
                                                                {/if}
                                                        </td>
                                                        <td class="columnDate columnNextExec">
index cedd17c771cd44d5608c22cb6cdcdebdaaa78e4d..6c27ee2fd628203042c6a4c4f7ec011af4646a16 100644 (file)
@@ -35,7 +35,7 @@
                                                        <tr>
                                                                <td class="columnID columnCronjobID"><p>{@$cronjobLog->cronjobID}</p></td>
                                                                <td class="columnTitle columnClassName"><p>{$cronjobLog->className}</p></td>
-                                                               <td class="columnText columnDescription"><p>{$cronjobLog->description}</p></td>
+                                                               <td class="columnText columnDescription"><p>{$cronjobLog->description|language}</p></td>
                                                                {if $cronjobLog->success}
                                                                        <td class="columnDate columnExecTime"><p>{@$cronjobLog->execTime|time} {lang}wcf.acp.cronjob.log.success{/lang}</p></td>
                                                                {elseif $cronjobLog->error}
@@ -46,7 +46,7 @@
                                                                {else}
                                                                        <td class="columnDate columnExecTime"></td>
                                                                {/if}
-                                                       
+                                                               
                                                                {event name='columns'}
                                                        </tr>
                                                {/foreach}
index 86565d9b75e57c671498ab38167c70d19a7fc8a4..512d963aef280d7db5eab088eaf046150fe970ff 100755 (executable)
@@ -1,8 +1,10 @@
 <?php
 namespace wcf\acp\form;
 use wcf\data\cronjob\CronjobAction;
+use wcf\data\cronjob\CronjobEditor;
 use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
+use wcf\system\language\I18nHandler;
 use wcf\system\WCF;
 use wcf\util\CronjobUtil;
 use wcf\util\StringUtil;
@@ -76,12 +78,23 @@ class CronjobAddForm extends ACPForm {
         */
        public $startDow = '*';
        
+       /**
+        * @see wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               I18nHandler::getInstance()->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,
index db972ab3dbf04abbe6ab362ad5d25fd5f87420ac..f63a31aecf9b7d5dccaf5f312e758e78e2fa045b 100755 (executable)
@@ -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'
index 3e8de06bf40b89d7ff92cdf78e275292d07c3a6d..56f5ca41940d5443cd359b1ead73211664c970a5 100644 (file)
@@ -1,13 +1,16 @@
 <?php
 namespace wcf\data\cronjob;
+use wcf\data\language\LanguageList;
 use wcf\data\DatabaseObjectEditor;
 use wcf\data\IEditableCachedObject;
 use wcf\system\cache\CacheHandler;
+use wcf\system\language\LanguageFactory;
+use wcf\system\WCF;
 
 /**
  * Provides functions to edit cronjobs.
  * 
- * @author     Alexander Ebert
+ * @author     Alexander Ebert, Matthias Schmidt
  * @copyright  2001-2012 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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()
         */
index e7ab80b13c7640b9349caf8b288d6a68794b0b3c..d4898e0a76b91e00e71bb2c0bbf3dab0088c015b 100644 (file)
@@ -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()
         */