Bladeren bron

Adding check if url exists and module is installed

gabriel 6 jaren geleden
bovenliggende
commit
5e84a47b13
3 gewijzigde bestanden met toevoegingen van 66 en 57 verwijderingen
  1. 28 28
      composer.lock
  2. 17 15
      src/CablemodemBundle/Command/DHCPHostCRUDCommand.php
  3. 21 14
      src/CablemodemBundle/Services/HostService.php

+ 28 - 28
composer.lock

@@ -1411,7 +1411,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/AuditBundle.git",
-                "reference": "34dece40daad7031e332f02314b681bb9ee1cd14"
+                "reference": "fdb6ffb9d88fb20bcdb7f46ae6098915112e5e55"
             },
             "require": {
                 "simplethings/entity-audit-bundle": "^1.0"
@@ -1427,7 +1427,7 @@
                 "audit",
                 "bundle"
             ],
-            "time": "2019-01-31T13:32:40+00:00"
+            "time": "2019-03-01T17:42:21+00:00"
         },
         {
             "name": "ik/auth-bundle",
@@ -1435,7 +1435,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/AuthBundle.git",
-                "reference": "c8e77dce32b92c08d75e12c537ead77bf976cd84"
+                "reference": "11b7d49dc85ac20e7b16d8cec296d140b1650641"
             },
             "type": "library",
             "autoload": {
@@ -1450,7 +1450,7 @@
                 "auth",
                 "bundle"
             ],
-            "time": "2019-01-31T13:33:33+00:00"
+            "time": "2019-03-01T17:42:56+00:00"
         },
         {
             "name": "ik/base-admin-bundle",
@@ -1458,7 +1458,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "a2b2110a69a21e2691266d66e421d2e56dff1c8a"
+                "reference": "5e124f6f6dd407ba4cfa6cb34db67f8c9c2a4a1f"
             },
             "type": "library",
             "autoload": {
@@ -1473,7 +1473,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2019-02-11T17:28:26+00:00"
+            "time": "2019-04-16T15:54:39+00:00"
         },
         {
             "name": "ik/check-sintax-bundle",
@@ -1481,7 +1481,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/CheckSintaxBundle.git",
-                "reference": "df53b6339c7ae09fbdc350540f15e334be42b000"
+                "reference": "2d285a2d52ff4eaaddf6e98b92cbe91842c1f1e8"
             },
             "type": "library",
             "autoload": {
@@ -1496,7 +1496,7 @@
                 "bundle",
                 "validators"
             ],
-            "time": "2019-01-31T13:23:39+00:00"
+            "time": "2019-03-01T17:38:39+00:00"
         },
         {
             "name": "ik/device-bundle",
@@ -1504,7 +1504,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/DeviceBundle.git",
-                "reference": "5a72c912f13ba8728fda6792d867e61a889e6c06"
+                "reference": "5af05cc3812b1f8f0e30042f94f8240f553b8d4e"
             },
             "type": "library",
             "autoload": {
@@ -1519,7 +1519,7 @@
                 "bundle",
                 "validators"
             ],
-            "time": "2019-01-31T13:35:09+00:00"
+            "time": "2019-03-01T17:44:12+00:00"
         },
         {
             "name": "ik/extra-data-bundle",
@@ -1527,7 +1527,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/ExtraDataBundle.git",
-                "reference": "77c2c8228bb9dfd13add559909fd809508b61388"
+                "reference": "0af5c1039f8c47394b7cf2f5b1925dcda942d48b"
             },
             "type": "library",
             "autoload": {
@@ -1542,7 +1542,7 @@
                 "bundle",
                 "extra-data"
             ],
-            "time": "2019-01-31T13:44:14+00:00"
+            "time": "2019-03-01T17:35:13+00:00"
         },
         {
             "name": "ik/leaflet-bundle",
@@ -1550,7 +1550,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/LeafletBundle.git",
-                "reference": "bcf009e03ace356adfd92a7a89f814aa2e96fb6c"
+                "reference": "7ce5a56ec0d134be131b28fc84535fc4613ecad4"
             },
             "require": {
                 "ext-curl": "*",
@@ -1563,7 +1563,7 @@
                 }
             },
             "description": "The Flowdat3 Leaflet Resource",
-            "time": "2019-01-31T13:34:17+00:00"
+            "time": "2019-03-01T17:43:35+00:00"
         },
         {
             "name": "ik/map-bundle",
@@ -1571,7 +1571,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/MapBundle.git",
-                "reference": "94454d6f6943fb07040dadae8edddd3d13510b5f"
+                "reference": "006c6db55ae17b6153f4d110d8a939aae2c660da"
             },
             "type": "library",
             "autoload": {
@@ -1586,7 +1586,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2019-01-31T13:29:47+00:00"
+            "time": "2019-03-01T17:40:17+00:00"
         },
         {
             "name": "ik/migrations-bundle",
@@ -1594,7 +1594,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/migrations.git",
-                "reference": "f786c642a32803b11cda2514940d69bce81116ac"
+                "reference": "02ca1ac6fd2ac6954bd632d98d5ce1e0de6fc674"
             },
             "type": "library",
             "autoload": {
@@ -1609,7 +1609,7 @@
                 "bundle",
                 "migrations"
             ],
-            "time": "2019-01-31T11:55:56+00:00"
+            "time": "2019-03-01T17:36:43+00:00"
         },
         {
             "name": "ik/oauthclient-bundle",
@@ -1617,7 +1617,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/BaseOAuthClientBundle.git",
-                "reference": "a057890183bddcb6f4c431c3b7c9afe6839d8d78"
+                "reference": "ddcdd35701577440b564b42a65ea55e0f675cd96"
             },
             "require": {
                 "ext-curl": "*",
@@ -1636,7 +1636,7 @@
                 "bundle",
                 "oauth"
             ],
-            "time": "2019-01-31T13:37:25+00:00"
+            "time": "2019-04-05T15:00:43+00:00"
         },
         {
             "name": "ik/owner-voter-bundle",
@@ -1644,7 +1644,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/OwnerVoter.git",
-                "reference": "ece1ca1df9ca18789ccdcae19a381ee5d9142f6c"
+                "reference": "f99aeb3a95996b481a163dd7963e84bd35d00f6e"
             },
             "type": "library",
             "autoload": {
@@ -1659,7 +1659,7 @@
                 "bundle",
                 "owner-voter"
             ],
-            "time": "2019-01-31T13:18:32+00:00"
+            "time": "2019-03-01T17:37:38+00:00"
         },
         {
             "name": "ik/template-bundle",
@@ -1667,7 +1667,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/TemplateBundle.git",
-                "reference": "2c02107d2ec87aad3fca45adc94f6e69f3aa0119"
+                "reference": "814f06b1cac5d6d67670a1cec1c87e288526bb59"
             },
             "require": {
                 "ik/base-admin-bundle": "*"
@@ -1685,7 +1685,7 @@
                 "bundle",
                 "template"
             ],
-            "time": "2019-01-31T13:32:01+00:00"
+            "time": "2019-03-01T17:41:42+00:00"
         },
         {
             "name": "ik/webservice-bundle",
@@ -1693,7 +1693,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/Webservice.git",
-                "reference": "68f356b67da08b94cdb7613ad58c5525c88ff950"
+                "reference": "8767981f13e591b805cde0ee8319fb8f15a4b364"
             },
             "require": {
                 "ext-curl": "*",
@@ -1706,7 +1706,7 @@
                 }
             },
             "description": "The Flowdat3 Webservice Rest",
-            "time": "2019-01-31T13:36:09+00:00"
+            "time": "2019-04-05T14:57:21+00:00"
         },
         {
             "name": "ik/workflow-bundle",
@@ -1714,7 +1714,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/WorkflowBundle.git",
-                "reference": "8bd50352aca1344d96bdd300a3bfb74d9041e431"
+                "reference": "c22a633e32053400986316c2905d6ec95c29a593"
             },
             "require": {
                 "php-amqplib/rabbitmq-bundle": "^1.12"
@@ -1744,7 +1744,7 @@
                 "bundle",
                 "workflow"
             ],
-            "time": "2019-02-21T13:09:25+00:00"
+            "time": "2019-03-28T15:09:41+00:00"
         },
         {
             "name": "incenteev/composer-parameter-handler",

+ 17 - 15
src/CablemodemBundle/Command/DHCPHostCRUDCommand.php

@@ -2,6 +2,7 @@
 
 namespace CablemodemBundle\Command;
 
+use Base\AdminBundle\Checks\CheckParametersAsURL;
 use Buzz\Message\RequestInterface as HttpRequestInterface;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputArgument;
@@ -42,7 +43,7 @@ class DHCPHostCRUDCommand extends ContainerAwareCommand
             ->setHelp(<<<EOT
 The <info>dhcp:host:crud</info> command create or delete a DHCP Host from Cablemodem HostType and mac parameter
 EOT
-        );
+            );
     }
 
     /**
@@ -194,7 +195,7 @@ EOT
     }
 
     /**
-     * @param string $type  HostType name Cablemodem | MTA | CPE
+     * @param string $type HostType name Cablemodem | MTA | CPE
      *
      * @return string
      */
@@ -285,21 +286,22 @@ EOT
         $hostType = null;
         $container = $this->getContainer();
         $parameter = 'dhcp_host_type_get_url';
-        $url = $container->hasParameter($parameter) ?
-            $container->getParameter($parameter) :
-            $this->input->getOption('url-get-hosttype');
-
-        $url = $this->webservice->buildUrl($url, [
-            'shortname' => $name,
-        ]);
-        $hostTypeJSON = $this->webservice->makeGetRequest($url);
-        if ($hostTypeJSON != '' && !is_null($hostTypeJSON)) {
-            $hostDecode = json_decode($hostTypeJSON, true);
-            if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
-                $hostType = current($hostDecode)['id'];
+        $url = CheckParametersAsURL::checkParametersUrl($container, $parameter);
+        if (is_null($url)) {
+            $url = $this->input->getOption('url-get-hosttype');
+        }
+        if (is_null($url) || strlen($url) < 7) {
+            $url = $this->webservice->buildUrl($url, [
+                'shortname' => $name,
+            ]);
+            $hostTypeJSON = $this->webservice->makeGetRequest($url);
+            if ($hostTypeJSON != '' && !is_null($hostTypeJSON)) {
+                $hostDecode = json_decode($hostTypeJSON, true);
+                if (json_last_error() == JSON_ERROR_NONE && is_array($hostDecode)) {
+                    $hostType = current($hostDecode)['id'];
+                }
             }
         }
-
         return $hostType;
     }
 

+ 21 - 14
src/CablemodemBundle/Services/HostService.php

@@ -2,33 +2,34 @@
 
 namespace CablemodemBundle\Services;
 
+use Base\AdminBundle\Checks\CheckParametersAsURL;
 use Buzz\Message\RequestInterface as HttpRequestInterface;
 use WebserviceBundle\Services\Webservice;
 
 class HostService
 {
-    
+
     /**
      * @var Webservice
      */
     private $webservice;
-    
+
     /**
      * @var string
      */
     private $dhcpHostTypeGetUrl;
-    
-    
+
+
     /**
      * @param string $dhcpHostTypeGetUrl
      * @param Webservice $webservice
      */
     public function __construct($dhcpHostTypeGetUrl, Webservice $webservice)
     {
-        $this->dhcpHostTypeGetUrl = $dhcpHostTypeGetUrl;
+        $this->dhcpHostTypeGetUrl = CheckParametersAsURL::checkUrl($dhcpHostTypeGetUrl);
         $this->webservice = $webservice;
     }
-    
+
     /**
      * @param string $shortname HostType name Cablemodem | MTA | CPE
      * @param string $url url API DHCP a consultar
@@ -37,16 +38,22 @@ class HostService
      */
     public function getIdHostType($shortname = 'cablemodem', $url = null)
     {
-        $url = $this->webservice->buildUrl($url ?: $this->dhcpHostTypeGetUrl, [
-            'shortname' => $shortname,
-        ]);
-        
         $hostType = null;
-        if ($hostTypeJSON = $this->webservice->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [])) {
-            $hostType = current(json_decode($hostTypeJSON, true))['id'];
+        if (is_null($url)) {
+            $url = $this->dhcpHostTypeGetUrl;
         }
-        
+        if (!is_null($url)) {
+            $url = $this->webservice->buildUrl($url ?: $this->dhcpHostTypeGetUrl, [
+                'shortname' => $shortname,
+            ]);
+
+
+            if ($hostTypeJSON = $this->webservice->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [])) {
+                $hostType = current(json_decode($hostTypeJSON, true))['id'];
+            }
+        }
+
         return $hostType;
     }
-    
+
 }