mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
php cs fixer
This commit is contained in:
parent
94f26df81e
commit
c19d1ff0c7
@ -1,5 +1,14 @@
|
|||||||
<?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\PersonBundle\Actions\Remove\Handler;
|
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||||
|
|
||||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||||
@ -15,7 +24,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler implements PersonMoveSqlH
|
|||||||
|
|
||||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||||
{
|
{
|
||||||
$insertSql = sprintf(<<<SQL
|
$insertSql = sprintf(<<<'SQL'
|
||||||
INSERT INTO chill_person_accompanying_period_participation (person_id, accompanyingperiod_id, id, startdate, enddate)
|
INSERT INTO chill_person_accompanying_period_participation (person_id, accompanyingperiod_id, id, startdate, enddate)
|
||||||
SELECT %d, accompanyingperiod_id, nextval('chill_person_accompanying_period_id_seq'), startdate, enddate
|
SELECT %d, accompanyingperiod_id, nextval('chill_person_accompanying_period_id_seq'), startdate, enddate
|
||||||
FROM chill_person_accompanying_period_participation cpapp
|
FROM chill_person_accompanying_period_participation cpapp
|
||||||
@ -28,7 +37,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler implements PersonMoveSqlH
|
|||||||
)
|
)
|
||||||
SQL, $to->getId(), $from->getId(), $to->getId());
|
SQL, $to->getId(), $from->getId(), $to->getId());
|
||||||
|
|
||||||
$deleteSql = sprintf(<<<SQL
|
$deleteSql = sprintf(<<<'SQL'
|
||||||
DELETE FROM chill_person_accompanying_period_participation WHERE person_id = %d
|
DELETE FROM chill_person_accompanying_period_participation WHERE person_id = %d
|
||||||
SQL, $from->getId());
|
SQL, $from->getId());
|
||||||
|
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
<?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\PersonBundle\Actions\Remove\Handler;
|
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||||
|
|
||||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Repository\Person\PersonCenterHistoryRepository;
|
use Chill\PersonBundle\Repository\Person\PersonCenterHistoryRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
|
|
||||||
class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private PersonCenterHistoryRepository $centerHistoryRepository,
|
private PersonCenterHistoryRepository $centerHistoryRepository,
|
||||||
private EntityManagerInterface $em
|
) {
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supports(string $className, string $field): bool
|
public function supports(string $className, string $field): bool
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?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\PersonBundle\Actions\Remove\Handler;
|
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||||
|
|
||||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||||
@ -15,7 +24,7 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
|
|||||||
|
|
||||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||||
{
|
{
|
||||||
$sqlInsert = sprintf(<<<SQL
|
$sqlInsert = sprintf(<<<'SQL'
|
||||||
INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder)
|
INSERT INTO chill_person_household_members (id, person_id, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder)
|
||||||
SELECT nextval('chill_person_household_members_id_seq'), %d, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder
|
SELECT nextval('chill_person_household_members_id_seq'), %d, household_id, startdate, enddate, comment, sharedhousehold, position_id, holder
|
||||||
FROM chill_person_household_members cphm
|
FROM chill_person_household_members cphm
|
||||||
@ -26,13 +35,13 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
|
|||||||
person_id = %d
|
person_id = %d
|
||||||
AND daterange(cphm.startdate, cphm.enddate) && daterange(cphm_inner.startdate, cphm_inner.enddate)
|
AND daterange(cphm.startdate, cphm.enddate) && daterange(cphm_inner.startdate, cphm_inner.enddate)
|
||||||
)
|
)
|
||||||
SQL, $to->getId(), $from->getId(), $to->getId());
|
SQL, $to->getId(), $from->getId(), $to->getId());
|
||||||
|
|
||||||
$deleteSql = sprintf(<<<SQL
|
$deleteSql = sprintf(<<<'SQL'
|
||||||
DELETE FROM chill_person_household_members WHERE person_id = %d
|
DELETE FROM chill_person_household_members WHERE person_id = %d
|
||||||
SQL, $from->getId());
|
SQL, $from->getId());
|
||||||
|
|
||||||
return [$sqlInsert, $deleteSql];
|
return [$sqlInsert, $deleteSql];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?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\PersonBundle\Actions\Remove\Handler;
|
namespace Chill\PersonBundle\Actions\Remove\Handler;
|
||||||
|
|
||||||
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
|
||||||
@ -15,7 +24,7 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
|
|||||||
|
|
||||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||||
{
|
{
|
||||||
$insertSql = sprintf(<<<SQL
|
$insertSql = sprintf(<<<'SQL'
|
||||||
INSERT INTO chill_person_relationships (id, relation_id, reverse, fromperson_id, toperson_id)
|
INSERT INTO chill_person_relationships (id, relation_id, reverse, fromperson_id, toperson_id)
|
||||||
SELECT nextval('chill_person_relationships_id_seq'), relation_id, reverse, fromperson_id, toperson_id
|
SELECT nextval('chill_person_relationships_id_seq'), relation_id, reverse, fromperson_id, toperson_id
|
||||||
FROM chill_person_relationships cpr
|
FROM chill_person_relationships cpr
|
||||||
@ -28,7 +37,7 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
|
|||||||
)
|
)
|
||||||
SQL, $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId());
|
SQL, $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId());
|
||||||
|
|
||||||
$deleteSql = sprintf(<<<SQL
|
$deleteSql = sprintf(<<<'SQL'
|
||||||
DELETE FROM chill_person_relationships WHERE fromperson_id = %d;
|
DELETE FROM chill_person_relationships WHERE fromperson_id = %d;
|
||||||
DELETE FROM chill_person_relationships WHERE toperson_id = %d;
|
DELETE FROM chill_person_relationships WHERE toperson_id = %d;
|
||||||
SQL, $from->getId(), $from->getId());
|
SQL, $from->getId(), $from->getId());
|
||||||
|
@ -37,7 +37,7 @@ class PersonMove
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private EntityManagerInterface $em,
|
private EntityManagerInterface $em,
|
||||||
private PersonMoveManager $personMoveManager,
|
private PersonMoveManager $personMoveManager,
|
||||||
private EventDispatcherInterface $eventDispatcher
|
private EventDispatcherInterface $eventDispatcher
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
@ -78,9 +78,9 @@ class PersonMove
|
|||||||
|
|
||||||
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
|
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
|
||||||
|
|
||||||
if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) {
|
if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) {
|
||||||
$sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
|
$sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
|
if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
|
||||||
@ -148,32 +148,28 @@ class PersonMove
|
|||||||
$tableName = '';
|
$tableName = '';
|
||||||
|
|
||||||
if (array_key_exists('joinTable', $mapping)) {
|
if (array_key_exists('joinTable', $mapping)) {
|
||||||
// there is a join_table: we have to find conflict
|
// there is a join_table: we have to find conflict
|
||||||
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '')
|
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '')
|
||||||
. $mapping['joinTable']['name'];
|
. $mapping['joinTable']['name'];
|
||||||
|
|
||||||
$sqlInsert = sprintf(
|
$sqlInsert = sprintf(
|
||||||
"INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING",
|
"INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING",
|
||||||
$tableName,
|
$tableName,
|
||||||
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
||||||
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
|
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
|
||||||
$to->getId(),
|
$to->getId(),
|
||||||
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
|
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
|
||||||
$tableName,
|
$tableName,
|
||||||
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
||||||
$from->getId()
|
$from->getId()
|
||||||
);
|
);
|
||||||
|
|
||||||
$deleteSql = sprintf(
|
$deleteSql = sprintf(
|
||||||
"DELETE FROM %s WHERE %s = %d",
|
"DELETE FROM %s WHERE %s = %d",
|
||||||
$tableName,
|
$tableName,
|
||||||
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
||||||
$from->getId()
|
$from->getId()
|
||||||
);
|
);
|
||||||
|
|
||||||
return [
|
|
||||||
$sqlInsert, $deleteSql
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) {
|
foreach ($mapping['joinTable']['inverseJoinColumns'] as $columns) {
|
||||||
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
|
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
|
||||||
@ -183,7 +179,12 @@ class PersonMove
|
|||||||
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
|
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif (array_key_exists('joinColumns', $mapping)) {
|
return [
|
||||||
|
$sqlInsert, $deleteSql
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (array_key_exists('joinColumns', $mapping)) {
|
||||||
$tableName = $this->getTableName($metadata);
|
$tableName = $this->getTableName($metadata);
|
||||||
foreach ($mapping['joinColumns'] as $columns) {
|
foreach ($mapping['joinColumns'] as $columns) {
|
||||||
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
|
$sets[] = sprintf('%s = %d', $columns['name'], $to->getId());
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?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\PersonBundle\Actions\Remove;
|
namespace Chill\PersonBundle\Actions\Remove;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
@ -11,8 +20,7 @@ class PersonMoveManager
|
|||||||
* @var iterable<PersonMoveSqlHandlerInterface>
|
* @var iterable<PersonMoveSqlHandlerInterface>
|
||||||
*/
|
*/
|
||||||
private iterable $handlers,
|
private iterable $handlers,
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +28,7 @@ class PersonMoveManager
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasHandler(string $className, string $field): bool
|
public function hasHandler(string $className, string $field): bool
|
||||||
{
|
{
|
||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
if ($handler->supports($className, $field)) {
|
if ($handler->supports($className, $field)) {
|
||||||
@ -28,14 +36,14 @@ class PersonMoveManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string $className
|
* @param class-string $className
|
||||||
* @return array<string>
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||||
{
|
{
|
||||||
foreach ($this->handlers as $handler) {
|
foreach ($this->handlers as $handler) {
|
||||||
if ($handler->supports($className, $field)) {
|
if ($handler->supports($className, $field)) {
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?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\PersonBundle\Actions\Remove;
|
namespace Chill\PersonBundle\Actions\Remove;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
@ -11,7 +20,7 @@ interface PersonMoveSqlHandlerInterface
|
|||||||
*/
|
*/
|
||||||
public function supports(string $className, string $field): bool;
|
public function supports(string $className, string $field): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param class-string $className
|
* @param class-string $className
|
||||||
* @return array<string>
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<?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 Action\Remove;
|
namespace Action\Remove;
|
||||||
|
|
||||||
use Chill\ActivityBundle\Entity\Activity;
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
@ -21,6 +30,10 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
class PersonMoveTest extends KernelTestCase
|
class PersonMoveTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
@ -121,9 +134,9 @@ class PersonMoveTest extends KernelTestCase
|
|||||||
$move = new PersonMove($this->em, $this->personMoveManager, $this->eventDispatcher);
|
$move = new PersonMove($this->em, $this->personMoveManager, $this->eventDispatcher);
|
||||||
$sqls = $move->getSQL($personA, $personB);
|
$sqls = $move->getSQL($personA, $personB);
|
||||||
$this->em->getConnection()->transactional(function (Connection $conn) use ($personA, $personB, $sqls) {
|
$this->em->getConnection()->transactional(function (Connection $conn) use ($personA, $personB, $sqls) {
|
||||||
foreach ($sqls as $sql) {
|
foreach ($sqls as $sql) {
|
||||||
$conn->executeStatement($sql);
|
$conn->executeStatement($sql);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$personsByIdOfA = $this->em->createQuery("SELECT p FROM " . Person::class . " p WHERE p.id = :id")
|
$personsByIdOfA = $this->em->createQuery("SELECT p FROM " . Person::class . " p WHERE p.id = :id")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user