Working on adding audit trail to events

master
Mike Koch 6 years ago
parent 770a01a970
commit 1a66485d48
No known key found for this signature in database
GPG Key ID: 9BA5D7F8391455ED

@ -3,14 +3,20 @@
namespace BusinessLogic\Calendar;
use BusinessLogic\DateTimeHelpers;
use BusinessLogic\Security\UserContext;
use BusinessLogic\Tickets\AuditTrailEntityType;
use DataAccess\AuditTrail\AuditTrailGateway;
use DataAccess\Calendar\CalendarGateway;
class CalendarHandler extends \BaseClass {
private $calendarGateway;
private $auditTrailGateway;
public function __construct(CalendarGateway $calendarGateway) {
public function __construct(CalendarGateway $calendarGateway,
AuditTrailGateway $auditTrailGateway) {
$this->calendarGateway = $calendarGateway;
$this->auditTrailGateway = $auditTrailGateway;
}
public function getEventsForStaff($searchEventsFilter, $heskSettings) {
@ -37,10 +43,25 @@ class CalendarHandler extends \BaseClass {
throw new \Exception("Expected exactly 1 event, found: " . count($events));
}
return $events[0];
$event = $events[0];
$this->auditTrailGateway->insertAuditTrailRecord($event->id,
AuditTrailEntityType::CALENDAR_EVENT,
'audit_event_updated',
DateTimeHelpers::heskDate($heskSettings),
array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings);
return $event;
}
/**
* @param $calendarEvent CalendarEvent
* @param $userContext UserContext
* @param $heskSettings array
* @return AbstractEvent
* @throws \Exception
*/
public function createEvent($calendarEvent, $userContext, $heskSettings) {
$this->calendarGateway->createEvent($calendarEvent, $userContext, $heskSettings);
@ -54,7 +75,15 @@ class CalendarHandler extends \BaseClass {
throw new \Exception("Expected exactly 1 event, found: " . count($events));
}
return $events[0];
$event = $events[0];
$this->auditTrailGateway->insertAuditTrailRecord($event->id,
AuditTrailEntityType::CALENDAR_EVENT,
'audit_event_created',
DateTimeHelpers::heskDate($heskSettings),
array(0 => $userContext->name . ' (' . $userContext->username . ')'), $heskSettings);
return $event;
}
public function deleteEvent($id, $userContext, $heskSettings) {

@ -5,4 +5,5 @@ namespace BusinessLogic\Tickets;
class AuditTrailEntityType extends \BaseClass {
const TICKET = 'TICKET';
const CALENDAR_EVENT = 'CALENDAR_EVENT';
}

@ -69,6 +69,7 @@ class CalendarController extends \BaseClass {
function post() {
/* @var $userContext UserContext */
/* @var $hesk_settings array */
global $applicationContext, $hesk_settings, $userContext;
$json = JsonRetriever::getJsonData();
@ -78,7 +79,7 @@ class CalendarController extends \BaseClass {
/* @var $calendarHandler CalendarHandler */
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
return output($calendarHandler->createEvent($event, $userContext, $hesk_settings));
return output($calendarHandler->createEvent($event, $userContext, $hesk_settings), 201);
}
function put($id) {

@ -10,6 +10,8 @@ use BusinessLogic\Calendar\SearchEventsFilter;
use BusinessLogic\Calendar\TicketEvent;
use BusinessLogic\Helpers;
use BusinessLogic\Security\UserContext;
use BusinessLogic\Tickets\AuditTrail;
use BusinessLogic\Tickets\AuditTrailEntityType;
use Core\Constants\Priority;
use DataAccess\CommonDao;
use DataAccess\Logging\LoggingGateway;
@ -73,6 +75,36 @@ class CalendarGateway extends CommonDao {
$event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']);
$event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']);
$auditTrailSql = "SELECT `at`.`id` AS `id`, `at`.`entity_id`, `at`.`language_key`, `at`.`date`,
`values`.`replacement_index`, `values`.`replacement_values`
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail` AS `at`
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "audit_trail_to_replacement_values` AS `values`
ON `at`.`id` = `values`.`audit_trail_id`
WHERE `entity_id` = " . intval($event->id) . "
AND `entity_type` = '" . AuditTrailEntityType::CALENDAR_EVENT . "'";
$auditTrailRs = hesk_dbFetchAssoc($auditTrailSql);
$auditTrailEntry = null;
while ($row = hesk_dbFetchAssoc($rs)) {
if ($auditTrailEntry == null || intval($auditTrailEntry['id']) !== intval($row['id'])) {
if ($auditTrailEntry !== null) {
//$audit_records[] = $auditTrailEntry;
}
$auditTrailEntry = new AuditTrail();
$auditTrailEntry->id = $row['id'];
$auditTrailEntry->entityId = $row['entity_id'];
$auditTrailEntry->entityType = AuditTrailEntityType::CALENDAR_EVENT;
$auditTrailEntry->languageKey = $row['language_key'];
$auditTrailEntry->date = $row['date'];
$auditTrailEntry->replacementValues = array();
}
$auditTrailEntry->replacementValues[intval($row['replacement_index'])] = $row['replacement_value'];
}
if ($auditTrailEntry !== null) {
//$event->auditTrail[] = $audiTrailEntry;
}
$events[] = $event;
}

@ -2214,5 +2214,9 @@ $hesklang['audit_due_date_changed'] = '%s changed due date to %s';
$hesklang['audit_linked_ticket'] = '%s linked ticket %s to this ticket';
$hesklang['audit_unlinked_ticket'] = '%s unlinked ticket %s';
// Added or modified in Mods for HESK 3.3.0
$hesklang['audit_event_created'] = '%s created event';
$hesklang['audit_event_updated'] = '%s updated event';
// DO NOT CHANGE BELOW
if (!defined('IN_SCRIPT')) die('PHP syntax OK!');

Loading…
Cancel
Save