Julien Fastré d2323e91ca
new cs rule: single_line_empty_body
Rule is added to the last version of php-cs-fixer
2023-09-12 15:58:59 +02:00

46 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use function count;
/**
* Check if each person do not have multiple addresses with the same valideFrom.
*/
class Version20160422000000 extends AbstractMigration
{
public function down(Schema $schema): void {}
public function up(Schema $schema): void
{
$stmt = $this->connection->query('SELECT COUNT(*), pe.id, ad.validfrom FROM person AS pe
INNER JOIN chill_person_persons_to_addresses AS pe_ad ON pe.id = pe_ad.person_id
INNER JOIN chill_main_address AS ad ON ad.id = pe_ad.address_id
GROUP BY pe.id, ad.validfrom
HAVING COUNT(*) > 1');
$personWithTwoAddressWithSameValidFrom = $stmt->fetchAll();
foreach ($personWithTwoAddressWithSameValidFrom as $p) {
$this->warnIf(true, 'The person with id ' . $p['id'] . ' has two adresses with the same validFrom date');
}
$this->abortIf(
count($personWithTwoAddressWithSameValidFrom) !== 0,
'There exists some person with multiple adress with the same validFrom'
);
}
}