<?php
/**
 * 2017-08-16 by a.binder - bug first user is always not synced
 * index.php?_route=Users&_task=syncUser&usrLogin=$argv[2]
 *
 */

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');
// _ Lib::loadClass('UserStorageFactory');


if (isset($_SERVER["argv"][2])) {
	$_SERVER['SERVER_NAME'] = $_SERVER["argv"][1];
	$usrLogin = $_SERVER["argv"][2];
}

else {
	die("\n The second argument should be server domain - e.g. biuro.biall-net.pl and third usrLogin e.g. jan.kowalski \n");
}


$cronTaskName = 'forceSyncUser';
$keyToken = 'bash_forceSyncUser';
$token = Router::getRoute('Cron')->generateCliAuthToken($keyToken, $cronTaskName, 300 * 10);
$output = Router::getRoute('Cron')->executeCurlTastByToken($cronTaskName, $keyToken, $token, [ 'usrLogin' => $usrLogin ]);
echo "DBG: output -----------------------\n{$output}\nEOF output---------------------------------\n";



//_ Lib::loadClass('Router');
//_			$usrStorageDB = UserStorageFactory::getStorage('DB');
//_			$usrStorageLdap = UserStorageFactory::getStorage('MacOSX');
//)			$forceSync = 1;
//_Router::getRoute('Users')->syncUser($usrLogin,$usrStorageDB,$usrStorageLdap,$forceSync);

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

?>
