<?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 Version20220406215630 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove mediaprofil type player that has no player attached (identiteservice_mediaprofil)';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$lastId = 0;
$removed = 0;
while (true) {
$profiles = $this->connection->fetchAllAssociative("SELECT idmediaprofil, identiteservice_mediaprofil FROM mediaprofil WHERE typeentite_mediaprofil = 1 AND idmediaprofil > {$lastId} LIMIT 1000");
if (empty($profiles)) {
break;
}
foreach ($profiles as $profile) {
$lastId = $profileId = $profile['idmediaprofil'];
$playerServiceId = $profile['identiteservice_mediaprofil'];
$player = $this->connection->fetchAssociative("SELECT idjoueur FROM joueur WHERE idjoueurservice_joueur = {$playerServiceId}");
if (!$player) {
$this->connection->executeQuery("DELETE FROM mediaprofil WHERE idmediaprofil = {$profileId}");
++$removed;
}
}
}
dump("Removed {$removed} mediaprofil type player that had no player");
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}