Browse Source

Merge branch 'master' of ssh://gitlab.com/interlink-sa/flowdat3/modules/ftth into 11

gabriel 6 years ago
parent
commit
897b882488

+ 27 - 0
app/DoctrineMigrations/Version20190328134353.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Update workflow_id in onu table
+ */
+class Version20190328134353 extends AbstractMigration
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql('SET FOREIGN_KEY_CHECKS=0; UPDATE workflow SET id = 2 WHERE name = "onu_workflow"; UPDATE onu SET workflow_id = 2; SET FOREIGN_KEY_CHECKS=1;');
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+    }
+}

File diff suppressed because it is too large
+ 102 - 108
app/DoctrineMigrations/src/action.yml


+ 4 - 17
app/DoctrineMigrations/src/workflow.yml

@@ -21,25 +21,12 @@ insertorupdate:
           type: "state_machine"
           marking_type: "single_state"
           marking_name: "currentState"
-          description: "onu workflow"
-          template: "initial_place: active\r\nplaces:\r\n  - active\r\n  - disable\r\ntransitions:\r\n  add_config:\r\n    from: active\r\n    to: active\r\n  disable:\r\n    from: active\r\n    to: disable\r\n  active:\r\n    from: disable\r\n    to: active"
-          created: "2017-04-27 11:35:07"
-          updated: "2017-04-27 20:01:43"
-          tenancy_id: 1
-          enable: 1
-          support: "a:1:{i:0;s:21:\"FTTHBundle\\Entity\\ONU\";}"
-          owner: 1
-        -
-          id: 3
-          name: "onu_workflow_2"
-          type: "state_machine"
-          marking_type: "single_state"
-          marking_name: "currentState"
-          description: "ONU Workflow v2"
-          template: "initial_place: active\r\nplaces:\r\n  - active\r\n  - disable\r\n  - deleted\r\ntransitions:\r\n  active:\r\n    from: disable\r\n    to: active\r\n  disable_deleted:\r\n    from: disable\r\n    to: deleted\r\n  add_config:\r\n    from: active\r\n    to: active\r\n  disable:\r\n    from: active\r\n    to: disable\r\n  active_deleted:\r\n    from: active\r\n    to: deleted\r\n  deleted_active:\r\n    from: deleted\r\n    to: active"
+          description: "ONU Workflow"
+          template: "initial_place: active\r\nplaces:\r\n  - active\r\n  - disable\r\n  - deleted\r\ntransitions:\r\n  disable_active:\r\n    from: disable\r\n    to: active\r\n  disable_deleted:\r\n    from: disable\r\n    to: deleted\r\n  config:\r\n    from: active\r\n    to: active\r\n  active_disable:\r\n    from: active\r\n    to: disable\r\n  active_deleted:\r\n    from: active\r\n    to: deleted\r\n  deleted_active:\r\n    from: deleted\r\n    to: active"
           created: "2018-08-06 17:13:54"
-          updated: "2018-08-07 14:58:10"
+          updated: "2019-03-28 13:34:30"
           tenancy_id: 1
           enable: 1
           support: "a:1:{i:0;s:21:\"FTTHBundle\\Entity\\ONU\";}"
           owner: 1
+          used_by_default: 1

+ 7 - 26
app/Resources/workflows/workflow_list.yml.dist

@@ -20,28 +20,6 @@ framework:
           from: disabled
           to: enabled
     onu_workflow:
-      type: state_machine
-      marking_store:
-        type: single_state
-        arguments:
-          - currentState
-      supports:
-        - FTTHBundle\Entity\ONU
-      initial_place: active
-      places:
-        - active
-        - disable
-      transitions:
-        add_config:
-          from: active
-          to: active
-        disable:
-          from: active
-          to: disable
-        active:
-          from: disable
-          to: active
-    onu_workflow_2:
       type: state_machine
       marking_store:
         type: single_state
@@ -55,18 +33,21 @@ framework:
         - disable
         - deleted
       transitions:
-        active:
+        disable_active:
           from: disable
           to: active
         disable_deleted:
           from: disable
           to: deleted
-        add_config:
+        config:
           from: active
           to: active
-        disable:
+        active_disable:
           from: active
           to: disable
         active_deleted:
           from: active
-          to: deleted
+          to: deleted
+        deleted_active:
+          from: deleted
+          to: active

+ 5 - 5
composer.lock

@@ -1,7 +1,7 @@
 {
     "_readme": [
         "This file locks the dependencies of your project to a known state",
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
     "content-hash": "2936d77bbfff21651cf2c40704457bde",
@@ -1947,7 +1947,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "a3268eb5d3806d8d811e8df78c148544dfc46f4d"
+                "reference": "0e77ef117751fc9360086347cb8554a507d84ce6"
             },
             "type": "library",
             "autoload": {
@@ -1962,7 +1962,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2019-03-15T17:10:29+00:00"
+            "time": "2019-03-28T11:53:21+00:00"
         },
         {
             "name": "ik/check-sintax-bundle",
@@ -2223,7 +2223,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/WorkflowBundle.git",
-                "reference": "5b0608cc9e4288c05fe6520c0621b6fd8b2eda5d"
+                "reference": "c22a633e32053400986316c2905d6ec95c29a593"
             },
             "require": {
                 "php-amqplib/rabbitmq-bundle": "^1.12"
@@ -2253,7 +2253,7 @@
                 "bundle",
                 "workflow"
             ],
-            "time": "2019-03-15T17:07:28+00:00"
+            "time": "2019-03-28T15:09:41+00:00"
         },
         {
             "name": "incenteev/composer-parameter-handler",

+ 122 - 0
src/FTTHBundle/Command/MigrateSerialToPonCommand.php

@@ -0,0 +1,122 @@
+<?php
+
+namespace FTTHBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use StatsBundle\Services\DeviceManager;
+
+class MigrateSerialToPonCommand extends ContainerAwareCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('migrate:serial:pon')
+            ->setDescription('Convert in Pon Serial Number the value in pon_serial_number_aux field in DB onu when value is a serial_number')
+            ->setHelp('Convert in Pon Serial Number the value in pon_serial_number_aux field in DB onu when value is a serial_number')
+            ->setDefinition(array())
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+
+        
+        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+        
+        $onus = $doctrine->getRepository('\FTTHBundle\Entity\ONU')->findAll();
+        $updates = array();
+
+        foreach($onus as $i => $onu) {
+            $value = $onu->getPonSerialNumberAux(); 
+            
+            if(strlen($value) == 16) {
+                $newValue = $this->psnCalulate($value);
+                $updates[$onu->getId()] = $newValue;
+            }
+            
+        }
+
+        $sql = null;
+        foreach($updates as $id => $value) {
+            if($id) {
+                $sql .= "UPDATE `onu` SET `pon_serial_number_aux` = '{$value}' WHERE `onu`.`id` = {$id};".PHP_EOL;
+            }
+        }
+
+        if($sql) {
+            $conn = $doctrine->getConnection();
+            $conn->query($sql);
+            $conn->close();
+        }
+    }
+
+    private function hex2str($hex) {
+        $hex = strtoupper($hex);
+        $str = "";
+        for($i=0;$i<strlen($hex);$i+=2)
+            $str .= chr(hexdec(substr($hex,$i,2)));
+
+        return $str;
+    }
+
+    private function str2hex($string){
+        $string = strtoupper($string);
+        $hex = "";
+        for ($i=0; $i < strlen($string); $i++)
+            $hex .= dechex(ord($string[$i]));
+
+        return $hex;
+    }
+
+    //HWTC22BDED0C > 4857544322BDED0C
+    private function snCalulate($value) {
+        $value = str_replace(" ","",$value);
+        
+        if(strlen($value) == 16)
+            return strtolower($value);
+        
+        if(strlen($value) == 12) {
+            $vendoId = $this->str2hex(substr($value,0,4));
+            $rest = substr($value,4);
+            return strtolower($vendoId.$rest);
+        }
+
+        return strtolower($value);
+    }
+
+    //4857544322BDED0C > HWTC22BDED0C
+    private function psnCalulate($value) {
+        $value = str_replace(" ","",$value);
+        
+        if(strlen($value) == 12)
+            return strtolower($value);
+        
+        if(strlen($value) == 16) {
+            $vendorId = substr($value,0,8);
+            $hex = strtoupper($vendorId);
+            $isNumeric = true;
+            for($i=0;$i<strlen($hex);$i+=2) {
+                if(!is_numeric(substr($hex,$i,2))) {
+                    $isNumeric = false;
+                    break;
+                }
+            }
+            
+            if($isNumeric) {
+                $vendoId = $this->hex2str($hex);
+                $rest = substr($value,8);
+                return strtolower($vendoId.$rest);
+            }
+        }
+
+        return strtolower($value);
+    }
+}