From 3b6c3ca449cfa5b1692d8bbb64fb2699c5932d10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 8 Sep 2014 18:13:13 +0200 Subject: [PATCH] Write language files atomically --- .../data/language/LanguageEditor.class.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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(); } } -- 2.20.1