<commit_before><?php 
/*
Config Database Controller

Author: <NAME>
Url: http://denbeke.be
Date: July 2014
*/

namespace Database;

require_once(__DIR__ . '/../model/album.php');


/**
Config Database Controller
*/
class Config {

	const CONFIG = 'Config';


	/**
	Read the stored config data
	
	@return `['config_key' => 'config_value']`
	*/
	static public function read() {

		$query = BUILDER::table(self::CONFIG)->select('*');
		
		$result = $query->get();
		$output = [];

		foreach ($result as $item) {
			
			$output[$item->config_key] = $item->config_value;
			
		}

		return $output;

	}
	
	
	/**
	Save the given config data item in the database
	
	If the given config doesn't exist,
	a new entry will be created in the database.
	
	The function will store an array of config data items
		[
			'config_key' => 'config_value'
		]
		
	This makes it easy to save a batch of configuration options
	
	@param config data
	*/
	static public function save($config_data) {
		
		foreach ($config_data as $config_key => $config_value) {
			
			//TODO check for empty keys/values
			self::saveSingle($config_key, $config_value);
			
		}
		
	}
	
	
	/**
	Check if the given config item exists
	
	@param config key
	@return exists
	*/
	static public function exists($config_key) {
		
		$query = BUILDER::table(self::CONFIG)->where('config_key', '=', $config_key);
		$count = $query->count();
		
		if($count == 1) {
			return true;
		}
		else {
			return false;
		}
		
	}
	

	/**
	Save a single config item to the databases
	
	If the given config doesn't exist,
	a new entry will be created in the database.
	
	@param config key
	@param config value
	*/
	static private function saveSingle($config_key, $config_value) {
		
		if(!self::exists($config_key)) {
			
			//If not exists, we make new item
			$data = [
				'config_key' => $config_key,
				'config_value' => $config_value
			];
			
			BUILDER::table(self::CONFIG)->insert($data);
	
		}
		else {
			
			//Else, we update the item
			$data = [
				'config_value' => $config_value
			];
			
			BUILDER::table(self::CONFIG)->where('config_key', '=', $config_key)->update($data);
			
		}
		
		
		
	}


}



?><commit_msg>Checking for empty config keys/values<commit_after><?php 
/*
Config Database Controller

Author: <NAME>
Url: http://denbeke.be
Date: July 2014
*/

namespace Database;


/**
Config Database Controller
*/
class Config {

	const CONFIG = 'Config';


	/**
	Read the stored config data
	
	@return `['config_key' => 'config_value']`
	*/
	static public function read() {

		$query = BUILDER::table(self::CONFIG)->select('*');
		
		$result = $query->get();
		$output = [];

		foreach ($result as $item) {
			
			$output[$item->config_key] = $item->config_value;
			
		}

		return $output;

	}
	
	
	/**
	Save the given config data item in the database
	
	If the given config doesn't exist,
	a new entry will be created in the database.
	
	The function will store an array of config data items
		[
			'config_key' => 'config_value'
		]
		
	This makes it easy to save a batch of configuration options
	
	@param config data
	*/
	static public function save($config_data) {
		
		foreach ($config_data as $config_key => $config_value) {
			
			if($config_key == '' or $config_key == NULL) {
				throw new \exception('No config key given');	
			}
			elseif($config_value == '' or $config_value == NULL) {
				throw new \exception('No config value given');
			}
			else {
				self::saveSingle($config_key, $config_value);	
			}
			
		}
		
	}
	
	
	/**
	Check if the given config item exists
	
	@param config key
	@return exists
	*/
	static public function exists($config_key) {
		
		$query = BUILDER::table(self::CONFIG)->where('config_key', '=', $config_key);
		$count = $query->count();
		
		if($count == 1) {
			return true;
		}
		else {
			return false;
		}
		
	}
	

	/**
	Save a single config item to the databases
	
	If the given config doesn't exist,
	a new entry will be created in the database.
	
	@param config key
	@param config value
	*/
	static private function saveSingle($config_key, $config_value) {
		
		if(!self::exists($config_key)) {
			
			//If not exists, we make new item
			$data = [
				'config_key' => $config_key,
				'config_value' => $config_value
			];
			
			BUILDER::table(self::CONFIG)->insert($data);
	
		}
		else {
			
			//Else, we update the item
			$data = [
				'config_value' => $config_value
			];
			
			BUILDER::table(self::CONFIG)->where('config_key', '=', $config_key)->update($data);
			
		}
		
		
		
	}


}



?>
{'fraction_non_alphanumeric': 0.13968957871396895, 'fraction_numerical': 0.0022172949002217295, 'mean_word_length': 2.984982332155477, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, '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': '5751774', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1455, 'n_words': 420}