From 37aea9ae9ade646c4f54d08edb1af6ec39aec847 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Thu, 7 Nov 2024 23:52:45 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B2=20?= =?UTF-8?q?=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B5=20=D0=B0=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D0=B1=D1=83=D1=82=D1=8B=20-=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=20flusher=20-=20=D0=A3=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=B8=D0=B7=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D1=8F=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=20flusher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/Bitrix24Account.php | 24 ------------------- .../Doctrine/Bitrix24AccountRepository.php | 12 ++-------- .../UseCase/RenewAuthToken/Handler.php | 1 + .../UseCase/RenewAuthToken/HandlerTest.php | 3 +++ 4 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 3d33815..b0cb6e4 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -25,18 +25,11 @@ use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException; use Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException; use Bitrix24\SDK\Core\Response\DTO\RenewedAuthToken; -use Bitrix24\Lib\Bitrix24Accounts\Infrastructure\Doctrine\Bitrix24AccountRepository; use Carbon\CarbonImmutable; -use Doctrine\ORM\Mapping\Embedded; use Override; -use Symfony\Bridge\Doctrine\Types\UuidType; -use Symfony\Component\Serializer\Annotation\Ignore; -use Symfony\Component\Serializer\Annotation\SerializedName; use Symfony\Component\Uid\Uuid; -use Doctrine\ORM\Mapping as ORM; use Symfony\Contracts\EventDispatcher\Event; -#[ORM\Entity(repositoryClass: Bitrix24AccountRepository::class)] class Bitrix24Account implements Bitrix24AccountInterface, AggregateRootEventsEmitterInterface { private string $accessToken; @@ -60,33 +53,16 @@ class Bitrix24Account implements Bitrix24AccountInterface, AggregateRootEventsEm public function __construct( - #[ORM\Id] - #[ORM\Column(type: UuidType::NAME, unique: true)] private Uuid $id, - #[ORM\Column(name: 'b24_user_id', type: 'integer', nullable: false)] - #[SerializedName('b24_user_id')] private readonly int $bitrix24UserId, - #[ORM\Column(name: 'is_b24_user_admin', type: 'boolean', nullable: false)] - #[SerializedName('is_b24_user_admin')] private readonly bool $isBitrix24UserAdmin, /** bitrix24 portal unique id */ - #[ORM\Column(name: 'member_id', type: 'string', nullable: false)] - #[SerializedName('member_id')] private readonly string $memberId, - #[ORM\Column(name: 'domain_url', type: 'string', nullable: false)] - #[SerializedName('domain_url')] private string $domainUrl, - #[ORM\Column(name: 'account_status', type: 'string', nullable: false, enumType: Bitrix24AccountStatus::class)] private Bitrix24AccountStatus $status, AuthToken $authToken, - #[ORM\Column(name: 'created_at_utc', type: 'carbon_immutable', precision: 3, nullable: false)] - #[Ignore] private readonly CarbonImmutable $createdAt, - #[ORM\Column(name: 'update_at_utc', type: 'carbon_immutable', precision: 3, nullable: false)] - #[Ignore] private CarbonImmutable $updatedAt, - #[ORM\Column(name: 'application_version', type: 'integer', nullable: false)] - #[Ignore] private int $applicationVersion, Scope $applicationScope, ) diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index 93196ad..122ef99 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -49,12 +49,7 @@ public function getById(Uuid $uuid): Bitrix24AccountInterface #[Override] public function save(Bitrix24AccountInterface $bitrix24Account): void { - $this->getEntityManager()->persist($bitrix24Account); - - //todo discuss add flush arg to contract or add flusher in usecases? - $this->getEntityManager()->flush(); - } /** @@ -81,18 +76,15 @@ public function findByMemberId(string $memberId, ?Bitrix24AccountStatus $bitrix2 * @inheritdoc */ #[Override] - public function delete(Uuid $uuid, bool $flush = false): void + public function delete(Uuid $uuid): void { $bitrix24Account = $this->getEntityManager()->getRepository(Bitrix24Account::class)->find($uuid); + if ($bitrix24Account === null) { throw new Bitrix24AccountNotFoundException(sprintf('bitrix24 account not found by id %s', $uuid->toRfc4122())); } $this->getEntityManager()->remove($bitrix24Account); - - if ($flush) { - $this->getEntityManager()->flush(); - } } public function findAllActive(): array diff --git a/src/Bitrix24Accounts/UseCase/RenewAuthToken/Handler.php b/src/Bitrix24Accounts/UseCase/RenewAuthToken/Handler.php index e5987d3..3fe5632 100644 --- a/src/Bitrix24Accounts/UseCase/RenewAuthToken/Handler.php +++ b/src/Bitrix24Accounts/UseCase/RenewAuthToken/Handler.php @@ -62,6 +62,7 @@ public function handle(Command $command): void } $targetAccount = $accounts[0]; + /** * @var Bitrix24AccountInterface|AggregateRootEventsEmitterInterface $targetAccount */ diff --git a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php index 6d28b3e..6ea1f6e 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php @@ -40,6 +40,7 @@ class HandlerTest extends TestCase { private Handler $handler; + private Flusher $flusher; private Bitrix24AccountRepositoryInterface $repository; private TraceableEventDispatcher $eventDispatcher; @@ -62,6 +63,8 @@ public function testRenewAuthTokenWithoutBitrix24UserId(): void $this->repository->save($bitrix24Account); + $this->flusher->flush(); + $newAuthToken = new AuthToken('new_1', 'new_2', 3600); $this->handler->handle( new Command(