-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81aefaf
commit 4f78d5d
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Add enabled field to User entity. | ||
*/ | ||
final class Version20231220194844 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add enabled field to User entity.'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
if ($schema->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use App\Entity\User; | ||
use App\Enum\Roles; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Remove Roles::SPAM from users and disable them. | ||
*/ | ||
final class Version20231220203032 extends AbstractMigration implements ContainerAwareInterface | ||
{ | ||
private $container; | ||
|
||
public function setContainer(ContainerInterface $container = null): void | ||
{ | ||
$this->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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class LoadUserData extends Fixture implements OrderedFixtureInterface, Container | |
['email' => '[email protected]', 'roles' => [Roles::USER]], | ||
['email' => '[email protected]', 'roles' => [Roles::MULTIPLIER]], | ||
['email' => '[email protected]', 'roles' => [Roles::SUSPICIOUS]], | ||
['email' => '[email protected]', 'roles' => [Roles::SPAM]], | ||
['email' => '[email protected]', 'roles' => [Roles::DOMAIN_ADMIN]], | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters