diff --git a/migrations/Version20231220194844.php b/migrations/Version20231220194844.php new file mode 100644 index 00000000..20a178e0 --- /dev/null +++ b/migrations/Version20231220194844.php @@ -0,0 +1,37 @@ +getTable('virtual_users')->hasColumn('enabled')) { + return; + } + + $this->addSql('ALTER TABLE virtual_users ADD enabled TINYINT(1) NOT NULL'); + } + + public function down(Schema $schema): void + { + if (!$schema->getTable('virtual_users')->hasColumn('enabled')) { + return; + } + + $this->addSql('ALTER TABLE virtual_users DROP enabled'); + } +} diff --git a/migrations/Version20231220203032.php b/migrations/Version20231220203032.php new file mode 100644 index 00000000..90c9e9be --- /dev/null +++ b/migrations/Version20231220203032.php @@ -0,0 +1,53 @@ +container = $container; + } + + public function getDescription(): string + { + return 'Remove Roles::SPAM from users and disable them.'; + } + + public function up(Schema $schema): void + { + $entityManager = $this->container->get('doctrine.orm.entity_manager'); + /** @var \App\Entity\User[] $users */ + $users = $entityManager->getRepository(User::class)->findAll(); + foreach ($users as $user) { + if (!$user->hasRole(Roles::SPAM) || $user->isDeleted()) { + continue; + } + + $user->setRoles(array_filter($user->getRoles(), function ($role) { + return $role !== Roles::SPAM; + })); + $user->setEnabled(false); + $entityManager->persist($user); + } + $entityManager->flush(); + } + + public function down(Schema $schema): void + { + } +} diff --git a/src/DataFixtures/LoadUserData.php b/src/DataFixtures/LoadUserData.php index e8d850f9..6cea9914 100644 --- a/src/DataFixtures/LoadUserData.php +++ b/src/DataFixtures/LoadUserData.php @@ -21,6 +21,7 @@ class LoadUserData extends Fixture implements OrderedFixtureInterface, Container ['email' => 'user@example.org', 'roles' => [Roles::USER]], ['email' => 'support@example.org', 'roles' => [Roles::MULTIPLIER]], ['email' => 'suspicious@example.org', 'roles' => [Roles::SUSPICIOUS]], + ['email' => 'spammer@example.org', 'roles' => [Roles::SPAM]], ['email' => 'domain@example.com', 'roles' => [Roles::DOMAIN_ADMIN]], ]; diff --git a/src/Enum/Roles.php b/src/Enum/Roles.php index 92e9e829..f80865f9 100644 --- a/src/Enum/Roles.php +++ b/src/Enum/Roles.php @@ -6,6 +6,7 @@ final class Roles { public const PERMANENT = 'ROLE_PERMANENT'; public const MULTIPLIER = 'ROLE_MULTIPLIER'; + /** @deprecated */ public const SPAM = 'ROLE_SPAM'; public const SUSPICIOUS = 'ROLE_SUSPICIOUS'; public const USER = 'ROLE_USER';