<commit_before><?php

class SpotUpgrader {
	private $_db;
	private $_dbEngine;
	
	function __construct($dbSettings, $phpSettings) {
		$this->_db = new SpotDb($dbSettings);
		$this->_db->connect();
		$this->_dbEngine = $dbSettings['engine'];
		$this->_phpSettings = $phpSettings;
	} # ctor
	
	/*
	 * Upgrade de settings
	 */
	function settings() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotSettingsUpgrader = new SpotSettingsUpgrader($this->_db, $settings);
		$spotSettingsUpgrader->update();
	} # settings

	/*
	 * Upgrade de users
	 */
	function users() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->update();
	} # users
	 
	/*
	 * Creeert en upgrade de database
	 */
	function database() {
		# Instantieeer een struct object
		switch($this->_dbEngine) {	
			case 'mysql'			:
			case 'pdo_mysql'		: $dbStruct = new SpotStruct_mysql($this->_db); break;

			case 'pdo_pgsql'		: $dbStruct = new SpotStruct_pgsql($this->_db); break;
			
			case 'pdo_sqlite'		: $dbStruct = new SpotStruct_sqlite($this->_db); break;
			
			default					: throw new Exception("Unknown database engine");
		} # switch
		
		$dbStruct->updateSchema();
	 } # database

	/*
	 * Optimaliseert de database
	 */
	function analyze() {
		# Instantieeer een struct object
		switch($this->_dbEngine) {	
			case 'mysql'			:
			case 'pdo_mysql'		: $dbStruct = new SpotStruct_mysql($this->_db); break;
			
			case 'pdo_pgsql'		: $dbStruct = new SpotStruct_pgsql($this->_db); break;
			
			case 'pdo_sqlite'		: $dbStruct = new SpotStruct_sqlite($this->_db); break;
			
			default					: throw new Exception("Unknown database engine");
		} # switch
		
		$dbStruct->analyze();
	 } # analyze

	/*
	 * Reset users' group membership
	 */
	function resetUserGroupMembership() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->resetUserGroupMembership($settings->get('systemtype'));
	} # resetUserGroupMembership

	/*
	 * Reset securitygroup settings to their default
	 */
	function resetSecurityGroups() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->updateSecurityGroups(true);
	} # resetSecurityGroups

	/*
	 * Reset securitygroup settings to their default
	 */
	function resetFilters() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->updateUserFilters(true);
	} # resetFilters
	 
	/*
	 * Reset a systems' type to the given setting
	 */
	function resetSystemType($systemType) {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotSettingsUpgrader = new SpotSettingsUpgrader($this->_db, $settings);

		# change the systems' type
		$spotSettingsUpgrader->setSystemType($systemType);
		
		# and reset all the users' group memberships for all users to match
		$spotUserUpgrader->resetUserGroupMembership($systemType);
	} # resetSystemType

	/*
	 * Reset a users' password
	 */
	function resetPassword($username) {<commit_msg>Add this to the generic code upgrade path as well<commit_after><?php

class SpotUpgrader {
	private $_db;
	private $_dbEngine;
	
	function __construct($dbSettings, $phpSettings) {
		$this->_db = new SpotDb($dbSettings);
		$this->_db->connect();
		$this->_dbEngine = $dbSettings['engine'];
		$this->_phpSettings = $phpSettings;
	} # ctor
	
	/*
	 * Upgrade de settings
	 */
	function settings() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotSettingsUpgrader = new SpotSettingsUpgrader($this->_db, $settings);
		$spotSettingsUpgrader->update();
	} # settings

	/*
	 * Upgrade de users
	 */
	function users() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->update();
	} # users
	 
	/*
	 * Creeert en upgrade de database
	 */
	function database() {
		# Instantieeer een struct object
		switch($this->_dbEngine) {	
			case 'mysql'			:
			case 'pdo_mysql'		: $dbStruct = new SpotStruct_mysql($this->_db); break;

			case 'pdo_pgsql'		: $dbStruct = new SpotStruct_pgsql($this->_db); break;
			
			case 'pdo_sqlite'		: $dbStruct = new SpotStruct_sqlite($this->_db); break;
			
			default					: throw new Exception("Unknown database engine");
		} # switch
		
		$dbStruct->updateSchema();
	 } # database

	/*
	 * Optimaliseert de database
	 */
	function analyze() {
		# Instantieeer een struct object
		switch($this->_dbEngine) {	
			case 'mysql'			:
			case 'pdo_mysql'		: $dbStruct = new SpotStruct_mysql($this->_db); break;
			
			case 'pdo_pgsql'		: $dbStruct = new SpotStruct_pgsql($this->_db); break;
			
			case 'pdo_sqlite'		: $dbStruct = new SpotStruct_sqlite($this->_db); break;
			
			default					: throw new Exception("Unknown database engine");
		} # switch
		
		$dbStruct->analyze();
	 } # analyze

	/*
	 * Reset users' group membership
	 */
	function resetUserGroupMembership() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->resetUserGroupMembership($settings->get('systemtype'));
	} # resetUserGroupMembership

	/*
	 * Reset securitygroup settings to their default
	 */
	function resetSecurityGroups() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->updateSecurityGroups(true);
	} # resetSecurityGroups

	/*
	 * Reset users' filters settings to their default
	 */
	function resetFilters() {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotUserUpgrader->updateUserFilters(true);
	} # resetFilters
	 
	/*
	 * Perform a mass change for users' preferences
	 */
	function massChangeUserPreferences($prefName, $prefValue) {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_daoFactory->getSettingDao(), 
											$this->_daoFactory->getBlackWhiteListDao(),
											$this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_daoFactory, $settings);
		$spotUserUpgrader->massChangeUserPreferences($prefValue, $prefName);
	} # massChangeUserPreferences

	/*
	 * Reset a systems' type to the given setting
	 */
	function resetSystemType($systemType) {
		# Create the settings object
		$settings = SpotSettings::singleton($this->_db, $this->_phpSettings);
		$spotUserUpgrader = new SpotUserUpgrader($this->_db, $settings);
		$spotSettingsUpgrader = new SpotSettingsUpgrader($this->_db, $settings);

		# change the systems' type
		$spotSettingsUpgrader->setSystemType($systemType);
		
		# and reset all the users' group memberships for all users to match
		$spotUserUpgrader->resetUserGroupMembership($systemType);
	} # resetSystemType

	/*
	 * Reset a users' password
	 */
	function resetPassword($username) {
{'fraction_non_alphanumeric': 0.1332721792687721, 'fraction_numerical': 0.0, 'mean_word_length': 4.439771917320028, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, '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': '6773799', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2350, 'n_words': 527}