Added script to create QGIS data table
This commit is contained in:
173
scripts/update_workflow_gis_table.php
Normal file
173
scripts/update_workflow_gis_table.php
Normal file
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
//require 'vendor/autoload.php';
|
||||
require("../config/config.php");
|
||||
|
||||
define('FRONKDB_SQLDEBUG',false);
|
||||
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||
|
||||
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||
|
||||
$me = new User(1);
|
||||
|
||||
|
||||
$table = "TerminationWorkflow";
|
||||
/*
|
||||
$create_sql = "CREATE TABLE `{$table}_tmp` ENGINE = MEMORY AS SELECT * FROM `$view`";
|
||||
$rename_sql = "RENAME TABLE `$table` TO `{$table}_old`, {$table}_tmp TO `$table`";
|
||||
$drop_sql = "DROP {$table}_old";
|
||||
echo "$create_sql\n";
|
||||
echo "$rename_sql\n";
|
||||
echo "$drop_sql\n";
|
||||
*/
|
||||
|
||||
|
||||
$sql = "SELECT
|
||||
`Building`.`id` AS `building_id`,
|
||||
`Building`.`code` AS `building_code`,
|
||||
`Network`.`id` AS `network_id`,
|
||||
`Network`.`name` AS `network_name`,
|
||||
`Networksection`.`name` AS `networksection_name`,
|
||||
`Building`.`type_id` AS `buildingtype_id`,
|
||||
`Buildingtype`.`name` AS `buildingtype_name`,
|
||||
`Building`.`units` AS `units`,
|
||||
`Building`.`street` AS `street`,
|
||||
`Building`.`zip` AS `zip`,
|
||||
`Building`.`city` AS `city`,
|
||||
`Pop`.`name` AS `pop_name`,
|
||||
`Pop`.`gps_lat` AS `pop_gps_lat`,
|
||||
`Pop`.`gps_long` AS `pop_gps_long`,
|
||||
`Building`.`gps_lat` AS `building_gps_lat`,
|
||||
`Building`.`gps_long` AS `building_gps_long`,
|
||||
`Building`.`laea` AS `laea`,
|
||||
`Buildingstatus`.`code` AS `buildingstatus_code`,
|
||||
`Buildingstatus`.`name` AS `buildingstatus_name`,
|
||||
`Termination`.`id` AS `termination_id`,
|
||||
`Termination`.`code` AS `termination_code`
|
||||
FROM `Termination`
|
||||
LEFT JOIN `Building` on(`Termination`.`building_id` = `Building`.`id`)
|
||||
LEFT JOIN `Network` on(`Building`.`network_id` = `Network`.`id`)
|
||||
LEFT JOIN `Networksection` on(`Networksection`.`id` = `Building`.`networksection_id`)
|
||||
LEFT JOIN `Buildingtype` on(`Building`.`type_id` = `Buildingtype`.`id`)
|
||||
LEFT JOIN `Pop` on(`Building`.`pop_id` = `Pop`.`id`)
|
||||
LEFT JOIN `Buildingstatus` on(`Building`.`status_id` = `Buildingstatus`.`id`)
|
||||
";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->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");
|
||||
Reference in New Issue
Block a user