// This constant is already set in each package which got an own config.inc.php
if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', '../');
-// define the wcf-root-dir
-define('WCF_DIR', dirname(dirname(__FILE__)).'/');
+// include config
+require_once(RELATIVE_WCF_DIR.'app.config.inc.php');
// starting wcf acp
require_once(WCF_DIR.'lib/system/WCF.class.php');
--- /dev/null
+<?php
+// com.woltlab.wcf (packageID 0 during WCFSetup)
+if (!defined('WCF_DIR')) define('WCF_DIR', __DIR__.'/');
+if (!defined('PACKAGE_ID')) define('PACKAGE_ID', 0);
<?php
/**
* @author Marcel Werk
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @category Community Framework
*/
-// ignore direct access
-if (!defined('PACKAGE_ID')) {
- define('PACKAGE_ID', 1);
- /* TODO:
- @header("HTTP/1.0 404 Not Found");
- exit;
- */
-}
-
-// define the wcf-root-dir
-define('WCF_DIR', dirname(__FILE__).'/');
+// include config
+require_once(__DIR__.'/app.config.inc.php');
// initiate wcf core
require_once(WCF_DIR.'lib/system/WCF.class.php');
}
unset($options);
+ // add a pseudo option that indicates that option file has been written properly
+ $writer->write("if (!defined('WCF_OPTION_INC_PHP_SUCCESS')) define('WCF_OPTION_INC_PHP_SUCCESS', true);");
+
// file footer
$writer->write("\n");
$writer->flush();
<?php
namespace wcf\data\package;
use wcf\data\DatabaseObject;
-use wcf\system\io\File;
use wcf\system\package\PackageInstallationDispatcher;
use wcf\system\WCF;
use wcf\util\FileUtil;
* Represents a package.
*
* @author Alexander Ebert
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage data.package
public static function writeConfigFile($packageID) {
$package = new Package($packageID);
$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir));
- $file = new File($packageDir.PackageInstallationDispatcher::CONFIG_FILE);
- $file->write("<?php\n");
+
$prefix = strtoupper(self::getAbbreviation($package->package));
- $file->write("// ".$package->package." (packageID ".$package->packageID.")\n");
- $file->write("if (!defined('".$prefix."_DIR')) define('".$prefix."_DIR', dirname(__FILE__).'/');\n");
- $file->write("if (!defined('RELATIVE_".$prefix."_DIR')) define('RELATIVE_".$prefix."_DIR', '');\n");
- $file->write("\n");
+ $content = "<?php\n";
+ $content .= "// {$package->package} (packageID {$packageID})\n";
+ $content .= "if (!defined('{$prefix}_DIR')) define('{$prefix}_DIR', __DIR__.'/');\n";
+ $content .= "if (!defined('PACKAGE_ID')) define('PACKAGE_ID', {$packageID});\n";
+ $content .= "if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '" . addcslashes($package->getName(), "'") . "');\n";
+ $content .= "if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '{$package->packageVersion}');\n";
+
+ if ($packageID != 1) {
+ $content .= "\n";
+ $content .= "// helper constants for applications\n";
+ $content .= "if (!defined('RELATIVE_{$prefix}_DIR')) define('RELATIVE_{$prefix}_DIR', '');\n";
+ $content .= "if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', RELATIVE_{$prefix}_DIR.'" . FileUtil::getRelativePath($packageDir, WCF_DIR) . "');\n";
+ }
- // write general information
- $file->write("// general info\n");
- $file->write("if (!defined('RELATIVE_WCF_DIR')) define('RELATIVE_WCF_DIR', RELATIVE_".$prefix."_DIR.'".FileUtil::getRelativePath($packageDir, WCF_DIR)."');\n");
- $file->write("if (!defined('PACKAGE_ID')) define('PACKAGE_ID', ".$packageID.");\n");
- $file->write("if (!defined('PACKAGE_NAME')) define('PACKAGE_NAME', '".str_replace("'", "\'", $package->getName())."');\n");
- $file->write("if (!defined('PACKAGE_VERSION')) define('PACKAGE_VERSION', '".$package->packageVersion."');\n");
+ file_put_contents($packageDir . PackageInstallationDispatcher::CONFIG_FILE, $content);
- // write end
- $file->close();
+ // add legacy config.inc.php file for backward compatibility
+ if ($packageID != 1 && !file_exists($packageDir.'config.inc.php')) {
+ file_put_contents($packageDir.'config.inc.php', "<?php" . "\n" . "require_once('".PackageInstallationDispatcher::CONFIG_FILE."');\n");
+ }
}
}
OptionEditor::rebuild();
}
require_once($filename);
+
+ // check if option file is complete and writable
+ if (PACKAGE_ID) {
+ if (!is_writable($filename)) {
+ FileUtil::makeWritable($filename);
+
+ if (!is_writable($filename)) {
+ throw new SystemException("The option file '" . $filename . "' is not writable.");
+ }
+ }
+
+ // check if a previous write operation was incomplete and force rebuilding
+ if (!defined('WCF_OPTION_INC_PHP_SUCCESS')) {
+ OptionEditor::rebuild();
+
+ require_once($filename);
+ }
+ }
}
/**
if (class_exists($className) && is_subclass_of($className, 'wcf\system\application\IApplication')) {
// include config file
$configPath = $packageDir . PackageInstallationDispatcher::CONFIG_FILE;
+
+ // TODO: this should be done during update instead, remove this before any public release
+ if (!file_exists($configPath)) {
+ Package::writeConfigFile($package->packageID);
+ }
+
if (file_exists($configPath)) {
require_once($configPath);
}
* Caches options and option categories
*
* @author Marcel Werk
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.cache.builder
protected $application = 'wcf';
/**
- * @see \wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
+ * @inheritDoc
*/
public function rebuild(array $parameters) {
- $data = array(
- 'categories' => array(),
- 'options' => array(),
- 'categoryStructure' => array(),
- 'optionToCategories' => array()
- );
+ $data = [
+ 'categories' => [],
+ 'options' => [],
+ 'categoryStructure' => [],
+ 'optionToCategories' => []
+ ];
// option categories
- // get all option categories and sort categories by priority
- $sql = "SELECT categoryName, categoryID
- FROM ".$this->application.WCF_N."_".$this->tableName."_category";
+ $sql = "SELECT *
+ FROM ".$this->application.WCF_N."_".$this->tableName."_category
+ ORDER BY showOrder";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $optionCategories = array();
- while ($row = $statement->fetchArray()) {
- $optionCategories[$row['categoryName']] = $row['categoryID'];
- }
-
- if (!empty($optionCategories)) {
- // get needed option categories
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("categoryID IN (?)", array($optionCategories));
-
- $sql = "SELECT option_category.*, package.packageDir
- FROM ".$this->application.WCF_N."_".$this->tableName."_category option_category
- LEFT JOIN wcf".WCF_N."_package package
- ON (package.packageID = option_category.packageID)
- ".$conditions."
- ORDER BY showOrder ASC";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditions->getParameters());
- while ($row = $statement->fetchArray()) {
- $data['categories'][$row['categoryName']] = new OptionCategory(null, $row);
- if (!isset($data['categoryStructure'][$row['parentCategoryName']])) {
- $data['categoryStructure'][$row['parentCategoryName']] = array();
- }
-
- $data['categoryStructure'][$row['parentCategoryName']][] = $row['categoryName'];
+ while ($category = $statement->fetchObject(OptionCategory::class)) {
+ $data['categories'][$category->categoryName] = $category;
+ if (!isset($data['categoryStructure'][$category->parentCategoryName])) {
+ $data['categoryStructure'][$category->parentCategoryName] = [];
}
+
+ $data['categoryStructure'][$category->parentCategoryName][] = $category->categoryName;
}
// options
- // get all options and sort options by priority
- $optionIDs = array();
- $sql = "SELECT optionName, optionID
- FROM ".$this->application.WCF_N."_".$this->tableName;
+ $sql = "SELECT *
+ FROM ".$this->application.WCF_N."_".$this->tableName."
+ ORDER BY showOrder";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- while ($row = $statement->fetchArray()) {
- $optionIDs[$row['optionName']] = $row['optionID'];
- }
-
- if (!empty($optionIDs)) {
- // get needed options
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("optionID IN (?)", array($optionIDs));
-
- $sql = "SELECT *
- FROM ".$this->application.WCF_N."_".$this->tableName."
- ".$conditions."
- ORDER BY showOrder ASC";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditions->getParameters());
- $optionClassName = $this->optionClassName;
- while ($row = $statement->fetchArray()) {
- $data['options'][$row['optionName']] = new $optionClassName(null, $row);
- if (!isset($data['optionToCategories'][$row['categoryName']])) {
- $data['optionToCategories'][$row['categoryName']] = array();
- }
-
- $data['optionToCategories'][$row['categoryName']][] = $row['optionName'];
+ while ($option = $statement->fetchObject($this->optionClassName)) {
+ $data['options'][$option->optionName] = $option;
+ if (!isset($data['optionToCategories'][$option->categoryName])) {
+ $data['optionToCategories'][$option->categoryName] = [];
}
+
+ $data['optionToCategories'][$option->categoryName][] = $option->optionName;
}
return $data;
* default name of the config file
* @var string
*/
- const CONFIG_FILE = 'config.inc.php';
+ const CONFIG_FILE = 'app.config.inc.php';
/**
* data of previous package in queue
wcf".WCF_N."_package package
WHERE queue.processNo = ?
AND package.packageID = queue.packageID
- AND package.packageID <> ?
AND package.isApplication = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([
$this->queue->processNo,
- 1,
1
]);
while ($row = $statement->fetchArray()) {
* @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-define('PACKAGE_ID', 0);
define('LAST_UPDATE_TIME', TIME_NOW);
define('COOKIE_PREFIX', 'wcf_');
define('URL_LEGACY_MODE', 0);
define('URL_TO_LOWERCASE', 1);
define('SEARCH_ENGINE', 'mysql');
+
+define('WCF_OPTION_INC_PHP_SUCCESS', true);