-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: add-application-install
Are you sure you want to change the base?
Changes from 11 commits
8b5f5e0
de8b7fa
235f52a
848b1a2
a943adc
ae6dde2
e12cf66
34d49c0
1f29be1
c58be6e
da750c5
cb71267
5f04b1d
fc85738
edb04f3
5eef873
50e64f4
6fe5e16
bb67297
a42d3a1
231526f
12c486e
68f4056
f5f72c3
1aef0f8
1782b40
0f6d191
d0b6d5c
db88723
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
<?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\ApplicationInstallationFinishedEvent; | ||
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationUnblockedEvent; | ||
use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Events\ApplicationInstallationUninstalledEvent; | ||
use Bitrix24\SDK\Application\PortalLicenseFamily; | ||
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 readonly ApplicationStatus $applicationStatus, | ||
private readonly PortalLicenseFamily $portalLicenseFamily, | ||
private readonly ?int $portalUsersCount, | ||
private readonly ?Uuid $contactPersonId, | ||
private readonly ?Uuid $bitrix24PartnerContactPersonId, | ||
private readonly ?Uuid $bitrix24PartnerId, | ||
private ?string $externalId, | ||
private ?string $comment = null | ||
) {} | ||
|
||
#[\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 | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? необязательность параметра говорит о том, что можно и поменять, а можно и очистить. Имхо надо убрать, а если нужна очистка/удаление, то лучше добавить еще метод |
||
{ | ||
$this->updatedAt = new CarbonImmutable(); | ||
|
||
$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 | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. аналогичнго выше коммент |
||
{ | ||
$this->updatedAt = new CarbonImmutable(); | ||
|
||
$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 | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и тут тоже |
||
{ | ||
$this->updatedAt = new CarbonImmutable(); | ||
|
||
$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 | ||
{ | ||
$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 | ||
{ | ||
$this->status = ApplicationInstallationStatus::deleted; | ||
$this->updatedAt = new CarbonImmutable(); | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$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) { | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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(); | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$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 | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if ($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) { | ||
camaxtly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$this->updatedAt = new CarbonImmutable(); | ||
|
||
$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 | ||
KarlsonComplete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if ($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; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.