<commit_before><?php

require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."alpha".DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."kConf.php");
		
ini_set("memory_limit", "512M");
error_reporting(E_ALL);
$code = array();

$ignoreErrors = false;
if($argc > 1 && $argv[1] == 'ignore')
	$ignoreErrors = true;

$updateRunner = new ScriptsRunner();
$updateRunner->init($ignoreErrors);
	
// create version_management table
$updateRunner->runSqlScript(dirname(__FILE__).DIRECTORY_SEPARATOR."create_version_mng_table.sql");
$sqlDir = dirname(__FILE__).DIRECTORY_SEPARATOR."sql";
$updateRunner->runSqlScripts($sqlDir);

$phpDir = dirname(__FILE__).DIRECTORY_SEPARATOR."scripts";
$updateRunner->runPhpScripts($phpDir);


class ScriptsRunner {
	
	private $dbParams = array();
	private $version;
	private $alreadyRun;
	private $ignoreErrors;
	
	public function init($ignore) {
		$this->ignoreErrors = $ignore;
		$dbConf = kConf::getDB();
		$dsn = $dbConf['datasources']['propel']['connection']['dsn'];
		$dsn = explode(":", $dsn);
		$dsnArray = explode(";", $dsn[1], -1);
		foreach ($dsnArray as $param) {
			$items = explode("=",$param);
			$this->dbParams[$items[0]] = $items[1];
		} 
		$this->version = $this->getMaxVersion() + 1;
		$this->alreadyRun = $this->getDeployedScripts();
	}
	
	public function runSqlScript($file) {		
		if (!is_file($file)) {
			echo "Could not run script: script not found $file";	
			return false;
		}
		
		if (empty($this->dbParams['password'])) {		
			$cmd = sprintf("mysql -h%s -u%s -P%s %s < %s", $this->dbParams['host'], $this->dbParams['user'], $this->dbParams['port'], $this->dbParams['dbname'], $file);
		} else {
			$cmd = sprintf("mysql -h%s -u%s -p%s -P%s %s < %s", $this->dbParams['host'], $this->dbParams['user'], $this->dbParams['password'], $this->dbParams['port'], $this->dbParams['dbname'], $file);
		}
		//logMessage(L_INFO, "Executing $cmd");
		@exec($cmd . ' 2>&1', $output, $return_var);
		if ($return_var === 0) {
			return true;
		} else {
			echo "Failed to run: ".$cmd." ".PHP_EOL.implode("\n",$output).PHP_EOL;	
			return false;
		}<commit_msg>on-prem eagle installation add update script log messages<commit_after><?php

require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."alpha".DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."kConf.php");
		
ini_set("memory_limit", "512M");
error_reporting(E_ALL);
$code = array();

$ignoreErrors = false;
if($argc > 1 && $argv[1] == 'ignore')
	$ignoreErrors = true;

$updateRunner = new ScriptsRunner();
$updateRunner->init($ignoreErrors);
	
// create version_management table
$updateRunner->runSqlScript(dirname(__FILE__).DIRECTORY_SEPARATOR."create_version_mng_table.sql");
$sqlDir = dirname(__FILE__).DIRECTORY_SEPARATOR."sql";
$updateRunner->runSqlScripts($sqlDir);

$phpDir = dirname(__FILE__).DIRECTORY_SEPARATOR."scripts";
$updateRunner->runPhpScripts($phpDir);


class ScriptsRunner {
	
	private $dbParams = array();
	private $version;
	private $alreadyRun;
	private $ignoreErrors;
	
	public function init($ignore) {
		$this->ignoreErrors = $ignore;
		$dbConf = kConf::getDB();
		$dsn = $dbConf['datasources']['propel']['connection']['dsn'];
		$dsn = explode(":", $dsn);
		$dsnArray = explode(";", $dsn[1], -1);
		foreach ($dsnArray as $param) {
			$items = explode("=",$param);
			$this->dbParams[$items[0]] = $items[1];
		} 
		$this->version = $this->getMaxVersion() + 1;
		$this->alreadyRun = $this->getDeployedScripts();
	}
	
	public function runSqlScript($file) {		
		if (!is_file($file)) {
			echo "Could not run script: script not found $file";	
			return false;
		}
		
		if (empty($this->dbParams['password'])) {		
			$cmd = sprintf("mysql -h%s -u%s -P%s %s < %s", $this->dbParams['host'], $this->dbParams['user'], $this->dbParams['port'], $this->dbParams['dbname'], $file);
		} else {
			$cmd = sprintf("mysql -h%s -u%s -p%s -P%s %s < %s", $this->dbParams['host'], $this->dbParams['user'], $this->dbParams['password'], $this->dbParams['port'], $this->dbParams['dbname'], $file);
		}
		logMessage(L_INFO, "Executing $cmd");
		@exec($cmd . ' 2>&1', $output, $return_var);
		if ($return_var === 0) {
			logMessage(L_INFO, "Command $cmd Executed Successfully");
			return true;
		} else {
			echo "Failed to run: ".$cmd." ".PHP_EOL.implode("\n",$output).PHP_EOL;	
			logMessage(L_INFO, "Failed to run: Failed to run:  $cmd ");
			logMessage(L_INFO, implode("\n",$output));
			return false;
		}
{'fraction_non_alphanumeric': 0.20614425645592163, 'fraction_numerical': 0.00578806767586821, 'mean_word_length': 5.310393258426966, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 47, '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': '4984966', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1604, 'n_words': 292}