From 882896dc5de2dad511c2050dccb019ebaae1d528 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 9 Aug 2022 17:10:50 +0200 Subject: [PATCH] Added script to create QGIS data table --- application/Building/Building.php | 2 +- application/Termination/Termination.php | 2 +- application/User/User.php | 4 + scripts/update_workflow_gis_table.php | 173 ++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 scripts/update_workflow_gis_table.php diff --git a/application/Building/Building.php b/application/Building/Building.php index b2b8bf53a..5eac00956 100644 --- a/application/Building/Building.php +++ b/application/Building/Building.php @@ -137,7 +137,7 @@ class Building extends mfBaseModel { $item = mfValuecache::singleton()->get("wfBuilding-name-".$itemname); if(!$item) { $item = WorkflowitemModel::getFirst(['name' => $itemname]); - if(!$item->id) { + if(!$item || !$item->id) { return null; } mfValuecache::singleton()->set("wfBuilding-name-".$itemname, $item); diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php index bbc26b685..15f742d68 100644 --- a/application/Termination/Termination.php +++ b/application/Termination/Termination.php @@ -78,7 +78,7 @@ class Termination extends mfBaseModel { $item = mfValuecache::singleton()->get("wfTerm-name-".$itemname); if(!$item) { $item = WorkflowitemModel::getFirst(['name' => $itemname]); - if(!$item->id) { + if(!$item || !$item->id) { return null; } mfValuecache::singleton()->set("wfTerm-name-".$itemname, $item); diff --git a/application/User/User.php b/application/User/User.php index 9e7376e02..0f6015f5c 100644 --- a/application/User/User.php +++ b/application/User/User.php @@ -29,6 +29,10 @@ class User extends mfBaseModel { return true; } + if(!isset($_SESSION) || !is_array($_SESSION) || !array_key_exists(MFAPPNAME.'_username', $_SESSION)) { + return false; + } + $username = $_SESSION[MFAPPNAME.'_username']; $res = $this->db->select($this->table,"*","username='$username' LIMIT 1"); if($this->db->num_rows($res)) { diff --git a/scripts/update_workflow_gis_table.php b/scripts/update_workflow_gis_table.php new file mode 100644 index 000000000..088ba121c --- /dev/null +++ b/scripts/update_workflow_gis_table.php @@ -0,0 +1,173 @@ +#!/usr/bin/php +query($sql); +if(!$db->num_rows($res)) { + echo "No termination data\n"; + exit; +} + +$fields = [ + 'building_id','building_code','network_id','network_name','networksection_name', + 'buildingtype_id','buildingtype_name','units','street','zip','city', + 'pop_name','pop_gps_lat','pop_gps_long','building_gps_lat','building_gps_long', + 'laea','buildingstatus_code','buildingstatus_name' +]; + +/*************************** + * create tmp table + */ +$create_sql = "CREATE TABLE `{$table}_tmp` ( + `id` int NOT NULL AUTO_INCREMENT, + `building_id` int DEFAULT NULL, + `building_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, + `network_id` int DEFAULT NULL, + `network_name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `networksection_name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `buildingtype_id` int, + `buildingtype_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `units` int, + `street` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `zip` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `city` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `pop_name` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `pop_gps_lat` decimal(15,10) DEFAULT NULL, + `pop_gps_long` decimal(15,10) DEFAULT NULL, + `building_gps_lat` decimal(15,10) DEFAULT NULL, + `building_gps_long` decimal(15,10) DEFAULT NULL, + `laea` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, + `buildingstatus_code` int, + `buildingstatus_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `schrank` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `rohrverband` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `rohrtype` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `rohrfarbe` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `termination_id` int NOT NULL DEFAULT '0', + `termination_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, + `abschlusstyp` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `bb_kabel` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `bb_kabel_steps` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `bb_fasern` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `kundenkabel_typ` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `kundenkabel_fasern` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci, + `backbone_finished` int DEFAULT NULL, + `inhouse_cabling_supplied` int DEFAULT NULL, + `inhouse_cabling_deployed` int DEFAULT NULL, + `bep_deployed` int DEFAULT NULL, + `customer_cable_injected` int DEFAULT NULL, + `spliced_network` int DEFAULT NULL, + `spliced_customer` int DEFAULT NULL, + `ont_deployed` int DEFAULT NULL, + `ont_sn` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci DEFAULT NULL, + `customer_passive_finished` int DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"; + +if(!$db->query($create_sql)) { + die("Cannot CREATE TABLE {$table}_tmp"); +} + +/***************************** + * loop through terminations + */ +while($row = $db->fetch_object($res)) { + $data = []; + + foreach($fields as $field) { + $data[$field] = $row->$field; + } + + $building = new Building($row->building_id); + $termination = new Termination($row->termination_id); + + $data['schrank'] = ($termination->getWorkflowvalue("ist_schrank")) ? $termination->getWorkflowvalue("ist_schrank") : $termination->getWorkflowvalue("schrank"); + $data['rohrverband'] = ($building->getWorkflowvalue("ist_rohrverband_name")) ? $building->getWorkflowvalue("ist_rohrverband_name") : $building->getWorkflowvalue("rohrverband_name"); + $data['rohrtype'] = ($building->getWorkflowvalue("ist rohrtype")) ? $building->getWorkflowvalue("ist_rohrtype") : $building->getWorkflowvalue("rohrtype"); + $data['rohrfarbe'] = ($building->getWorkflowvalue("ist_rohrfarbe")) ? $building->getWorkflowvalue("ist_rohrfarbe") : $building->getWorkflowvalue("rohrfarbe"); + $data['termination_id'] = $row->termination_id; + $data['termination_code'] = $row->termination_code; + + $items = [ + 'abschlusstyp','bb_kabel','bb_kabel_steps','bb_fasern','kundenkabel_typ','kundenkabel_fasern', + 'backbone_finished','inhouse_cabling_supplied','inhouse_cabling_deployed','bep_deployed','customer_cable_injected', + 'spliced_network','spliced_customer','ont_deployed','ont_sn','customer_passive_finished' + ]; + foreach($items as $item) { + $data[$item] = ($termination->getWorkflowvalue("ist_".$item)) ? $termination->getWorkflowvalue("ist_".$item) : $termination->getWorkflowvalue($item); + } + + //var_dump($data);exit; + + if(!is_array($data) || !count($data)) { + continue; + } + + /********************* + * insert data into tmp table + */ + $db->insert($table."_tmp", $data); + +} + +/***************** + * rename tables and delete old table + */ +$db->query("RENAME TABLE `$table` TO `{$table}_old`, {$table}_tmp TO `$table`"); +$db->query("DROP TABLE {$table}_old");