Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,5 @@

readonly class Command
{
public string $oldDomain;

public string $newDomain;

public function __construct(
Domain $oldDomain,
Domain $newDomain
) {
$this->oldDomain = $oldDomain->getValue();
$this->newDomain = $newDomain->getValue();
}
public function __construct(public Domain $oldDomain, public Domain $newDomain) {}
}
8 changes: 4 additions & 4 deletions src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public function __construct(
public function handle(Command $command): void
{
$this->logger->info('Bitrix24Accounts.ChangeDomainUrl.start', [
'b24_domain_url_old' => $command->oldDomain,
'b24_domain_url_new' => $command->newDomain,
'b24_domain_url_old' => $command->oldDomain->value,
'b24_domain_url_new' => $command->newDomain->value,
]);

/** @var AggregateRootEventsEmitterInterface[]|Bitrix24AccountInterface[] $accounts */
$accounts = $this->bitrix24AccountRepository->findByDomain($command->oldDomain);
$accounts = $this->bitrix24AccountRepository->findByDomain($command->oldDomain->value);
foreach ($accounts as $account) {
$account->changeDomainUrl($command->newDomain);
$account->changeDomainUrl($command->newDomain->value);
$this->bitrix24AccountRepository->save($account);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Bitrix24Accounts/UseCase/InstallFinish/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

readonly class Command
{
public string $domain;

public function __construct(
public string $applicationToken,
public string $memberId,
Domain $domain,
public Domain $domain,
public int $bitrix24UserId,
) {
$this->validate();
$this->domain = $domain->getValue();
}

private function validate(): void
Expand All @@ -26,7 +23,7 @@ private function validate(): void
throw new \InvalidArgumentException('Application token cannot be empty.');
}

if ('' === $this->memberId || '0' === $this->memberId) {
if ('' === $this->memberId) {
throw new \InvalidArgumentException('Member ID cannot be empty.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bitrix24Accounts/UseCase/InstallFinish/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function handle(Command $command): void
]);

/** @var AggregateRootEventsEmitterInterface|Bitrix24AccountInterface $bitrix24Account */
$bitrix24Account = $this->getSingleAccountByMemberId($command->domain, $command->memberId, $command->bitrix24UserId);
$bitrix24Account = $this->getSingleAccountByMemberId($command->domain->value, $command->memberId, $command->bitrix24UserId);

$bitrix24Account->applicationInstalled($command->applicationToken);

Expand Down
5 changes: 1 addition & 4 deletions src/Bitrix24Accounts/UseCase/InstallStart/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@

readonly class Command
{
public string $domain;

public function __construct(
public Uuid $uuid,
public int $bitrix24UserId,
public bool $isBitrix24UserAdmin,
public string $memberId,
Domain $domain,
public Domain $domain,
public AuthToken $authToken,
public int $applicationVersion,
public Scope $applicationScope
) {
$this->validate();
$this->domain = $domain->getValue();
}

private function validate(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Bitrix24Accounts/UseCase/InstallStart/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$command->bitrix24UserId,
$command->isBitrix24UserAdmin,
$command->memberId,
$command->domain,
$command->domain->value,
Bitrix24AccountStatus::new,
$command->authToken,
new CarbonImmutable(),
Expand All @@ -43,7 +43,7 @@
true
);

$isAccountExists = $this->bitrix24AccountRepository->existsById($bitrix24Account->getId());

Check failure on line 46 in src/Bitrix24Accounts/UseCase/InstallStart/Handler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ubuntu-latest)

Call to an undefined method Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterface::existsById().

if (!$isAccountExists) {
$this->bitrix24AccountRepository->save($bitrix24Account);
Expand Down
39 changes: 39 additions & 0 deletions src/Bitrix24Accounts/UseCase/UpdateVersion/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\UpdateVersion;

use Bitrix24\SDK\Core\Credentials\AuthToken;
use Bitrix24\SDK\Core\Credentials\Scope;
use Symfony\Component\Uid\Uuid;

readonly class Command
{
public function __construct(
public Uuid $uuid,
public int $bitrix24UserId,
public bool $isBitrix24UserAdmin,
public string $memberId,
public AuthToken $authToken,
public int $newApplicationVersion,
public Scope $newApplicationScope
) {
$this->validate();
}

private function validate(): void
{
if ($this->bitrix24UserId <= 0) {
throw new \InvalidArgumentException('Bitrix24 User ID must be a positive integer.');
}

if ('' === $this->memberId) {
throw new \InvalidArgumentException('Member ID must be a non-empty string.');
}

if ($this->newApplicationVersion <= 0) {
throw new \InvalidArgumentException('Application version must be a positive integer.');
}
}
}
92 changes: 92 additions & 0 deletions src/Bitrix24Accounts/UseCase/UpdateVersion/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\UpdateVersion;

use Bitrix24\Lib\Services\Flusher;
use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountInterface;
use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountStatus;
use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Exceptions\MultipleBitrix24AccountsFoundException;
use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterface;
use Bitrix24\SDK\Application\Contracts\Events\AggregateRootEventsEmitterInterface;
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
use Psr\Log\LoggerInterface;

readonly class Handler
{
public function __construct(
private Bitrix24AccountRepositoryInterface $bitrix24AccountRepository,
private Flusher $flusher,
private LoggerInterface $logger
) {}

/**
* @throws MultipleBitrix24AccountsFoundException
* @throws InvalidArgumentException
*/
public function handle(Command $command): void
{
$this->logger->info('Bitrix24Accounts.UpdateVersion.start', [
'uuid' => $command->uuid,
'bitrix24_user_id' => $command->bitrix24UserId,
'is_bitrix24UserAdmin' => $command->isBitrix24UserAdmin,
'member_id' => $command->memberId,
'auth_token' => $command->authToken,
'new_application_version' => $command->newApplicationVersion,
'new_application_scope' => $command->newApplicationScope,
]);

$accounts = $this->bitrix24AccountRepository->findByMemberId(
$command->memberId,
Bitrix24AccountStatus::active,
$command->bitrix24UserId,
);

if ([] !== $accounts) {
/** @var AggregateRootEventsEmitterInterface|Bitrix24AccountInterface $bitrix24Account */
$bitrix24Account = $accounts[0];
$bitrix24Account->updateApplicationVersion(
$command->authToken,
$command->bitrix24UserId,
$command->newApplicationVersion,
$command->newApplicationScope,
);

$this->bitrix24AccountRepository->save($bitrix24Account);
$this->flusher->flush($bitrix24Account);

$this->logger->info('Bitrix24Accounts.UpdateVersion.finish', [
'uuid' => $command->uuid,
'bitrix24_user_id' => $command->bitrix24UserId,
'is_bitrix24UserAdmin' => $command->isBitrix24UserAdmin,
'member_id' => $command->memberId,
'auth_token' => $command->authToken,
'new_application_version' => $command->newApplicationVersion,
'new_application_scope' => $command->newApplicationScope,
]);
} else {
$this->logger->info(
'Bitrix24Accounts.UpdateVersion.NotFoundAccount',
[
'uuid' => $command->uuid,
'bitrix24_user_id' => $command->bitrix24UserId,
'is_bitrix24UserAdmin' => $command->isBitrix24UserAdmin,
'member_id' => $command->memberId,
'auth_token' => $command->authToken,
'new_application_version' => $command->newApplicationVersion,
'new_application_scope' => $command->newApplicationScope,
]
);

throw new MultipleBitrix24AccountsFoundException(
sprintf(
'bitrix24account not found by memberId %s, status %s and bitrix24UserId %s ',
$command->memberId,
'active',
$command->bitrix24UserId
)
);
}
}
}
7 changes: 1 addition & 6 deletions src/Bitrix24Accounts/ValueObjects/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@

readonly class Domain
{
private string $value;
public string $value;

public function __construct(string $domain)
{
$this->validate($domain);
$this->value = $domain;
}

public function getValue(): string
{
return $this->value;
}

private function validate(string $domain): void
{
// Регулярное выражение для проверки допустимых символов (латиница и кириллица)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,4 @@ public function testInstallExistingAccount(): void
)
);
}



#[Test]
public function testUpdateAppVersion(): void {}
}
Loading
Loading