<commit_before><?php
/*
 * Copyright 2009-2013 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

class MY_Controller extends CI_Controller {
	public $data = array();
	public $var;

	protected $json_enabled_functions = array(
	);

	function __construct()
	{
		parent::__construct();

		$this->var = new StdClass();
		$csrf_protection = true;

		// check if DB is up to date
		if (!$this->input->is_cli_request()) {
			if (!$this->db->table_exists('migrations')){
				show_error("Database not initialized. Can't find migrations table. Please run the migration script.");
			} else {
				$this->config->load("migration", true);
				$target_version = $this->config->item("migration_version", "migration");

				// TODO: wait 20 seconds for an update so requests don't get lost for short updates?
				$row = $this->db->get('migrations')->row();

				$current_version = $row ? $row->version : 0;
				if ($current_version != $target_version) {
					show_error("Database version is $current_version, we want $target_version. Please run the migration script.");
				}
			}
		}

		$old_path = getenv("PATH");
		putenv("PATH=$old_path:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin");

		mb_internal_encoding('UTF-8');
		$this->load->helper(array('form', 'filebin'));

		// TODO: proper accept header handling or is this enough?
		if (isset($_SERVER["HTTP_ACCEPT"])) {
			if ($_SERVER["HTTP_ACCEPT"] == "application/json") {
				static_storage("response_type", "json");
			}
		}

		// Allow for easier testing in browser
		if ($this->input->get("json") !== false) {
			static_storage("response_type", "json");<commit_msg>Improve migration error message<commit_after><?php
/*
 * Copyright 2009-2013 Florian "Bluewind" Pritz <<EMAIL>>
 *
 * Licensed under AGPLv3
 * (see COPYING for full license text)
 *
 */

class MY_Controller extends CI_Controller {
	public $data = array();
	public $var;

	protected $json_enabled_functions = array(
	);

	function __construct()
	{
		parent::__construct();

		$this->var = new StdClass();
		$csrf_protection = true;

		// check if DB is up to date
		if (!$this->input->is_cli_request()) {
			if (!$this->db->table_exists('migrations')){
				show_error("Database not initialized. Can't find migrations table. Please run the migration script. (php index.php tools update_database)");
			} else {
				$this->config->load("migration", true);
				$target_version = $this->config->item("migration_version", "migration");

				// TODO: wait 20 seconds for an update so requests don't get lost for short updates?
				$row = $this->db->get('migrations')->row();

				$current_version = $row ? $row->version : 0;
				if ($current_version != $target_version) {
					show_error("Database version is $current_version, we want $target_version. Please run the migration script. (php index.php tools update_database)");
				}
			}
		}

		$old_path = getenv("PATH");
		putenv("PATH=$old_path:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin");

		mb_internal_encoding('UTF-8');
		$this->load->helper(array('form', 'filebin'));

		// TODO: proper accept header handling or is this enough?
		if (isset($_SERVER["HTTP_ACCEPT"])) {
			if ($_SERVER["HTTP_ACCEPT"] == "application/json") {
				static_storage("response_type", "json");
			}
		}

		// Allow for easier testing in browser
		if ($this->input->get("json") !== false) {
			static_storage("response_type", "json");
{'fraction_non_alphanumeric': 0.16464471403812825, 'fraction_numerical': 0.007510109763142692, 'mean_word_length': 4.122781065088757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '953409', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1090, 'n_words': 278}