<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220411103436 extends AbstractMigration
{
public function getDescription(): string
{
return 'Aka';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$totalPlayerRemoved = $totalTeamRemoved = $totalRemoved = 0;
$lastId = 0;
while (true) {
$akas = $this->connection->fetchAllAssociative("SELECT idaka, idelement_aka, typeelement_aka, aka_aka FROM aka WHERE idaka > {$lastId} LIMIT 1000");
if (empty($akas)) {
break;
}
foreach ($akas as $aka) {
$akaId = $lastId = $aka['idaka'];
$akaElementType = $aka['typeelement_aka'];
$akaElementId = $aka['idelement_aka'];
$akaName = $aka['aka_aka'];
$akaIdToDelete = null;
if (null === $akaElementType) {
echo "DELETE Aka {$akaId} : {$akaName} : pas de relation\n";
$akaIdToDelete = $akaId;
} elseif ('1' == $akaElementType) {
$player = $this->connection->fetchAssociative("SELECT idjoueur FROM joueur WHERE idjoueurservice_joueur = {$akaElementId}");
if (!$player) {
echo "DELETE Aka {$akaId} : {$akaName} : Player.idjoueurservice_joueur {$akaElementId} not found\n";
$akaIdToDelete = $akaId;
++$totalPlayerRemoved;
}
} elseif ('2' == $akaElementType) {
$team = $this->connection->fetchAssociative("SELECT idequipe FROM equipe WHERE idequipeservice_equipe = {$akaElementId}");
if (!$team) {
echo "DELETE Aka {$akaId} : {$akaName} : Team.idequipeservice_equipe {$akaElementId} not found\n";
$akaIdToDelete = $akaId;
++$totalTeamRemoved;
}
} else {
echo "ERROR : Aka {$akaId} : {$akaName}";
}
if ($akaIdToDelete) {
++$totalRemoved;
$this->connection->executeQuery("DELETE FROM aka WHERE idaka = {$akaIdToDelete}");
}
}
}
echo "END | Players removed : {$totalPlayerRemoved} | Teams removed : {$totalTeamRemoved} | Total removed : {$totalRemoved}\n";
$this->addSql('ALTER TABLE aka CHANGE typeelement_aka typeelement_aka VARCHAR(2) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE aka CHANGE typeelement_aka typeelement_aka VARCHAR(2) DEFAULT NULL');
}
}