public function findVersions(EntityInterface $entity)
 {
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor'];
     $versionRepository = EntityHelper::getRepository('ORM:Version');
     $entityClassName = Helper::createShortenEntityName($entity);
     $entityId = $entityAccessor->getPrimaryKey($entity);
     return $versionRepository->findBy(array('entityClass' => $entityClassName, 'entityId' => $entityId), array('createdAt' => 'DESC'));
 }
 protected function createVersion($action, $entity, OnFlushEventArgs $args)
 {
     // TODO version creation is disabled due to a lot of problems with the current serialisation format
     return;
     try {
         $entityManager = $args->getEntityManager();
         if ($entity instanceof EntityInterface && !$entity instanceof Version) {
             $changeSet = $entityManager->getUnitOfWork()->getEntityChangeSet($entity);
             /** @var EntityAccessor $entityAccessor */
             $entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor'];
             $originalData = $entityAccessor->getRawProperties($entity);
             // restore original values
             foreach ($changeSet as $field => $change) {
                 $originalData[$field] = $change[0];
             }
             /** @var VersionManager $versionManager */
             $versionManager = $GLOBALS['container']['doctrine.orm.versionManager'];
             /** @var Version $previousVersion */
             $previousVersion = $versionManager->findVersion($entity, $originalData);
             /** @var Serializer $serializer */
             $serializer = $GLOBALS['container']['doctrine.orm.entitySerializer'];
             $version = new Version();
             $version->setEntityClass(Helper::createShortenEntityName($entity));
             $version->setEntityId($entityAccessor->getPrimaryKey($entity));
             $version->setEntityHash(VersionManager::calculateHash($entity));
             $version->setAction($action);
             $version->setPrevious($previousVersion ? $previousVersion->getId() : null);
             $version->setData($serializer->serialize($entity, 'json'));
             $version->setChanges($serializer->serialize($changeSet, 'json'));
             if (BE_USER_LOGGED_IN) {
                 $user = \BackendUser::getInstance();
                 $version->setUserId($user->id);
                 $version->setUsername($user->username);
             }
             $this->versions[] = $version;
         }
     } catch (\Exception $e) {
         // silently ignore
         // TODO work around binary data
     }
 }