migrations/Version20220406215630.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220406215630 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Remove mediaprofil type player that has no player attached (identiteservice_mediaprofil)';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $lastId 0;
  19.         $removed 0;
  20.         while (true) {
  21.             $profiles $this->connection->fetchAllAssociative("SELECT idmediaprofil, identiteservice_mediaprofil FROM mediaprofil WHERE typeentite_mediaprofil = 1 AND idmediaprofil > {$lastId} LIMIT 1000");
  22.             if (empty($profiles)) {
  23.                 break;
  24.             }
  25.             foreach ($profiles as $profile) {
  26.                 $lastId $profileId $profile['idmediaprofil'];
  27.                 $playerServiceId $profile['identiteservice_mediaprofil'];
  28.                 $player $this->connection->fetchAssociative("SELECT idjoueur FROM joueur WHERE idjoueurservice_joueur = {$playerServiceId}");
  29.                 if (!$player) {
  30.                     $this->connection->executeQuery("DELETE FROM mediaprofil WHERE idmediaprofil = {$profileId}");
  31.                     ++$removed;
  32.                 }
  33.             }
  34.         }
  35.         dump("Removed {$removed} mediaprofil type player that had no player");
  36.     }
  37.     public function down(Schema $schema): void
  38.     {
  39.         // this down() migration is auto-generated, please modify it to your needs
  40.     }
  41. }