|
@@ -0,0 +1,61 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace FTTHBundle\Command;
|
|
|
+
|
|
|
+use FTTHBundle\Entity\ONU;
|
|
|
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Class ONUServicePortsDeleteCommand
|
|
|
+ * Delete all the service ports associated to the onu
|
|
|
+ * @package FTTHBundle\Command
|
|
|
+ */
|
|
|
+class ONUServicePortsDeleteCommand extends ContainerAwareCommand
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('onu:sp:delete')
|
|
|
+ ->setDescription('Delete all the service ports associated to the onu')
|
|
|
+ ->setHelp('Delete all the service ports associated to the onu')
|
|
|
+ ->addArgument('id', InputArgument::REQUIRED, 'ONU id')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $em = $this->getContainer()->get('doctrine')->getManager();
|
|
|
+
|
|
|
+ $filters = $em->getFilters();
|
|
|
+ $enableFilters = [];
|
|
|
+ $disableFilter = 'soft_deleteable';
|
|
|
+ if ($filters->isEnabled($disableFilter)) {
|
|
|
+ $filters->disable($disableFilter);
|
|
|
+ $enableFilters[] = $disableFilter;
|
|
|
+ }
|
|
|
+
|
|
|
+ $onu = $em->getRepository(ONU::class)->find($input->getArgument('id'));
|
|
|
+ if ($onu && $onu->isDeleted()) {
|
|
|
+ foreach ($onu->getServicePorts() as $sp) {
|
|
|
+ $onu->removeServicePort($sp);
|
|
|
+ $output->writeln("Service Port Number: {$sp} <error>Deleted</error>");
|
|
|
+ }
|
|
|
+ $em->flush();
|
|
|
+ } else {
|
|
|
+ $output->writeln("<error>ONU not found or not deleted</error>");
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($enableFilters as $enableFilter) {
|
|
|
+ $filters->enable($enableFilter);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ echo("\nERROR CODE: " . $e->getCode() . "\nERROR MESSAGE: " . $e->getMessage() . "\n");
|
|
|
+ echo("\nTRACE: \n" . $e->getTraceAsString() . "\n\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|