From: Alexander Ebert Date: Sun, 7 Feb 2016 17:45:05 +0000 (+0100) Subject: Added fail-safe mechanism for options, WCF is now an app X-Git-Tag: 3.0.0_Beta_1~2030^2~104 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b842faa18d3011eabd95a6d5e478f0e1a3ecd376;p=GitHub%2FWoltLab%2FWCF.git Added fail-safe mechanism for options, WCF is now an app --- diff --git a/wcfsetup/install/files/acp/global.php b/wcfsetup/install/files/acp/global.php index a107b52e09..5298236446 100644 --- a/wcfsetup/install/files/acp/global.php +++ b/wcfsetup/install/files/acp/global.php @@ -10,8 +10,8 @@ // 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'); diff --git a/wcfsetup/install/files/app.config.inc.php b/wcfsetup/install/files/app.config.inc.php new file mode 100644 index 0000000000..6d4a379e46 --- /dev/null +++ b/wcfsetup/install/files/app.config.inc.php @@ -0,0 +1,4 @@ + * @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'); diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 6ccde53af3..e079e80783 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -130,6 +130,9 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject } 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(); diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index a88a5c4133..68b191a2bd 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -1,7 +1,6 @@ * @package com.woltlab.wcf * @subpackage data.package @@ -346,23 +345,28 @@ class Package extends DatabaseObject { 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("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 = "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', "packageID); + } + if (file_exists($configPath)) { require_once($configPath); } diff --git a/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php index 3d8e1ad517..2a11d18318 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php @@ -8,7 +8,7 @@ use wcf\system\WCF; * Caches options and option categories * * @author Marcel Werk - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.cache.builder @@ -34,81 +34,44 @@ class OptionCacheBuilder extends AbstractCacheBuilder { 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; diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index a5384b6f38..3c64393e89 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -81,7 +81,7 @@ class PackageInstallationDispatcher { * 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 @@ -237,12 +237,10 @@ class PackageInstallationDispatcher { 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()) { diff --git a/wcfsetup/install/files/options.inc.php b/wcfsetup/install/files/options.inc.php index bef82c4cf6..c841ca222c 100644 --- a/wcfsetup/install/files/options.inc.php +++ b/wcfsetup/install/files/options.inc.php @@ -6,7 +6,6 @@ * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License */ -define('PACKAGE_ID', 0); define('LAST_UPDATE_TIME', TIME_NOW); define('COOKIE_PREFIX', 'wcf_'); @@ -37,3 +36,5 @@ define('EXTERNAL_LINK_TARGET_BLANK', 0); define('URL_LEGACY_MODE', 0); define('URL_TO_LOWERCASE', 1); define('SEARCH_ENGINE', 'mysql'); + +define('WCF_OPTION_INC_PHP_SUCCESS', true);