<commit_before><?php

require_once(dirname(__FILE__)."/globals.php");
require_once(dirname(__FILE__)."/db_query.php");

if (isset($_GET["action"])) {
		executeAction($_GET["action"]);
} else {
		drawOptions();
}

function executeAction($s_action) {
	if ($s_action == "save") {
			saveTables();
	} else if ($s_action == "load") {
			loadTables();
	} else if ($s_action == "save_common_data") {
			saveCommon_Data();
	} else if ($s_action == "load_common_data") {
			loadCommon_Data();
	}
}

function drawOptions() {
	echo "<form action='' method='GET'><input type='hidden' name='action' value='save'></input><input type='submit' value='Save Tables'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='load'></input><input type='submit' value='Update Tables'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='save_common_data'></input><input type='submit' value='Save Common_Data'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='load_common_data'></input><input type='submit' value='Update Common_Data'></input></form>";
}

function saveTables() {
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_new_tables = array("Tables"=>getTables());
	$a_tables = array_merge($a_tables, $a_new_tables);
	$s_tables = serialize($a_tables);
	file_put_contents($filename, $s_tables);
	echo "<pre>saved to file ".realpath($filename).":\n\nmodtime:\n".date("Y-m-d H:i:s",filemtime($filename))." (current time ".date("Y-m-d H:i:s").")\n\ncontents:\n".file_get_contents($filename)."</pre>";
}

function loadTables() {
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_file_tables = unserialize(file_get_contents($filename));
	$a_file_tables = $a_file_tables["Tables"];
	$a_tables = getTables();
	updateTables($a_tables, $a_file_tables);
}

function saveCommon_Data() {
	global $maindb;
	$a_common_data = getCommon_date();
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_tables = array_merge($a_tables, array("Common_Data"=>$a_common_data));
	file_put_contents($filename, serialize($a_tables));
	echo "<pre>saved to file ".realpath($filename).":\n\nmodtime:\n".date("Y-m-d H:i:s",filemtime($filename))." (current time ".date("Y-m-d H:i:s").")\n\ncontents:\n".file_get_contents($filename)."</pre>";	
}

function loadCommon_Data() {
	global $maindb;
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_common_data = $a_tables["Common_Data"];
	$a_curr_common_data = getCommon_date();
	updateCommon_Data($a_curr_common_data, $a_common_data);
}

function getCommon_date() {
	global $maindb;
	return array(
		array("name"=>"accesses", "index"=>"name", "rows"=>db_query("SELECT * FROM `{$maindb}`.`accesses`")),
		array("name"=>"buglog", "index"=>"id", "rows"=>db_query("SELECT * FROM `{$maindb}`.`buglog`")),
		array("name"=>"feedback", "index"=>"id", "rows"=>db_query("SELECT * FROM `{$maindb}`.`feedback`"))
	);
}<commit_msg>checking for successful write on database data updates<commit_after><?php

require_once(dirname(__FILE__)."/globals.php");
require_once(dirname(__FILE__)."/db_query.php");

if (isset($_GET["action"])) {
		executeAction($_GET["action"]);
} else {
		drawOptions();
}

function executeAction($s_action) {
	if ($s_action == "save") {
			saveTables();
	} else if ($s_action == "load") {
			loadTables();
	} else if ($s_action == "save_common_data") {
			saveCommon_Data();
	} else if ($s_action == "load_common_data") {
			loadCommon_Data();
	}
}

function drawOptions() {
	echo "<form action='' method='GET'><input type='hidden' name='action' value='save'></input><input type='submit' value='Save Tables'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='load'></input><input type='submit' value='Update Tables'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='save_common_data'></input><input type='submit' value='Save Common_Data'></input></form>
<form action='' method='GET'><input type='hidden' name='action' value='load_common_data'></input><input type='submit' value='Update Common_Data'></input></form>";
}

function saveTables() {
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_new_tables = array("Tables"=>getTables());
	$a_tables = array_merge($a_tables, $a_new_tables);
	$s_tables = serialize($a_tables);
	$success = file_put_contents($filename, $s_tables);
	if ($success === FALSE) {
			echo "<span style='color:red;'>ERROR:</span> failed to save file";
	} else {
			echo "<pre>saved to file ".realpath($filename).":\n\nmodtime:\n".date("Y-m-d H:i:s",filemtime($filename))." (current time ".date("Y-m-d H:i:s").")</pre>";
	}
	echo "<pre>\n\ncontents:\n".file_get_contents($filename)."</pre>";
}

function loadTables() {
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_file_tables = unserialize(file_get_contents($filename));
	$a_file_tables = $a_file_tables["Tables"];
	$a_tables = getTables();
	updateTables($a_tables, $a_file_tables);
}

function saveCommon_Data() {
	global $maindb;
	$a_common_data = getCommon_date();
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_tables = array_merge($a_tables, array("Common_Data"=>$a_common_data));
	$success = file_put_contents($filename, serialize($a_tables));
	if ($success === FALSE) {
			echo "<span style='color:red;'>ERROR:</span> failed to save file";
	} else {
			echo "<pre>saved to file ".realpath($filename).":\n\nmodtime:\n".date("Y-m-d H:i:s",filemtime($filename))." (current time ".date("Y-m-d H:i:s").")</pre>";
	}
	echo "<pre>\n\ncontents:\n".file_get_contents($filename)."</pre>";	
}

function loadCommon_Data() {
	global $maindb;
	$filename = dirname(__FILE__)."/../database_desc.txt";
	$a_tables = unserialize(file_get_contents($filename));
	$a_common_data = $a_tables["Common_Data"];
	$a_curr_common_data = getCommon_date();
	updateCommon_Data($a_curr_common_data, $a_common_data);
}

function getCommon_date() {
	global $maindb;
	return array(
		array("name"=>"accesses", "index"=>"name", "rows"=>db_query("SELECT * FROM `{$maindb}`.`accesses`")),
		array("name"=>"buglog", "index"=>"id", "rows"=>db_query("SELECT * FROM `{$maindb}`.`buglog`")),
		array("name"=>"feedback", "index"=>"id", "rows"=>db_query("SELECT * FROM `{$maindb}`.`feedback`"))
	);
}
{'fraction_non_alphanumeric': 0.2189736561595858, 'fraction_numerical': 0.0, 'mean_word_length': 7.230576441102757, 'pattern_counts': {'":': 4, '<': 69, '<?xml version=': 0, '>': 89, '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': '6801530', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2326, 'n_words': 365}