roles property added to user, migration does not want to execute due to null value not allowed

This commit is contained in:
Julie Lenaerts 2022-03-08 15:48:22 +01:00
parent d18ab5cf49
commit 0a4abe9b8d
2 changed files with 76 additions and 105 deletions

View File

@ -138,6 +138,11 @@ class User implements AdvancedUserInterface
*/ */
private ?string $usernameCanonical = null; private ?string $usernameCanonical = null;
/**
* @ORM\Column(type="json")
*/
private array $roles = ['ROLE_USER'];
/** /**
* User constructor. * User constructor.
*/ */
@ -146,36 +151,17 @@ class User implements AdvancedUserInterface
$this->groupCenters = new ArrayCollection(); $this->groupCenters = new ArrayCollection();
} }
/** public function __toString(): string
* @return string
*/
public function __toString()
{ {
return $this->getLabel(); return $this->getLabel();
} }
/** // empty function... remove?
* @param \Chill\MainBundle\Entity\GroupCenter $groupCenter
*
* @return \Chill\MainBundle\Entity\User
*/
public function addGroupCenter(GroupCenter $groupCenter)
{
$this->groupCenters->add($groupCenter);
return $this;
}
public function eraseCredentials() public function eraseCredentials()
{ {
} }
/** public function getAttributes(): ?array
* Get attributes.
*
* @return array
*/
public function getAttributes()
{ {
if (null === $this->attributes) { if (null === $this->attributes) {
$this->attributes = []; $this->attributes = [];
@ -189,18 +175,12 @@ class User implements AdvancedUserInterface
return $this->currentLocation; return $this->currentLocation;
} }
/**
* @return string
*/
public function getEmail(): ?string public function getEmail(): ?string
{ {
return $this->email; return $this->email;
} }
/** public function getEmailCanonical(): ?string
* @return string
*/
public function getEmailCanonical()
{ {
return $this->emailCanonical; return $this->emailCanonical;
} }
@ -213,12 +193,7 @@ class User implements AdvancedUserInterface
return $this->groupCenters; return $this->groupCenters;
} }
/** public function getId(): ?int
* Get id.
*
* @return int
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
@ -243,23 +218,20 @@ class User implements AdvancedUserInterface
return $this->mainScope; return $this->mainScope;
} }
/** public function getPassword(): string
* @return string
*/
public function getPassword()
{ {
return $this->password; return $this->password;
} }
public function getRoles(): array public function getRoles(): array
{ {
return ['ROLE_USER']; $roles = $this->roles;
$roles[] = 'ROLE_USER';
return array_unique($roles);
} }
/** public function getSalt(): ?string
* @return string|null
*/
public function getSalt()
{ {
return $this->salt; return $this->salt;
} }
@ -269,50 +241,32 @@ class User implements AdvancedUserInterface
return $this->userJob; return $this->userJob;
} }
/** public function getUsername(): string
* @return string
*/
public function getUsername()
{ {
return $this->username; return $this->username;
} }
/** public function getUsernameCanonical(): ?string
* @return string
*/
public function getUsernameCanonical()
{ {
return $this->usernameCanonical; return $this->usernameCanonical;
} }
/** public function isAccountNonExpired(): bool
* @return bool
*/
public function isAccountNonExpired()
{ {
return true; return true;
} }
/** public function isAccountNonLocked(): bool
* @return bool
*/
public function isAccountNonLocked()
{ {
return $this->locked; return $this->locked;
} }
/** public function isCredentialsNonExpired(): bool
* @return bool
*/
public function isCredentialsNonExpired()
{ {
return true; return true;
} }
/** public function isEnabled(): bool
* @return bool
*/
public function isEnabled()
{ {
return $this->enabled; return $this->enabled;
} }
@ -349,6 +303,13 @@ class User implements AdvancedUserInterface
} }
} }
public function addGroupCenter(GroupCenter $groupCenter): self
{
$this->groupCenters->add($groupCenter);
return $this;
}
/** /**
* Set attributes. * Set attributes.
* *
@ -363,97 +324,83 @@ class User implements AdvancedUserInterface
return $this; return $this;
} }
public function setCurrentLocation(?Location $currentLocation): User public function setCurrentLocation(?Location $currentLocation): self
{ {
$this->currentLocation = $currentLocation; $this->currentLocation = $currentLocation;
return $this; return $this;
} }
/** public function setRoles($roles): self
* @param $email {
* $this->roles = $roles;
* @return $this return $this;
*/ }
public function setEmail($email)
public function setEmail($email): self
{ {
$this->email = $email; $this->email = $email;
return $this; return $this;
} }
/** public function setEmailCanonical($emailCanonical): self
* @param $emailCanonical
*
* @return $this
*/
public function setEmailCanonical($emailCanonical)
{ {
$this->emailCanonical = $emailCanonical; $this->emailCanonical = $emailCanonical;
return $this; return $this;
} }
public function setEnabled(bool $enabled) public function setEnabled(bool $enabled): self
{ {
$this->enabled = $enabled; $this->enabled = $enabled;
return $this; return $this;
} }
public function setLabel(string $label): User public function setLabel(string $label): self
{ {
$this->label = $label; $this->label = $label;
return $this; return $this;
} }
public function setMainCenter(?Center $mainCenter): User public function setMainCenter(?Center $mainCenter): self
{ {
$this->mainCenter = $mainCenter; $this->mainCenter = $mainCenter;
return $this; return $this;
} }
public function setMainLocation(?Location $mainLocation): User public function setMainLocation(?Location $mainLocation): self
{ {
$this->mainLocation = $mainLocation; $this->mainLocation = $mainLocation;
return $this; return $this;
} }
public function setMainScope(?Scope $mainScope): User public function setMainScope(?Scope $mainScope): self
{ {
$this->mainScope = $mainScope; $this->mainScope = $mainScope;
return $this; return $this;
} }
/** public function setPassword($password): self
* @param $password
*
* @return $this
*/
public function setPassword($password)
{ {
$this->password = $password; $this->password = $password;
return $this; return $this;
} }
/** public function setSalt($salt): self
* @param $salt
*
* @return $this
*/
public function setSalt($salt)
{ {
$this->salt = $salt; $this->salt = $salt;
return $this; return $this;
} }
public function setUserJob(?UserJob $userJob): User public function setUserJob(?UserJob $userJob): self
{ {
$this->userJob = $userJob; $this->userJob = $userJob;
@ -478,12 +425,7 @@ class User implements AdvancedUserInterface
return $this; return $this;
} }
/** public function setUsernameCanonical($usernameCanonical): self
* @param $usernameCanonical
*
* @return $this
*/
public function setUsernameCanonical($usernameCanonical)
{ {
$this->usernameCanonical = $usernameCanonical; $this->usernameCanonical = $usernameCanonical;

View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220308104030 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add roles property to user';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE users ADD roles JSON NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE users DROP roles');
}
}