From: Tim Düsterhus Date: Mon, 8 Sep 2014 16:13:13 +0000 (+0200) Subject: Write language files atomically X-Git-Tag: 2.1.0_Alpha_1~344^2~32^2~1^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3b6c3ca449cfa5b1692d8bbb64fb2699c5932d10;p=GitHub%2FWoltLab%2FWCF.git Write language files atomically --- diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index 476e2d7ffd..92611f3b76 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -9,7 +9,7 @@ use wcf\data\IEditableCachedObject; use wcf\system\cache\builder\LanguageCacheBuilder; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\SystemException; -use wcf\system\io\File; +use wcf\system\io\AtomicWriter; use wcf\system\language\LanguageFactory; use wcf\system\Regex; use wcf\system\WCF; @@ -85,22 +85,27 @@ class LanguageEditor extends DatabaseObjectEditor implements IEditableCachedObje continue; } - $content = "languageCode."\n* encoding: UTF-8\n* category: ".$category->languageCategory."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n"; + $filename = WCF_DIR.'language/'.$this->languageID.'_'.$category->languageCategory.'.php'; + $writer = new AtomicWriter($filename); + + $writer->write("languageCode."\n* encoding: UTF-8\n* category: ".$category->languageCategory."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n"); foreach ($languageItems as $languageItem => $languageItemValue) { - $content .= "\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n"; + $writer->write("\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n"); // compile dynamic language variables if ($category->languageCategory != 'wcf.global' && strpos($languageItemValue, '{') !== false) { + $writer->write("\$this->dynamicItems['".$languageItem."'] = '"); + $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue); - $content .= "\$this->dynamicItems['".$languageItem."'] = '".str_replace("'", "\'", $output['template'])."';\n"; + $writer->write(str_replace("'", "\'", $output['template'])); + + $writer->write("';\n"); } } - $filename = WCF_DIR.'language/'.$this->languageID.'_'.$category->languageCategory.'.php'; - $file = new File($filename); + $writer->flush(); + $writer->close(); FileUtil::makeWritable($filename); - $file->write($content . '?>'); - $file->close(); } }