<commit_before><?php

namespace Rcms\Core;

use PDO;
use PDOException;

use Rcms\Core\Exception\NotFoundException;
use Rcms\Core\Widget\InstalledWidgets;

class Website {

    const MAX_SITE_OPTION_LENGTH = 200;
    const CONFIG_FILE = "config.php";
    const BASE_NAMESPACE = "Rcms\\";

    /** @var TablePrefixedPDO The main database */
    protected $databaseObject;

    /** @var Themes Themes object */
    protected $themesObject;

    /** @var Config Settings of the site. */
    protected $config;

    /** @var InstalledWidgets Widgets currently loaded. */
    protected $widgets;

    /** @var Authentication Handles authentication */
    protected $authenticationObject;

    /** @var Text Handles errors, messages and translations. */
    protected $text;

    /**
     * @deprecated For old page system. Errors are now always echoed after the
     * page is rendered, so old pages shouldn't try to display them themselves 
     */
    public $errorsDisplayed = true;

    /**
     * Constructs the Website. Page- and theme-specific logic won't be loaded yet.
     */
    function __construct() {
        // We're loaded (included files test for the existance this constant)
        define("WEBSITE", "Loaded");

        // Site settings and database connection
        $this->config = new Config(self::CONFIG_FILE);
        $this->text = new Text($this->getConfig()->get('url'), $this->getUriTranslations(Config::DEFAULT_LANGUAGE), $this->getUrlJavaScripts());

        // Connect to database, read settings
        try {
            $dataSource = "mysql:dbname={$this->config->get(Config::OPTION_DATABASE_NAME)};host={$this->config->get(Config::OPTION_DATABASE_HOST)}";
            $this->databaseObject = new TablePrefixedPDO($dataSource,
                    $this->config->get(Config::OPTION_DATABASE_USER),
                    $this->config->get(Config::OPTION_DATABASE_PASSWORD),
                    array("table_prefix" => $this->config->get(Config::OPTION_DATABASE_TABLE_PREFIX)));
            $this->databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->databaseObject->prefixTables(array("categorie", "users",
                "links", "artikel", "comments", "menus", "widgets", "documents",
                "settings", "gebruikers", "reacties"));
            
        } catch (PDOException $e) {
            // No database connection - safe to ignore this error, as the page
            // renderer will start the installation procedure, based on the lack
            // of settings
            $this->text->addError($this->text->tReplaced("install.no_database_connection", $e->getMessage()));
        }
        $this->config->readFromDatabase($this->databaseObject);

        // Set updated properties of Text object, now that settings are read
        // from the database
        $this->text->setTranslationsDirectory($this->getUriTranslations($this->config->get("language")));
        $this->text->setUrlRewrite($this->config->get("url_rewrite"));

        // Init other objects
        if ($this->databaseObject == null) {
            $this->authenticationObject = new Authentication($this, null);<commit_msg>Don't read settings from database if connection fails<commit_after><?php

namespace Rcms\Core;

use PDO;
use PDOException;

use Rcms\Core\Exception\NotFoundException;
use Rcms\Core\Widget\InstalledWidgets;

class Website {

    const MAX_SITE_OPTION_LENGTH = 200;
    const CONFIG_FILE = "config.php";
    const BASE_NAMESPACE = "Rcms\\";

    /** @var TablePrefixedPDO The main database */
    protected $databaseObject;

    /** @var Themes Themes object */
    protected $themesObject;

    /** @var Config Settings of the site. */
    protected $config;

    /** @var InstalledWidgets Widgets currently loaded. */
    protected $widgets;

    /** @var Authentication Handles authentication */
    protected $authenticationObject;

    /** @var Text Handles errors, messages and translations. */
    protected $text;

    /**
     * @deprecated For old page system. Errors are now always echoed after the
     * page is rendered, so old pages shouldn't try to display them themselves 
     */
    public $errorsDisplayed = true;

    /**
     * Constructs the Website. Page- and theme-specific logic won't be loaded yet.
     */
    function __construct() {
        // We're loaded (included files test for the existance this constant)
        define("WEBSITE", "Loaded");

        // Site settings and database connection
        $this->config = new Config(self::CONFIG_FILE);
        $this->text = new Text($this->getConfig()->get('url'), $this->getUriTranslations(Config::DEFAULT_LANGUAGE), $this->getUrlJavaScripts());

        // Connect to database, read settings
        try {
            $dataSource = "mysql:dbname={$this->config->get(Config::OPTION_DATABASE_NAME)};host={$this->config->get(Config::OPTION_DATABASE_HOST)}";
            $this->databaseObject = new TablePrefixedPDO($dataSource,
                    $this->config->get(Config::OPTION_DATABASE_USER),
                    $this->config->get(Config::OPTION_DATABASE_PASSWORD),
                    array("table_prefix" => $this->config->get(Config::OPTION_DATABASE_TABLE_PREFIX)));
            $this->databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->databaseObject->prefixTables(array("categorie", "users",
                "links", "artikel", "comments", "menus", "widgets", "documents",
                "settings", "gebruikers", "reacties"));
            $this->config->readFromDatabase($this->databaseObject);
        } catch (PDOException $e) {
            // No database connection - safe to ignore this error, as the page
            // renderer will start the installation procedure, based on the lack
            // of settings
            $this->text->addError($this->text->tReplaced("install.no_database_connection", $e->getMessage()));
        }

        // Set updated properties of Text object, now that settings are read
        // from the database
        $this->text->setTranslationsDirectory($this->getUriTranslations($this->config->get("language")));
        $this->text->setUrlRewrite($this->config->get("url_rewrite"));

        // Init other objects
        if ($this->databaseObject == null) {
            $this->authenticationObject = new Authentication($this, null);
{'fraction_non_alphanumeric': 0.12995767361655433, 'fraction_numerical': 0.0009405862987929142, 'mean_word_length': 2.9261538461538463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4763221', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1708, 'n_words': 432}