function createHistory($o, $h)
{
if ($o instanceof Ticket) {
$history = new TicketHistory();
$history->setTicket($o);
} else {
$history = new IssueHistory();
$history->setIssue($o);
}
if (!empty($h['enteredDate'])) {
$d = DateTime::createFromFormat('U', $h['enteredDate']->sec);
if ($d) {
$history->setEnteredDate($d->format('Y-m-d H:i:s'));
}
}
if (!empty($h['actionDate'])) {
$d = DateTime::createFromFormat('U', $h['actionDate']->sec);
if ($d) {
$history->setActionDate($d->format('Y-m-d H:i:s'));
}
}
if (!empty($h['enteredByPerson'])) {
$id = getPersonIdFromCrosswalk($h['enteredByPerson']['_id']);
if ($id) {
$history->setEnteredByPerson_id($id);
}
}
if (!empty($h['actionPerson'])) {
$id = getPersonIdFromCrosswalk($h['actionPerson']['_id']);
if ($id) {
$history->setActionPerson_id($id);
}
}
if (!empty($h['action'])) {
try {
$action = new Action($h['action']);
} catch (Exception $e) {
$action = new Action();
$action->setName($h['action']);
$action->setDescription($h['action']);
$action->setType('system');
}
$history->setAction($action);
}
if (!empty($h['notes'])) {
$history->setNotes($h['notes']);
}
$history->save();
}