migrations/Version20220411103436.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 Version20220411103436 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Aka';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $totalPlayerRemoved $totalTeamRemoved $totalRemoved 0;
  19.         $lastId 0;
  20.         while (true) {
  21.             $akas $this->connection->fetchAllAssociative("SELECT idaka, idelement_aka, typeelement_aka, aka_aka FROM aka WHERE idaka > {$lastId} LIMIT 1000");
  22.             if (empty($akas)) {
  23.                 break;
  24.             }
  25.             foreach ($akas as $aka) {
  26.                 $akaId $lastId $aka['idaka'];
  27.                 $akaElementType $aka['typeelement_aka'];
  28.                 $akaElementId $aka['idelement_aka'];
  29.                 $akaName $aka['aka_aka'];
  30.                 $akaIdToDelete null;
  31.                 if (null === $akaElementType) {
  32.                     echo "DELETE Aka {$akaId} : {$akaName} : pas de relation\n";
  33.                     $akaIdToDelete $akaId;
  34.                 } elseif ('1' == $akaElementType) {
  35.                     $player $this->connection->fetchAssociative("SELECT idjoueur FROM joueur WHERE idjoueurservice_joueur = {$akaElementId}");
  36.                     if (!$player) {
  37.                         echo "DELETE Aka {$akaId} : {$akaName} : Player.idjoueurservice_joueur {$akaElementId} not found\n";
  38.                         $akaIdToDelete $akaId;
  39.                         ++$totalPlayerRemoved;
  40.                     }
  41.                 } elseif ('2' == $akaElementType) {
  42.                     $team $this->connection->fetchAssociative("SELECT idequipe FROM equipe WHERE idequipeservice_equipe = {$akaElementId}");
  43.                     if (!$team) {
  44.                         echo "DELETE Aka {$akaId} : {$akaName} : Team.idequipeservice_equipe {$akaElementId} not found\n";
  45.                         $akaIdToDelete $akaId;
  46.                         ++$totalTeamRemoved;
  47.                     }
  48.                 } else {
  49.                     echo "ERROR : Aka {$akaId} : {$akaName}";
  50.                 }
  51.                 if ($akaIdToDelete) {
  52.                     ++$totalRemoved;
  53.                     $this->connection->executeQuery("DELETE FROM aka WHERE idaka = {$akaIdToDelete}");
  54.                 }
  55.             }
  56.         }
  57.         echo "END | Players removed : {$totalPlayerRemoved} | Teams removed : {$totalTeamRemoved} | Total removed : {$totalRemoved}\n";
  58.         $this->addSql('ALTER TABLE aka CHANGE typeelement_aka typeelement_aka VARCHAR(2) NOT NULL');
  59.     }
  60.     public function down(Schema $schema): void
  61.     {
  62.         // this down() migration is auto-generated, please modify it to your needs
  63.         $this->addSql('ALTER TABLE aka CHANGE typeelement_aka typeelement_aka VARCHAR(2) DEFAULT NULL');
  64.     }
  65. }