Commit 5ac64a07 authored by Thomas Citharel's avatar Thomas Citharel 🏃🏻
Browse files

Add a command to detach domains manually if it fails through webview


Signed-off-by: Thomas Citharel's avatarThomas Citharel <tcit@tcit.fr>
parent 73728367
Pipeline #44581 passed with stage
in 5 minutes and 28 seconds
<?php
namespace AppBundle\Command;
use AppBundle\Exception\APIException\Release\ReleaseContactException;
use AppBundle\Exception\APIException\Release\ReleaseDomainException;
use AppBundle\Exception\SiteException\UnknownSiteType;
use AppBundle\Service\Domain\DetachDomainService;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class DetachDomain extends ContainerAwareCommand
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var DetachDomainService
*/
private $detachDomainService;
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(LoggerInterface $logger,
EntityManagerInterface $entityManager,
DetachDomainService $detachDomainService
) {
$this->logger = $logger;
$this->entityManager = $entityManager;
$this->detachDomainService = $detachDomainService;
parent::__construct();
}
protected function configure()
{
$this
->setName('framasites:site:detach-domain')
->setDescription("Detach a domain from it's website")
->setDefinition(
[
new InputArgument(
'domainName', InputArgument::REQUIRED, 'The domain name which should be detached'
),
]
)
->setHelp("The domain will be removed from our database. If it was registered with Gandi through Framasoft, it will be send to the user informations to get the domain back.")
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$domainName = $input->getArgument('domainName');
$this->logger->info("Wanting to detach " . $domainName . ' from console command');
$domain = $this->entityManager->getRepository('AppBundle:Domain')->findOneBy(['domainName' => $domainName]);
if (!$domain) {
$io->error("No such domain has been found inside Framasites");
return;
}
try {
$this->detachDomainService->detachDomain($domain, $domain->getUser());
$io->success('Domain ' . $domainName . ' has been successfully detached');
} catch (ReleaseDomainException $e) {
$io->error('When releasing domain ' . $domain->getDomainName() . ' from console command, an error occurred : ' . $e->getMessage());
} catch (ReleaseContactException $e) {
$io->error('When releasing contact ' . $e->getGandiId() . ' from console command, an error occurred : ' . $e->getMessage());
} catch (UnknownSiteType $e) {
$io->error($e->getMessage());
$io->error("Unknown Site type : very odd !");
}
}
}
......@@ -9,6 +9,7 @@ use AppBundle\Entity\User;
use AppBundle\Entity\Wiki\Wiki;
use AppBundle\Exception\APIException;
use AppBundle\Exception\APIException\Release\ReleaseContactException;
use AppBundle\Exception\SiteException\UnknownSiteType;
use AppBundle\Helper\CertTaskFactory;
use AppBundle\Helper\DomainFactory;
use AppBundle\Service\BaseService;
......@@ -54,6 +55,13 @@ class DetachDomainService extends BaseService
$this->accountDoku = $accountDoku;
}
/**
* @param Domain $domain
* @param User $user
* @throws APIException\Release\ReleaseDomainException
* @throws ReleaseContactException
* @throws UnknownSiteType
*/
public function detachDomain(Domain $domain, User $user)
{
if ($domain->isRegisteredByFrama()) {
......@@ -74,7 +82,7 @@ class DetachDomainService extends BaseService
*
* TODO: Find out what happens if the user added it's own BuyDomains Account
*/
$user = $gandiId = $domain->getUser();
$user = $domain->getUser();
if ($gandiId = $user->getGandiId()) {
try {
$this->logger->info("We registered the contact, so now we release it");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment