<?php
/**
 * 2017-08-16 by a.binder - force A_CLASSIFIED/A_ADM_COMPANY by GroupID - use for single table
 *
 *
 */

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


if (isset($_SERVER["argv"][3])) {
	$_SERVER['SERVER_NAME'] = $_SERVER["argv"][1];
	$groupID = $_SERVER["argv"][2];
	$Table = $_SERVER["argv"][3];
}
else {
	die("\n The second argument should be server domain - e.g. biuro.biall-net.pl and third idGroup e.g. 3,  and last should be table name e.g. CRM_PROCES \n");
}

$cronTaskName = 'forceTablePerms';
$keyToken = 'bash_force_table_perms';
$token = Router::getRoute('Cron')->generateCliAuthToken($keyToken, $cronTaskName, 300 * 10);
$output = Router::getRoute('Cron')->executeCurlTastByToken($cronTaskName, $keyToken, $token, [ 'idGroup' => $groupID, 'table' => $Table ]);
echo "DBG: output -----------------------\n{$output}\nEOF output---------------------------------\n";

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

?>
