/**
  * Creates a new history.
  *
  * @param Records $record
  * @param string  $action
  *
  * @return bool
  */
 public function createHistory(Records $record, $action = 'CREATE')
 {
     $changes = $record->getChanges();
     if (0 == count($changes) && !in_array($action, array('CREATE', 'DELETE'))) {
         return true;
     }
     $content = $this->getSerializer()->serialize($record, 'json', SerializationContext::create()->setGroups('history'));
     $history = new RecordsHistory();
     $history->setDomainId($record->getDomain()->getId());
     $history->setRecordId($record->getId());
     $history->setDomainName($record->getDomain()->getName());
     $history->setRecordType($record->getType());
     $history->setAction($action);
     $history->setContents(json_decode($content, true));
     $history->setChanges($changes);
     $history->setCreated(new \DateTime());
     $history->setUser($record->getUser());
     $this->getDatabase()->persist($history);
     $this->getDatabase()->flush($history);
     return true;
 }