<commit_before><?php

namespace app\libraries;

use app\authentication\AbstractAuthentication;
use app\exceptions\AuthenticationException;
use app\exceptions\CurlException;
use app\libraries\database\DatabaseFactory;
use app\libraries\database\AbstractDatabase;
use app\libraries\database\DatabaseQueries;
use app\libraries\database\DatabaseUtils;
use app\models\Config;
use app\models\User;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class Core
 *
 * This is the core of the application that contains references to the other main
 * libraries (such as Database, Session, etc.) that the application relies on.
 */
class Core {
    /**
     * @var \app\models\Config
     */
    private $config = null;

    /** @var AbstractDatabase */
    private $submitty_db = null;

    /** @var AbstractDatabase */
    private $course_db = null;

    /** @var EntityManager */
    private $submitty_entity_manager;

    /** @var DebugStack */
    private $submitty_debug_stack;

    /** @var EntityManager */
    private $course_entity_manager;

    /** @var DebugStack */
    private $course_debug_stack;

    /** @var AbstractAuthentication */
    private $authentication;

    /** @var SessionManager */
    private $session_manager;

    /** @var DatabaseFactory */
    private $database_factory;

    /** @var DatabaseQueries */
    private $database_queries;

    /** @var User */
    private $user = null;

    /** @var string */
    private $user_id = null;

    /** @var Output */
    private $output = null;

    /** @var GradingQueue */
    private $grading_queue = null;

    /** @var Access $access */
    private $access = null;

    /** @var NotificationFactory */
    private $notification_factory;
    /** @var bool */
    private $redirect = true;

    /** @var bool */
    private $testing = false;


    /**
     * Core constructor.
     *
     * This sets up our core for usage, by starting up our Output class as well as any $_SESSION variables that we
     * need. This should be called first, then loadConfig() and then loadDatabases().
     */
    public function __construct() {
        $this->setOutput(new Output($this));
        $this->access = new Access($this);

        // initialize our alert queue if it doesn't exist
        if (!isset($_SESSION['messages'])) {
            $_SESSION['messages'] = [];
        }

        // initialize our alert types if one of them doesn't exist
        foreach (['error', 'notice', 'success'] as $key) {
            if (!isset($_SESSION['messages'][$key])) {
                $_SESSION['messages'][$key] = [];
            }
        }

        // we cast each of our controller markers to lower to normalize our controller switches
        // and prevent any unexpected page failures for users in entering a capitalized controller
        foreach (['component', 'page', 'action'] as $key) {
            $_REQUEST[$key] = (isset($_REQUEST[$key])) ? strtolower($_REQUEST[$key]) : "";
        }
        $this->notification_factory = new NotificationFactory($this);
    }

    /**
     * Disable all redirects for API calls.
     */
    public function disableRedirects() {
        $this->redirect = false;
    }

    /**
     * Load the config details for the application. This takes in a file from the ../../../config as well as
     * then a config.json contained in {$SUBMITTY_DATA_DIR}/courses/{$SEMESTER}/{$COURSE}/config directory. These
     * files contain details about how the database, location of files, late days settings, etc.
     *
     * Config model will throw exceptions if we cannot find a given $semester or $course on the filesystem.
     *
     * @param string $semester
     * @param string $course
     * @throws \Exception
     */
    public function loadCourseConfig($semester, $course) {
        if ($this->config === null) {
            throw new \Exception("Master config has not been loaded");
        }
        if (!empty($semester) && !empty($course)) {
            $course_path = FileUtils::joinPaths($this->config->getSubmittyPath(), "courses", $semester, $course);
            $course_json_path = FileUtils::joinPaths($course_path, "config", "config.json");
            if (file_exists($course_json_path) && is_readable($course_json_path)) {
                $this->config->loadCourseJson($semester, $course, $course_json_path);
            }
            else {
                $message = "Unable to access configuration file " . $course_json_path . " for " .
                  $semester . " " . $course . " please contact your system administrator.\n" .
                  "If this is a new course, the error might be solved by restarting php-fpm:\n" .
                  "sudo service php7.2-fpm restart";
                $this->addErrorMessage($message);
            }
        }
    }

    public function loadMasterConfig() {
        $conf_path = FileUtils::joinPaths(__DIR__, '..', '..', '..', 'config');

        $this->setConfig(new Config($this));
        $this->config->loadMasterConfigs($conf_path);
    }

    public function setConfig(Config $config): void {
        $this->config = $config;
    }<commit_msg>[Bugfix:Developer] Update config.json error message (#8145)<commit_after><?php

namespace app\libraries;

use app\authentication\AbstractAuthentication;
use app\exceptions\AuthenticationException;
use app\exceptions\CurlException;
use app\libraries\database\DatabaseFactory;
use app\libraries\database\AbstractDatabase;
use app\libraries\database\DatabaseQueries;
use app\libraries\database\DatabaseUtils;
use app\models\Config;
use app\models\User;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class Core
 *
 * This is the core of the application that contains references to the other main
 * libraries (such as Database, Session, etc.) that the application relies on.
 */
class Core {
    /**
     * @var \app\models\Config
     */
    private $config = null;

    /** @var AbstractDatabase */
    private $submitty_db = null;

    /** @var AbstractDatabase */
    private $course_db = null;

    /** @var EntityManager */
    private $submitty_entity_manager;

    /** @var DebugStack */
    private $submitty_debug_stack;

    /** @var EntityManager */
    private $course_entity_manager;

    /** @var DebugStack */
    private $course_debug_stack;

    /** @var AbstractAuthentication */
    private $authentication;

    /** @var SessionManager */
    private $session_manager;

    /** @var DatabaseFactory */
    private $database_factory;

    /** @var DatabaseQueries */
    private $database_queries;

    /** @var User */
    private $user = null;

    /** @var string */
    private $user_id = null;

    /** @var Output */
    private $output = null;

    /** @var GradingQueue */
    private $grading_queue = null;

    /** @var Access $access */
    private $access = null;

    /** @var NotificationFactory */
    private $notification_factory;
    /** @var bool */
    private $redirect = true;

    /** @var bool */
    private $testing = false;


    /**
     * Core constructor.
     *
     * This sets up our core for usage, by starting up our Output class as well as any $_SESSION variables that we
     * need. This should be called first, then loadConfig() and then loadDatabases().
     */
    public function __construct() {
        $this->setOutput(new Output($this));
        $this->access = new Access($this);

        // initialize our alert queue if it doesn't exist
        if (!isset($_SESSION['messages'])) {
            $_SESSION['messages'] = [];
        }

        // initialize our alert types if one of them doesn't exist
        foreach (['error', 'notice', 'success'] as $key) {
            if (!isset($_SESSION['messages'][$key])) {
                $_SESSION['messages'][$key] = [];
            }
        }

        // we cast each of our controller markers to lower to normalize our controller switches
        // and prevent any unexpected page failures for users in entering a capitalized controller
        foreach (['component', 'page', 'action'] as $key) {
            $_REQUEST[$key] = (isset($_REQUEST[$key])) ? strtolower($_REQUEST[$key]) : "";
        }
        $this->notification_factory = new NotificationFactory($this);
    }

    /**
     * Disable all redirects for API calls.
     */
    public function disableRedirects() {
        $this->redirect = false;
    }

    /**
     * Load the config details for the application. This takes in a file from the ../../../config as well as
     * then a config.json contained in {$SUBMITTY_DATA_DIR}/courses/{$SEMESTER}/{$COURSE}/config directory. These
     * files contain details about how the database, location of files, late days settings, etc.
     *
     * Config model will throw exceptions if we cannot find a given $semester or $course on the filesystem.
     *
     * @param string $semester
     * @param string $course
     * @throws \Exception
     */
    public function loadCourseConfig($semester, $course) {
        if ($this->config === null) {
            throw new \Exception("Master config has not been loaded");
        }
        if (!empty($semester) && !empty($course)) {
            $course_path = FileUtils::joinPaths($this->config->getSubmittyPath(), "courses", $semester, $course);
            $course_json_path = FileUtils::joinPaths($course_path, "config", "config.json");
            if (file_exists($course_json_path) && is_readable($course_json_path)) {
                $this->config->loadCourseJson($semester, $course, $course_json_path);
            }
            else {
                $message = "Unable to access configuration file " . $course_json_path . " for " .
                  $semester . " " . $course . " please contact your system administrator.\n" .
                  "If this is a new course, the error might be solved by restarting php-fpm:\n" .
                  "sudo service php7.4-fpm restart";
                $this->addErrorMessage($message);
            }
        }
    }

    public function loadMasterConfig() {
        $conf_path = FileUtils::joinPaths(__DIR__, '..', '..', '..', 'config');

        $this->setConfig(new Config($this));
        $this->config->loadMasterConfigs($conf_path);
    }

    public function setConfig(Config $config): void {
        $this->config = $config;
    }
{'fraction_non_alphanumeric': 0.12724322260404736, 'fraction_numerical': 0.0007636502481863307, 'mean_word_length': 2.5599728168535507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6172231', 'n_tokens_mistral': 2926, 'n_tokens_neox': 2798, 'n_words': 839}