Skip to content

Commit

Permalink
Merge pull request #2586 from irontec/PROVIDER-678-DDI-pool
Browse files Browse the repository at this point in the history
Company nullable in ddi pool
  • Loading branch information
danigargar authored Mar 21, 2024
2 parents 87e8626 + de7810f commit 745032e
Show file tree
Hide file tree
Showing 15 changed files with 45,839 additions and 33,574 deletions.
11 changes: 9 additions & 2 deletions asterisk/agi/src/Agi/Action/ExternalFilterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Agi\Wrapper;
use Ivoz\Provider\Domain\Model\CalendarPeriod\CalendarPeriodInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Model\Ddi\DdiInterface;
use Ivoz\Provider\Domain\Model\ExternalCallFilter\ExternalCallFilterInterface;
use Ivoz\Provider\Domain\Model\HolidayDate\HolidayDateInterface;
Expand Down Expand Up @@ -117,10 +118,13 @@ public function processHoliday()
// Play holiday louction
$this->agi->playbackLocution($locution);

/** @var CompanyInterface $company */
$company = $ddi->getCompany();

// Set Diversion information
$count = $this->agi->getRedirecting('count');
$this->agi->setRedirecting('count,i', ++$count);
$this->agi->setRedirecting('from-name,i', $ddi->getCompany()->getName());
$this->agi->setRedirecting('from-name,i', $company->getName());
$this->agi->setRedirecting('from-num,i', $ddi->getDDIE164());
$this->agi->setRedirecting('reason', 'time_of_day');

Expand Down Expand Up @@ -168,10 +172,13 @@ public function processOutOfSchedule()
// Play holiday locution
$this->agi->playbackLocution($locution);

/** @var CompanyInterface $company */
$company = $ddi->getCompany();

// Set Diversion information
$count = $this->agi->getRedirecting('count');
$this->agi->setRedirecting('count,i', ++$count);
$this->agi->setRedirecting('from-name,i', $ddi->getCompany()->getName());
$this->agi->setRedirecting('from-name,i', $company->getName());
$this->agi->setRedirecting('from-num,i', $ddi->getDDIE164());
$this->agi->setRedirecting('reason', 'time_of_day');

Expand Down
11 changes: 9 additions & 2 deletions asterisk/agi/src/Agi/Agents/DdiAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Agi\Agents;

use Agi\Wrapper;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Model\Ddi\DdiInterface;

class DdiAgent implements AgentInterface
Expand Down Expand Up @@ -41,7 +42,10 @@ public function getId()

public function getCompany()
{
return $this->ddi->getCompany();
/** @var CompanyInterface $company */
$company = $this->ddi->getCompany();

return $company;
}

public function getLanguageCode()
Expand All @@ -55,7 +59,10 @@ public function getOutgoingDdi($destination)
$ddi = $this->ddi;

// If user has OutgoingDDI rules, check if we have to override current DDI
$outgoingDDIRule = $this->getCompany()->getOutgoingDDIRule();
/** @var CompanyInterface $company */
$company = $this->getCompany();

$outgoingDDIRule = $company->getOutgoingDDIRule();
if ($outgoingDDIRule) {
$this->agi->verbose("Checking %s for destination %s", $outgoingDDIRule, $destination);
// Check if outgoing DDI rule matches for given destination
Expand Down
2 changes: 2 additions & 0 deletions asterisk/agi/src/Dialplan/Trunks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Agi\Wrapper;
use Assert\Assertion;
use Doctrine\ORM\EntityManagerInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Model\Ddi\Ddi;
use RouteHandlerAbstract;

Expand Down Expand Up @@ -87,6 +88,7 @@ public function process()
$this->agi->setVariable("__CALL_ID", $this->agi->getCallId());

// Get company MusicClass: company, Generic or default
/** @var CompanyInterface $company */
$company = $ddi->getCompany();
$this->agi->setVariable("__COMPANYID", $company->getId());
$this->agi->setVariable("CHANNEL(musicclass)", $company->getMusicClass());
Expand Down
21 changes: 14 additions & 7 deletions library/Ivoz/Provider/Domain/Model/Ddi/Ddi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Assert\Assertion;
use Ivoz\Provider\Domain\Traits\RoutableTrait;
use Ivoz\Provider\Domain\Model\Domain\DomainInterface;
use Ivoz\Provider\Domain\Model\Ddi\DdiInterface;

/**
* Ddi
Expand Down Expand Up @@ -49,20 +48,20 @@ public function __toString(): string

protected function sanitizeValues(): void
{
$isNew = $this->isNew();
$changedClient = $this->hasChanged('companyId');
$initialClient = $this->getInitialValue('companyId');

if (!$isNew && $changedClient) {
if ($changedClient && $initialClient !== null) {
throw new \DomainException(
'Forbidden ddi client update',
403
);
}


if (! $this->getCountry()) {
$company = $this->getCompany();
if (! $this->getCountry() && $company) {
$this->setCountry(
$this->getCompany()->getCountry()
$company->getCountry()
);
}
$country = $this->getCountry();
Expand All @@ -89,6 +88,11 @@ public function setDdi(string $ddi): static
public function getDomain(): ?DomainInterface
{
$company = $this->getCompany();

if (!$company) {
return null;
}

$brand = $company->getBrand();

return $brand->getDomain();
Expand All @@ -97,10 +101,13 @@ public function getDomain(): ?DomainInterface
public function getLanguageCode(): string
{
$language = $this->getLanguage();

if (!$language) {
$company = $this->getCompany();

return $company->getLanguageCode();
return $company
? $company->getLanguageCode()
: $this->getBrand()->getLanguage()->getIden();
}

return $language->getIden();
Expand Down
18 changes: 7 additions & 11 deletions library/Ivoz/Provider/Domain/Model/Ddi/DdiAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ abstract class DdiAbstract
protected $type = 'inout';

/**
* @var CompanyInterface
* @var ?CompanyInterface
* inversedBy ddis
*/
protected $company;
protected $company = null;

/**
* @var BrandInterface
Expand Down Expand Up @@ -251,8 +251,6 @@ public static function fromDto(
Assertion::notNull($recordCalls, 'getRecordCalls value is null, but non null value was expected.');
$type = $dto->getType();
Assertion::notNull($type, 'getType value is null, but non null value was expected.');
$company = $dto->getCompany();
Assertion::notNull($company, 'getCompany value is null, but non null value was expected.');
$brand = $dto->getBrand();
Assertion::notNull($brand, 'getBrand value is null, but non null value was expected.');

Expand All @@ -268,7 +266,7 @@ public static function fromDto(
->setDisplayName($dto->getDisplayName())
->setRouteType($dto->getRouteType())
->setFriendValue($dto->getFriendValue())
->setCompany($fkTransformer->transform($company))
->setCompany($fkTransformer->transform($dto->getCompany()))
->setBrand($fkTransformer->transform($brand))
->setConferenceRoom($fkTransformer->transform($dto->getConferenceRoom()))
->setLanguage($fkTransformer->transform($dto->getLanguage()))
Expand Down Expand Up @@ -305,8 +303,6 @@ public function updateFromDto(
Assertion::notNull($recordCalls, 'getRecordCalls value is null, but non null value was expected.');
$type = $dto->getType();
Assertion::notNull($type, 'getType value is null, but non null value was expected.');
$company = $dto->getCompany();
Assertion::notNull($company, 'getCompany value is null, but non null value was expected.');
$brand = $dto->getBrand();
Assertion::notNull($brand, 'getBrand value is null, but non null value was expected.');

Expand All @@ -319,7 +315,7 @@ public function updateFromDto(
->setRouteType($dto->getRouteType())
->setFriendValue($dto->getFriendValue())
->setType($type)
->setCompany($fkTransformer->transform($company))
->setCompany($fkTransformer->transform($dto->getCompany()))
->setBrand($fkTransformer->transform($brand))
->setConferenceRoom($fkTransformer->transform($dto->getConferenceRoom()))
->setLanguage($fkTransformer->transform($dto->getLanguage()))
Expand Down Expand Up @@ -383,7 +379,7 @@ protected function __toArray(): array
'routeType' => self::getRouteType(),
'friendValue' => self::getFriendValue(),
'type' => self::getType(),
'companyId' => self::getCompany()->getId(),
'companyId' => self::getCompany()?->getId(),
'brandId' => self::getBrand()->getId(),
'conferenceRoomId' => self::getConferenceRoom()?->getId(),
'languageId' => self::getLanguage()?->getId(),
Expand Down Expand Up @@ -557,14 +553,14 @@ public function getType(): string
return $this->type;
}

public function setCompany(CompanyInterface $company): static
public function setCompany(?CompanyInterface $company = null): static
{
$this->company = $company;

return $this;
}

public function getCompany(): CompanyInterface
public function getCompany(): ?CompanyInterface
{
return $this->company;
}
Expand Down
4 changes: 2 additions & 2 deletions library/Ivoz/Provider/Domain/Model/Ddi/DdiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public function getFriendValue(): ?string;

public function getType(): string;

public function setCompany(CompanyInterface $company): static;
public function setCompany(?CompanyInterface $company = null): static;

public function getCompany(): CompanyInterface;
public function getCompany(): ?CompanyInterface;

public function getBrand(): BrandInterface;

Expand Down
2 changes: 1 addition & 1 deletion library/Ivoz/Provider/Domain/Service/Ddi/DdiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function fromMassProvisioningCsv(
(int) $country->getId()
);

if ($ddi) {
if ($ddi && $ddi->getCompany() !== null) {
if ($ddi->getCompany()->getId() !== $company->getId()) {
throw new \DomainException(
'DDI already exists in another company'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</field>
<many-to-one field="company" target-entity="Ivoz\Provider\Domain\Model\Company\CompanyInterface" inversed-by="ddis" fetch="LAZY">
<join-columns>
<join-column name="companyId" referenced-column-name="id" on-delete="CASCADE" nullable=""/>
<join-column name="companyId" referenced-column-name="id" on-delete="CASCADE" nullable="true"/>
</join-columns>
</many-to-one>
<many-to-one field="brand" target-entity="Ivoz\Provider\Domain\Model\Brand\BrandInterface" fetch="LAZY">
Expand Down
4 changes: 2 additions & 2 deletions library/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,8 @@
<MixedArgument occurrences="30">
<code>$fkTransformer-&gt;transform($brand)</code>
<code>$fkTransformer-&gt;transform($brand)</code>
<code>$fkTransformer-&gt;transform($company)</code>
<code>$fkTransformer-&gt;transform($company)</code>
<code>$fkTransformer-&gt;transform($dto-&gt;getCompany())</code>
<code>$fkTransformer-&gt;transform($dto-&gt;getCompany())</code>
<code>$fkTransformer-&gt;transform($dto-&gt;getConditionalRoute())</code>
<code>$fkTransformer-&gt;transform($dto-&gt;getConditionalRoute())</code>
<code>$fkTransformer-&gt;transform($dto-&gt;getConferenceRoom())</code>
Expand Down
32 changes: 32 additions & 0 deletions schema/DoctrineMigrations/Version20240319221538.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Ivoz\Core\Infrastructure\Persistence\Doctrine\LoggableMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240319221538 extends LoggableMigration
{
public function getDescription(): string
{
return 'Allow NULL in DDIs companyId';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE DDIs CHANGE companyId companyId INT UNSIGNED DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE DDIs CHANGE companyId companyId INT UNSIGNED NOT NULL');
}
}
Loading

0 comments on commit 745032e

Please sign in to comment.