Skip to content

Add application install #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: add-application-install
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8b5f5e0
- Добавил сущность ApplicationInstallation.php
KarlsonComplete Feb 22, 2025
de8b7fa
- Реализовал большинство методов для сущности ApplicationInstallation
KarlsonComplete Feb 24, 2025
235f52a
Добавил репозиторий и написал методы для ApplicationInstall
KarlsonComplete Feb 25, 2025
848b1a2
Добавил 3 метку в домен
KarlsonComplete Mar 2, 2025
a943adc
Поправил сущности
KarlsonComplete Mar 5, 2025
ae6dde2
Маппинг сущности applicationInstallation
KarlsonComplete Mar 5, 2025
e12cf66
- Поправил сущность инсталяции
KarlsonComplete Mar 9, 2025
34d49c0
- Тесты на репозиторий
KarlsonComplete Mar 10, 2025
1f29be1
- Поправил домен и провел правки по комментам.
KarlsonComplete Mar 16, 2025
c58be6e
- Поправил тесты на репозиторий
KarlsonComplete Mar 18, 2025
da750c5
- Поправил тесты на репозиторий
KarlsonComplete Mar 23, 2025
cb71267
- Добавил юнит тесты из sdk
KarlsonComplete Mar 23, 2025
5f04b1d
- Протестировал unit тесты.
KarlsonComplete Mar 24, 2025
fc85738
- Юзанул ректор и cs-fixer
KarlsonComplete Mar 24, 2025
edb04f3
- Юзанул ректор и cs-fixer
KarlsonComplete Mar 30, 2025
5eef873
- Добавил в сущность метод для выброса события установки
KarlsonComplete Mar 31, 2025
50e64f4
- Поправил тест на установку (включающий в себя аккаунт битрикс 24)
KarlsonComplete Apr 3, 2025
6fe5e16
- Обновил тест на установку (включающий в себя аккаунт битрикс 24)
KarlsonComplete Apr 5, 2025
bb67297
- Начал писать тест переустановки приложения
KarlsonComplete Apr 6, 2025
a42d3a1
- Правки для теста переустановки
KarlsonComplete Apr 13, 2025
231526f
- Правки по битрикс 24 аккаунту убрали (дату создания / дату обновлен…
KarlsonComplete Apr 16, 2025
12c486e
Правки установки
KarlsonComplete Apr 20, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xs="https://www.w3.org/2001/XMLSchema"
xmlns:orm="https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Bitrix24\Lib\ApplicationInstallations\Entity\ApplicationInstallation"
table="application_installation">
<id name="id" type="uuid" column="id">

</id>

<field name="status" enum-type="string" column="status" nullable="false"/>

<field name="createdAt" type="carbon_immutable" column="created_at_utc" precision="3" nullable="false"/>

<field name="updatedAt" type="carbon_immutable" column="update_at_utc" precision="3" nullable="false"/>

<field name="bitrix24AccountId" type="uuid" column="bitrix_24_account_id" nullable="false"/>

<field name="contactPersonId" type="uuid" column="contact_person_id" nullable="true"/>

<field name="bitrix24PartnerContactPersonId" type="uuid" column="bitrix_24_partner_contact_person_id"
nullable="true"/>

<field name="bitrix24PartnerId" type="uuid" column="bitrix_24_partner_id" nullable="true"/>

<field name="externalId" type="string" column="external_id" nullable="true"/>

<field name="portalLicenseFamily" enum-type="string" column="portal_license_family" nullable="false"/>

<field name="portalUsersCount" type="integer" column="portal_users_count" nullable="true"/>

<field name="comment" type="text" column="comment" nullable="true"/>

<embedded name="applicationStatus" class="Bitrix24\SDK\Application\ApplicationStatus"/>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

<field name="applicationVersion" type="integer" column="application_version" nullable="false"/>

<field name="comment" type="text" column="comment" nullable="true"/>

<embedded name="authToken" class="Bitrix24\SDK\Core\Credentials\AuthToken"/>

<embedded name="applicationScope" class="Bitrix24\SDK\Core\Credentials\Scope"/>
Expand Down
7 changes: 7 additions & 0 deletions config/xml/Bitrix24.SDK.Application.ApplicationStatus.dcm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xs="https://www.w3.org/2001/XMLSchema"
xmlns:orm="https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="Bitrix24\SDK\Application\ApplicationStatus">
<field name="statusCode" type="json" nullable="true" column="status_code"/>
</embeddable>
</doctrine-mapping>
344 changes: 344 additions & 0 deletions src/ApplicationInstallations/Entity/ApplicationInstallation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
<?php

declare(strict_types=1);

namespace Bitrix24\Lib\ApplicationInstallations\Entity;

use Bitrix24\Lib\AggregateRoot;
use Bitrix24\SDK\Application\ApplicationStatus;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Entity\ApplicationInstallationInterface;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Entity\ApplicationInstallationStatus;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationBlockedEvent;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationCreatedEvent;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationFinishedEvent;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationUnblockedEvent;
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationUninstalledEvent;
use Bitrix24\SDK\Application\PortalLicenseFamily;
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
use Carbon\CarbonImmutable;
use Symfony\Component\Uid\Uuid;

class ApplicationInstallation extends AggregateRoot implements ApplicationInstallationInterface
{
public function __construct(
private readonly Uuid $id,
private ApplicationInstallationStatus $status,
private readonly CarbonImmutable $createdAt,
private CarbonImmutable $updatedAt,
private readonly Uuid $bitrix24AccountId,
private ApplicationStatus $applicationStatus,
private PortalLicenseFamily $portalLicenseFamily,
private ?int $portalUsersCount,
private ?Uuid $contactPersonId,
private ?Uuid $bitrix24PartnerContactPersonId,
private ?Uuid $bitrix24PartnerId,
private ?string $externalId,
private ?string $comment = null,
private $isEmitApplicationInstallationCreatedEvent = false,
) {
$this->addApplicationCreatedEventIfNeeded($this->isEmitApplicationInstallationCreatedEvent);
}

#[\Override]
public function getId(): Uuid
{
return $this->id;
}

#[\Override]
public function getCreatedAt(): CarbonImmutable
{
return $this->createdAt;
}

#[\Override]
public function getUpdatedAt(): CarbonImmutable
{
return $this->updatedAt;
}

#[\Override]
public function getBitrix24AccountId(): Uuid
{
return $this->bitrix24AccountId;
}

#[\Override]
public function getContactPersonId(): ?Uuid
{
return $this->contactPersonId;
}

#[\Override]
public function changeContactPerson(?Uuid $uuid): void
{
$this->updatedAt = new CarbonImmutable();

$this->contactPersonId = $uuid;

$this->events[] = new Events\ApplicationInstallationContactPersonChangedEvent(
$this->id,
$this->updatedAt,
$this->contactPersonId,
$uuid
);
}

#[\Override]
public function getBitrix24PartnerContactPersonId(): ?Uuid
{
return $this->bitrix24PartnerContactPersonId;
}

#[\Override]
public function changeBitrix24PartnerContactPerson(?Uuid $uuid): void
{
$this->updatedAt = new CarbonImmutable();

$this->bitrix24PartnerContactPersonId = $uuid;

$this->events[] = new Events\ApplicationInstallationBitrix24PartnerContactPersonChangedEvent(
$this->id,
$this->updatedAt,
$this->bitrix24PartnerContactPersonId,
$uuid
);
}

#[\Override]
public function getBitrix24PartnerId(): ?Uuid
{
return $this->bitrix24PartnerId;
}

#[\Override]
public function changeBitrix24Partner(?Uuid $uuid): void
{
$this->updatedAt = new CarbonImmutable();

$this->bitrix24PartnerId = $uuid;

$this->events[] = new Events\ApplicationInstallationBitrix24PartnerChangedEvent(
$this->id,
$this->updatedAt,
$this->bitrix24PartnerId,
$uuid
);
}

#[\Override]
public function getExternalId(): ?string
{
return $this->externalId;
}

#[\Override]
public function setExternalId(?string $externalId): void
{
if ('' === $externalId) {
throw new InvalidArgumentException('ExternalId cannot be empty string');
}

$this->externalId = $externalId;
}

#[\Override]
public function getStatus(): ApplicationInstallationStatus
{
return $this->status;
}

#[\Override]
public function applicationInstalled(): void
{
if (
ApplicationInstallationStatus::new !== $this->status
&& ApplicationInstallationStatus::blocked !== $this->status
) {
throw new \LogicException(
sprintf(
'installation was interrupted because status must be in new or blocked,but your status is %s',
$this->status->value
)
);
}

$this->status = ApplicationInstallationStatus::active;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new ApplicationInstallationFinishedEvent(
$this->id,
$this->updatedAt,
$this->bitrix24AccountId,
$this->portalLicenseFamily,
$this->contactPersonId,
$this->bitrix24PartnerContactPersonId,
$this->bitrix24PartnerId
);
}

#[\Override]
public function applicationUninstalled(): void
{
if (
ApplicationInstallationStatus::active !== $this->status
&& ApplicationInstallationStatus::blocked !== $this->status
) {
throw new \LogicException(
sprintf(
'installation was interrupted because status must be in active or blocked, but your status is %s',
$this->status->value
)
);
}

$this->status = ApplicationInstallationStatus::deleted;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new ApplicationInstallationUninstalledEvent(
$this->id,
$this->updatedAt,
$this->bitrix24AccountId,
$this->contactPersonId,
$this->bitrix24PartnerId,
$this->bitrix24PartnerId,
$this->externalId
);
}

#[\Override]
public function markAsActive(?string $comment): void
{
if (ApplicationInstallationStatus::blocked !== $this->status) {
throw new \LogicException(
sprintf(
'you must be in status blocked to complete the installation, now status is «%s»',
$this->status->value
)
);
}

$this->status = ApplicationInstallationStatus::active;
$this->comment = $comment;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new ApplicationInstallationUnblockedEvent(
$this->id,
$this->updatedAt,
$this->comment
);
}

#[\Override]
public function markAsBlocked(?string $comment): void
{
if (
ApplicationInstallationStatus::new !== $this->status
&& ApplicationInstallationStatus::active !== $this->status
) {
throw new \LogicException(sprintf(
'You can block application installation only in status new or active,but your status is «%s»',
$this->status->value
));
}

$this->status = ApplicationInstallationStatus::blocked;
$this->comment = $comment;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new ApplicationInstallationBlockedEvent(
$this->id,
new CarbonImmutable(),
$this->comment
);
}

#[\Override]
public function getApplicationStatus(): ApplicationStatus
{
return $this->applicationStatus;
}

#[\Override]
public function changeApplicationStatus(ApplicationStatus $applicationStatus): void
{
if ($this->applicationStatus !== $applicationStatus) {
$this->applicationStatus = $applicationStatus;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new Events\ApplicationInstallationApplicationStatusChangedEvent(
$this->id,
$this->updatedAt,
$applicationStatus
);
}
}

#[\Override]
public function getPortalLicenseFamily(): PortalLicenseFamily
{
return $this->portalLicenseFamily;
}

#[\Override]
public function changePortalLicenseFamily(PortalLicenseFamily $portalLicenseFamily): void
{
if ($this->portalLicenseFamily !== $portalLicenseFamily) {
$this->updatedAt = new CarbonImmutable();
$this->portalLicenseFamily = $portalLicenseFamily;

$this->events[] = new Events\ApplicationInstallationPortalLicenseFamilyChangedEvent(
$this->id,
$this->updatedAt,
$this->portalLicenseFamily,
$portalLicenseFamily
);
}
}

#[\Override]
public function getPortalUsersCount(): ?int
{
return $this->portalUsersCount;
}

#[\Override]
public function changePortalUsersCount(int $usersCount): void
{
if ($usersCount < 0) {
throw new \InvalidArgumentException('Users count can not be negative');
}

if ($this->portalUsersCount !== $usersCount) {
$this->portalUsersCount = $usersCount;
$this->updatedAt = new CarbonImmutable();

$this->events[] = new Events\ApplicationInstallationPortalUsersCountChangedEvent(
$this->id,
$this->updatedAt,
$this->portalUsersCount,
$usersCount
);
}
}

#[\Override]
public function getComment(): ?string
{
return $this->comment;
}

private function addApplicationCreatedEventIfNeeded(bool $isEmitCreatedEvent): void
{

if ($isEmitCreatedEvent) {
// Создание события и добавление его в массив событий
$this->events[] = new ApplicationInstallationCreatedEvent(
$this->id,
$this->createdAt,
$this->bitrix24AccountId
);
}
}
}
Loading
Loading