Deleting users unsets the author of Content

This commit is contained in:
Ivo Valchev
2019-10-30 15:22:26 +01:00
parent 75cbd746c8
commit 031d48d5c1
3 changed files with 12 additions and 4 deletions
@@ -98,6 +98,12 @@ class UserEditController extends TwigAwareController implements BackendZone
#$this->validateCsrf($request, 'useredit');
$this->em->remove($user);
$contentArray = $this->getDoctrine()->getManager()->getRepository('Bolt\Entity\Content')->findBy(['author' => $user]);
foreach($contentArray as $content){
$content->setAuthor(null);
$this->em->persist($content);
}
$this->em->flush();
$url = $this->urlGenerator->generate('bolt_users');
+5 -3
View File
@@ -233,7 +233,7 @@ class Content
return $this->getDefinition()->get('icon_one') ?: $this->getDefinition()->get('icon_many');
}
public function getAuthor(): User
public function getAuthor(): ?User
{
return $this->author;
}
@@ -447,9 +447,11 @@ class Content
/**
* @Groups("get_content")
*/
public function getAuthorName(): string
public function getAuthorName(): ?string
{
return $this->getAuthor()->getDisplayName();
if(!$this->getAuthor() == null)
return $this->getAuthor()->getDisplayName();
return null;
}
public function getStatuses(): array
+1 -1
View File
@@ -27,7 +27,7 @@
{% include '@bolt/_partials/fields/text.html.twig' with {
'label' : 'field.author'|trans,
'name' : 'author',
'value' : record.author.displayName,
'value' : record.author.displayName|default('undefined'),
'disabled' : true
} %}