<?php
/**
 * 2016-04-06 by plabudda
 *
 */

ini_set('max_execution_time', 300);
ini_set('memory_limit', '512M');

define('DS', DIRECTORY_SEPARATOR);
define('APP_PATH_ROOT', dirname(__FILE__));
define('APP_PATH_WWW', dirname(__FILE__));
define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');

// set ini to log errors into error log file
ini_set('display_startup_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', '/var/log/apache2/error_log');// TODO: php.ini ?

require_once APP_PATH_ROOT . DS . 'se-lib' . DS . 'Lib.php';
Lib::loadClass('V');
Lib::loadClass('Config');
Lib::loadClass('DB');
Lib::loadClass('User');

if (isset($_SERVER["argv"][1])) {
	$_SERVER['SERVER_NAME'] = $_SERVER["argv"][1];
}
else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'info') {
	$info = array();
	$info['max_execution_time'] = ini_get('max_execution_time');
	$info['memory_limit'] = ini_get('memory_limit');
	echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">info (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'</pre>';

	ini_set('max_execution_time', 300);
	ini_set('memory_limit', '512M');
	$info = array();
	$info['max_execution_time'] = ini_get('max_execution_time');
	$info['memory_limit'] = ini_get('memory_limit');
	echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">info (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'</pre>';
}
else {
	die("\n The second argument should be server domain - e.g. biuro.biall-net.pl \n");
}

// TODO: check install
Lib::loadClass('Router');
Router::getRoute('Config')->reinstall();
$cronTaskName = 'checkInstall';
$keyToken = 'bash_install_check';
$token = Router::getRoute('Cron')->generateCliAuthToken($keyToken, $cronTaskName, 300 * 10);
$string = Router::getRoute('Cron')->executeCurlTastByToken($cronTaskName, $keyToken, $token);
echo "DBG: string -----------------------\n{$string}\nEOF string---------------------------------\n";

{
	echo "Router::getRoute('FileStorage')->reinstall() ...\n";
	Router::getRoute('FileStorage')->reinstall();
	echo "\nRouter::getRoute('FileStorage')->reinstall() DONE\n";
}

die(".EOF - OK\n");

?>
