Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release-v5
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Sep 30, 2019
2 parents 9ec65d1 + 57e74cb commit 6fd8f5f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 27 deletions.
23 changes: 4 additions & 19 deletions app/Http/Controllers/Interfaces/CoreBundleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,12 @@ public function deleteCoreBundle( int $id ): JsonResponse {
abort('404', 'Unknown Core bundle');
}

foreach( $cb->getCoreLinks() as $cl ){
/** @var CoreLinkEntity $cl */
foreach( $cl->getCoreInterfaces() as $ci ){
/** @var CoreInterfaceEntity $ci */
$pi = $ci->getPhysicalInterface();

$vi = $pi->getVirtualInterface();

D2EM::remove( $ci );
D2EM::remove( $pi );
D2EM::remove( $vi );
}
D2EM::remove( $cl );
if( D2EM::getRepository( CoreBundleEntity::class )->delete( $cb ) ) {
AlertContainer::push( "Core bundle deleted successfully.", Alert::SUCCESS );
} else {
AlertContainer::push( "Error: core bundle could not be deleted. Please open a GitHub bug report.", Alert::DANGER );
}

D2EM::remove( $cb );

D2EM::flush();

AlertContainer::push( 'Core bundle deleted successfully.', Alert::SUCCESS );

return response()->json( [ 'success' => true ] );

}
Expand Down
68 changes: 66 additions & 2 deletions database/Repositories/CoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@

use Doctrine\ORM\EntityRepository;

use Entities\CoreBundle as CoreBundleEntity;
use Entities\Switcher as SwitchEntity;
use Entities\{
CoreBundle as CoreBundleEntity,
CoreLink as CoreLinkEntity,
CoreInterface as CoreInterfaceEntity,
Customer as CustomerEntity,
};

use Exception;

/**
* CoreBundle
Expand All @@ -37,8 +42,67 @@
*/
class CoreBundle extends EntityRepository
{
/**
* Return all the core bundles for a customer
*
* @param CustomerEntity $c
*
* @return array
*/
public function getAllForCustomer( CustomerEntity $c ) {
return $this->getEntityManager()->createQuery(
"SELECT cb
FROM Entities\\CoreBundle cb
LEFT JOIN cb.coreLinks cl
LEFT JOIN cl.coreInterfaceSideA ci
LEFT JOIN ci.physicalInterface pi
LEFT JOIN pi.VirtualInterface vi
LEFT JOIN vi.Customer c
WHERE c.id = ?1" )
->setParameter( 1, $c->getId() )
->getResult();
}


/**
* Delete the Core Bundle ans everything related.
*
* @param CoreBundleEntity $cb The Core Bundle Object
*
* @return bool
*
* @throws
*/
public function delete( CoreBundleEntity $cb): bool {

try {
$this->getEntityManager()->getConnection()->beginTransaction();

foreach( $cb->getCoreLinks() as $cl ){
/** @var CoreLinkEntity $cl */
foreach( $cl->getCoreInterfaces() as $ci ){
/** @var CoreInterfaceEntity $ci */
$pi = $ci->getPhysicalInterface();
$vi = $pi->getVirtualInterface();

$this->getEntityManager()->remove( $ci );
$this->getEntityManager()->remove( $pi );
$this->getEntityManager()->remove( $vi );
}
$this->getEntityManager()->remove( $cl );
}

$this->getEntityManager()->remove( $cb );

$this->getEntityManager()->flush();
$this->getEntityManager()->getConnection()->commit();


} catch( Exception $e ) {
$this->getEntityManager()->getConnection()->rollBack();
throw $e;
}

return true;
}
}
9 changes: 7 additions & 2 deletions database/Repositories/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
use Entities\{
BGPSessionData as BGPSessionDataEntity,
Customer as CustomerEntity,
CustomerToUser as CustomerToUserEntity
CustomerToUser as CustomerToUserEntity,
CoreBundle as CoreBundleEntity,
};


Expand Down Expand Up @@ -795,7 +796,6 @@ public function getAllForFeList( $showCurrentOnly = false, $state = null, $type
return $this->getEntityManager()->createQuery( $q )->getResult();
}


/**
* Delete the customer.
*
Expand Down Expand Up @@ -864,6 +864,11 @@ public function delete( CustomerEntity $c ): bool {
}
}

// Delete the Core Bundle
foreach ( D2EM::getRepository( CoreBundleEntity::class)->getAllForCustomer( $c ) as $cb ) {
D2EM::getRepository( CoreBundleEntity::class)->delete( $cb );
}

$this->getEntityManager()->remove( $c );
$this->getEntityManager()->remove( $cbd );
$this->getEntityManager()->remove( $crd );
Expand Down
11 changes: 9 additions & 2 deletions resources/views/customer/overview.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,17 @@
</h3>

<p class="tw-mt-2">
<a href="<?= $t->c->getCorpwww() ?>" target="_blank"><?= $t->nakedUrl( $t->c->getCorpwww() ?? '' ) ?></a>
<?php if( $t->c->getCorpwww() ): ?>
<a href="<?= $t->c->getCorpwww() ?>" target="_blank">
<?= $t->nakedUrl( $t->c->getCorpwww() ) ?>
</a>
<span class="tw-text-gray-600">
-
</span>
<?php endif; ?>

<span class="tw-text-gray-600">
- joined <?= $c->getDatejoin()->format('Y') ?>
joined <?= $c->getDatejoin()->format('Y') ?>

<?php if( $c->isResoldCustomer() ): ?>
- resold via <?= $c->getReseller()->getName() ?>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/patch-panel-port/action-dd.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<?php endif; ?>

<?php if( $t->tpl == "index"):?>
<?php if( $t->ppp->isAllocated() ): ?>
<?php if( $t->ppp->isAllocated() && $t->ppp->getCustomer() ): ?>

<a class="dropdown-item" href="<?= route( 'patch-panel-port@download-loa' , [ 'id' => $t->ppp->getId() ] ) ?>">
Download LoA
Expand Down
2 changes: 1 addition & 1 deletion resources/views/patch-panel-port/view.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
</tr>
<?php endif; ?>

<?php if( $current && ( Auth::user()->isSuperUser() || $p->isStateAwaitingXConnect() ) ): ?>
<?php if( $current && ( Auth::user()->isSuperUser() || $p->isStateAwaitingXConnect() ) && $t->ppp->getCustomer() ): ?>
<tr>
<td>
<b>
Expand Down

0 comments on commit 6fd8f5f

Please sign in to comment.