<commit_before><?php

/**
 * Class MaintenanceModeExtension
 *
 * @property Controller $owner
 */
class MaintenanceModeExtension extends Extension
{

    /**
     * @throws SS_HTTPResponse_Exception
     */
    public function onBeforeInit()
    {
        if($this->isDownForMaintenance())
        {
            $this->respond503();
        }
    }

    /**
     * @return bool
     */
    public function isDownForMaintenance()
    {
        return file_exists(BASE_PATH.'/mysite/down');
    }

    /**
     * Somehow $this->owner->httpError puts a burden on de Database.
     *
     * Maybe not very Silverstripe'sch, but at least this works
     */
    protected function respond503()
    {
        $message = 'Website is down for maintenance';
        $content = '<h1>'.$message.'</h1>';

        header($message, true, 503);

        $errorFile = $this->get503File();

        if(is_file($errorFile)) {
            $content = file_get_contents($errorFile);
        }

        echo $content;
        exit();
    }

    protected function get503File()
    {
        $custom = BASE_PATH.(string)Config::inst()->get('MaintenanceMode', 'file');

        if(is_file($custom)) {
            return $custom;
        }

        return BASE_PATH.'/assets/error-503.html';
    }

}<commit_msg>This 503 looks a little bit better...<commit_after><?php

/**
 * Class MaintenanceModeExtension.
 *
 * throw a 503 if mysite/down exists
 *
 * @property Controller $owner
 */
class MaintenanceModeExtension extends Extension
{

    /**
     * @throws SS_HTTPResponse_Exception
     */
    public function onBeforeInit()
    {
        if($this->isDownForMaintenance())
        {
            $this->throw503();
        }
    }

    /**
     * @return bool
     */
    public function isDownForMaintenance()
    {
        return file_exists(BASE_PATH.'/mysite/down');
    }

    /**
     * Somehow $this->owner->httpError keeps the website spinning.
     *
     * Maybe not very Silverstripe'sch, but at least this works
     *
     * @throws SS_HTTPResponse_Exception
     */
    protected function throw503()
    {
        $message   = 'Website is down for maintenance';
        $errorFile = $this->get503File();
        $content   = is_file($errorFile) ? file_get_contents($errorFile) : '<h1>'.$message.'</h1>';

        throw new SS_HTTPResponse_Exception(new SS_HTTPResponse($content, 503, $message));
    }

    /**
     * @return string
     */
    protected function get503File()
    {
        $custom = BASE_PATH.(string)Config::inst()->get('MaintenanceMode', 'file');

        return is_file($custom) ? $custom : BASE_PATH.'/assets/error-503.html';
    }
}
{'fraction_non_alphanumeric': 0.13401283503208758, 'fraction_numerical': 0.01736504341260853, 'mean_word_length': 2.259532595325953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '403616', 'n_tokens_mistral': 818, 'n_tokens_neox': 764, 'n_words': 160}