Force overwriting of cronjob descriptions
authorAlexander Ebert <ebert@woltlab.com>
Wed, 12 Apr 2017 10:21:06 +0000 (12:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 12 Apr 2017 10:21:06 +0000 (12:21 +0200)
These phrases may already exist due to the import of existing language
files. Overwriting them at all times avoids issues in these cases and
saves us an extra roundtrip to manually delete them first.

wcfsetup/install/files/lib/data/cronjob/CronjobEditor.class.php

index 6225ee9909f13451b62208efd679d70d1e270bdb..9ee8f38101361d6240da18bcb978b8e4c9cd2e93 100644 (file)
@@ -46,7 +46,7 @@ class CronjobEditor extends DatabaseObjectEditor implements IEditableCachedObjec
                // save cronjob description
                if (!empty($descriptions)) {
                        $cronjobEditor = new self($cronjob);
-                       $cronjobEditor->saveDescriptions($descriptions, false);
+                       $cronjobEditor->saveDescriptions($descriptions);
                }
                
                /** @noinspection PhpIncompatibleReturnTypeInspection */
@@ -57,10 +57,9 @@ class CronjobEditor extends DatabaseObjectEditor implements IEditableCachedObjec
         * Saves the descriptions of the cronjob in language items.
         * 
         * @param       string[]                $descriptions
-        * @param       boolean                 $deleteOldDescriptions
         * @since       3.0
         */
-       protected function saveDescriptions(array $descriptions, $deleteOldDescriptions = true) {
+       protected function saveDescriptions(array $descriptions) {
                // set default value
                if (isset($descriptions[''])) {
                        $defaultValue = $descriptions[''];
@@ -95,18 +94,12 @@ class CronjobEditor extends DatabaseObjectEditor implements IEditableCachedObjec
                        $languageCategory = LanguageFactory::getInstance()->getCategory('wcf.acp.cronjob');
                }
                
-               // delete old descriptions first
-               if ($deleteOldDescriptions) {
-                       $sql = "DELETE FROM     wcf".WCF_N."_language_item
-                               WHERE           languageItem = ?";
-                       $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(['wcf.acp.cronjob.description.cronjob'.$this->cronjobID]);
-               }
-               
                // save new descriptions
-               $sql = "INSERT INTO     wcf".WCF_N."_language_item
-                                       (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
-                       VALUES          (?, ?, ?, ?, ?)";
+               $sql = "INSERT INTO             wcf".WCF_N."_language_item
+                                               (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
+                       VALUES                  (?, ?, ?, ?, ?)
+                       ON DUPLICATE KEY UPDATE languageItemValue = VALUES(languageItemValue),
+                                               languageCategoryID = VALUES(languageCategoryID)";
                $statement = WCF::getDB()->prepareStatement($sql);
                
                foreach ($languages as $language) {