<?php
ini_set('display_errors', 0);

/* error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1); */

require_once(dirname(__FILE__) . '/Controllers/Controller.php');
require_once(dirname(__FILE__) . '/Controllers/ServiceSegmentations.php');

$token = 'HtDFjQYeyfFb9e27n9URgFw27b9en9URg11Fw664ey11664ey11WJ9P27aGLOKmFh';
$ctrl = new Controller();
$serviceSegmentations = new ServiceSegmentations();

try {
	// Ejecutar el servicio de segmentaciones programadas
	$response = $serviceSegmentations->startService();

	return $response;
} catch(Exception $e) {
	// Gestión de excepciones
	$errorFile = dirname(__FILE__) . '/runningSegmentationsError.txt';
	$date = date('Y-m-d H:i:s');
	$exceptionString =	' EXCEPTION OCURRED: ' . $e->getMessage() . "\r\n" .
						'	-Exception Code: ' . $e->getCode() . "\r\n" .
						'	-Exception Line: ' . $e->getLine() . "\r\n" .
						'	-Exception Trace: ' . "\r\n" . $e->getTraceAsString() . "\r\n";
	// Escribir la excepción en el errorfile
	file_put_contents($errorFile, $date . $exceptionString . '---------------------------------' ."\r\n", FILE_APPEND);
	//lanzar un log en el server para registrarlo
	$ctrl->setCMBPLOG($token, 'SERVICE_SEGMENTATIONS_EXCEPTION', 'service segmentations exception', $exceptionString, '');
}
?>