2 namespace wcf\data\option
;
3 use wcf\data\DatabaseObjectEditor
;
4 use wcf\data\IEditableCachedObject
;
5 use wcf\system\cache\CacheHandler
;
6 use wcf\system\io\File
;
11 * Provides functions to edit options.
13 * @author Alexander Ebert
14 * @copyright 2001-2012 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package com.woltlab.wcf
17 * @subpackage data.option
18 * @category Community Framework
20 class OptionEditor
extends DatabaseObjectEditor
implements IEditableCachedObject
{
22 * options cache file name
25 const FILENAME
= 'options.inc.php';
28 * @see wcf\data\DatabaseObjectDecorator::$baseClass
30 protected static $baseClass = 'wcf\data\option\Option';
33 * Imports the given options.
35 * @param array $options name to value
37 public static function import(array $options) {
39 $sql = "SELECT optionName, optionID
40 FROM wcf".WCF_N
."_option";
41 $statement = WCF
::getDB()->prepareStatement($sql);
42 $statement->execute();
44 while ($row = $statement->fetchArray()) {
45 $optionIDs[$row['optionName']] = $row['optionID'];
48 $newOptions = array();
49 foreach ($options as $name => $value) {
50 if (isset($optionIDs[$name])) {
51 $newOptions[$optionIDs[$name]] = $value;
55 self
::updateAll($newOptions);
59 * Updates the values of the given options.
61 * @param array $options id to value
63 public static function updateAll(array $options) {
64 $sql = "UPDATE wcf".WCF_N
."_option
67 $statement = WCF
::getDB()->prepareStatement($sql);
69 foreach ($options as $id => $value) {
70 $statement->execute(array(
76 // force a cache reset if options were changed
81 * @see wcf\data\IEditableCachedObject::resetCache()
83 public static function resetCache() {
85 CacheHandler
::getInstance()->clear(WCF_DIR
.'cache', 'cache.option.php');
87 // reset options.inc.php files
92 * Rebuilds the option file.
94 public static function rebuild() {
98 $buffer .= "<?php\n/**\n* generated at ".gmdate('r')."\n*/\n";
101 $options = Option
::getOptions();
102 foreach ($options as $optionName => $option) {
103 $buffer .= "if (!defined('".$optionName."')) define('".$optionName."', ".(($option->optionType
== 'boolean' ||
$option->optionType
== 'integer') ?
intval($option->optionValue
) : "'".addcslashes($option->optionValue
, "'\\")."'").");\n";
111 $file = new File(WCF_DIR
.'options.inc.php');
114 $file->write($buffer);