<commit_before><?php

error_reporting(E_ALL);

require_once(dirname(__FILE__).'/../infra/kConf.php');

// clear kConf defined cache directories
$path = realpath(kConf::get('cache_root_path'));

askToDelete(fixPath(kConf::get('general_cache_dir')));
askToDelete(fixPath(kConf::get('response_cache_dir')));
askToDelete(fixPath(kConf::get('cache_root_path')));

// clear APC cache
if (function_exists('apc_clear_cache'))
{
	// clear apc system cache
	if (!apc_clear_cache())
	{
		echo 'Unable to clear APC SYSTEM cache!'.PHP_EOL;
	} 
	
	// clear apc user cache
	if (!apc_clear_cache('user'))
	{
		echo 'Unable to clear APC USER cache!'.PHP_EOL;
	}
}

function fixPath($path)
{
	$path = str_replace('\\', '/', $path);
	return realpath($path);
}


function askToDelete($path)
{	
	$baseKalturaPath = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..');
	if (strpos($path, $baseKalturaPath) === 0)
	{
		echo 'Are you sure you want to delete all files under ['.$path.'] (y/n) ?  ';
		$input = trim(fgets(STDIN));
		if ($input === strtolower('y')) {
                    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
			$cmd = 'del /F /S /Q '.$path.DIRECTORY_SEPARATOR.'*'.DIRECTORY_SEPARATOR.'* del /F /S /Q '.$path.DIRECTORY_SEPARATOR.'*.*';
                    } else {
		        $cmd = "find $path -type f -exec rm -rf {} \;";
                    }
                    echo "Executing: $cmd\n";
                    system($cmd,$rc);
                    if ($rc){
                            echo "Failed to clean up $path.";
                    }
		}
		else {
			echo 'Skipping...'.PHP_EOL;
		}
	}
	else
	{
		echo 'Path ['.$path.'] does not belong to the kaltura server. Skipping.'.PHP_EOL;
	}	
}<commit_msg>qnd: clear_cache.php - added support for non interactive mode<commit_after><?php

error_reporting(E_ALL);

require_once(dirname(__FILE__).'/../infra/kConf.php');

$interactive = true;
if ($argc == 2 && $argv[1] == '-y')
{
	$interactive = false;
}

// clear kConf defined cache directories
$path = realpath(kConf::get('cache_root_path'));

askToDelete(fixPath(kConf::get('general_cache_dir')), $interactive);
askToDelete(fixPath(kConf::get('response_cache_dir')), $interactive);
askToDelete(fixPath(kConf::get('cache_root_path')), $interactive);

// clear APC cache
if (function_exists('apc_clear_cache'))
{
	// clear apc system cache
	if (!apc_clear_cache())
	{
		echo 'Unable to clear APC SYSTEM cache!'.PHP_EOL;
	} 
	
	// clear apc user cache
	if (!apc_clear_cache('user'))
	{
		echo 'Unable to clear APC USER cache!'.PHP_EOL;
	}
}

function fixPath($path)
{
	$path = str_replace('\\', '/', $path);
	return realpath($path);
}


function askToDelete($path, $interactive)
{	
	$baseKalturaPath = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..');
	if (strpos($path, $baseKalturaPath) === 0)
	{
		if ($interactive)
		{
			echo 'Are you sure you want to delete all contents of ['.$path.'] (y/n) ?  ';
			$input = trim(fgets(STDIN));
		}
		else
		{
			$input = 'y';
		}
		
		if ($input === strtolower('y')) 
		{
			if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') 
			{
				$cmd = 'del /F /S /Q '.$path.DIRECTORY_SEPARATOR.'*'.DIRECTORY_SEPARATOR.'* del /F /S /Q '.$path.DIRECTORY_SEPARATOR.'*.*';
			}
			else 
			{
				$cmd = "find $path -type f -exec rm -rf {} \;";
			}
			
			echo "Executing: $cmd\n";
			system($cmd,$rc);
			if ($rc)
			{
				echo "Failed to clean up $path.".PHP_EOL;
			}
		}
		else 
		{
			echo 'Skipping...'.PHP_EOL;
		}
	}
	else
	{
		echo 'Path ['.$path.'] does not belong to the kaltura server. Skipping.'.PHP_EOL;
	}	
}
{'fraction_non_alphanumeric': 0.18378834787503517, 'fraction_numerical': 0.002251618350689558, 'mean_word_length': 3.1325581395348836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5595145', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1329, 'n_words': 283}