public function delete($deleteFilesAndThumbnails = false)
    {
        $app = Application::getFacadeApplication();
        $db = $app->make(Connection::class);
        $em = $app->make(EntityManagerInterface::class);
        $category = $this->getObjectAttributeCategory();

        foreach ($this->getAttributes() as $attribute) {
            $category->deleteValue($attribute);
        }

        $db->executeQuery('DELETE FROM FileVersionLog WHERE fID = ? AND fvID = ?', [$this->getFileID(), $this->fvID]);

        if ($deleteFilesAndThumbnails) {
            if ($this->getTypeObject()->getGenericType() === FileType::T_IMAGE) {
                $types = ThumbnailType::getVersionList();
                foreach ($types as $type) {
                    $this->deleteThumbnail($type);
                }
            }
            try {
                $fsl = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject();
                $fre = $this->getFileResource();
                if ($fsl->has($fre->getPath())) {
                    $fsl->delete($fre->getPath());
                }
            } catch (FileNotFoundException $e) {
            }
        }
        $em->remove($this);
        $em->flush();
    }