added rimo_id and unit_count to ADBNetzgebietModel
This commit is contained in:
123
scripts/rimo-import-test.php
Executable file
123
scripts/rimo-import-test.php
Executable file
@@ -0,0 +1,123 @@
|
||||
#!/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);
|
||||
|
||||
define("INTERNAL_USER_ID", $me->id);
|
||||
define("INTERNAL_USER_USERNAME", $me->username);
|
||||
|
||||
$mainlog = mfLoghandler::singleton();
|
||||
$log = new mfLog_File();
|
||||
$log->init(BASEDIR."/var/log/rimo-import.log");
|
||||
|
||||
$apiUrl = RIMO_API_JSON_URL_PROD;
|
||||
$apiToken = RIMO_API_JSON_APIKEY_PROD;
|
||||
|
||||
$epGetClusters = $apiUrl.RIMO_API_JSON_EP_GET_CLUSTERS;
|
||||
$epGetBuildings = $apiUrl.RIMO_API_JSON_EP_GET_BUILDINGS;
|
||||
|
||||
|
||||
if(!defined("RIMO_API_JSON_APIKEY_PROD")) {
|
||||
die("rimo api token not defined!");
|
||||
}
|
||||
|
||||
$import_count = 0;
|
||||
|
||||
$baseParams = ['apiKey' => RIMO_API_JSON_APIKEY_PROD];
|
||||
|
||||
$ctxOptsPost = [
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
$ctxOptsGet = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
/*
|
||||
* Get RIMO Sales Clusters
|
||||
*/
|
||||
|
||||
$params = $baseParams;
|
||||
$qs = http_build_query($params);
|
||||
|
||||
$req_url = $epGetClusters."?".$qs;
|
||||
$req_ctx = stream_context_create($ctxOptsGet);
|
||||
|
||||
echo $req_url."\n";
|
||||
$responseText = file_get_contents($req_url, false, $req_ctx);
|
||||
if($responseText === false) {
|
||||
echo "Error fetching clusters\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$clustersResponse = json_decode($responseText);
|
||||
//var_dump($clustersResponse);
|
||||
if(is_object($clustersResponse) && property_exists($clustersResponse, "item") && is_array($clustersResponse->item) && count($clustersResponse->item)) {
|
||||
|
||||
foreach($clustersResponse->item as $cluster) {
|
||||
$cluster_rimo_id = $cluster->id;
|
||||
$adb_netzgebiet = ADBNetzgebietModel::getFirst(['rimo_id' => $cluster_rimo_id]);
|
||||
if(!$adb_netzgebiet) {
|
||||
echo "Kein Netzgebiet für Salescluster $cluster_rimo_id (".$cluster->name.")\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Buildings per SalesCluster
|
||||
*/
|
||||
$params = $baseParams;
|
||||
$params["clusterId"] = $cluster_rimo_id;
|
||||
$qs = http_build_query($params);
|
||||
|
||||
$req_url = $epGetBuildings."?".$qs;
|
||||
$req_ctx = stream_context_create($ctxOptsGet);
|
||||
|
||||
echo $req_url."\n";
|
||||
$responseText = file_get_contents($req_url, false, $req_ctx);
|
||||
|
||||
if($responseText === false) {
|
||||
echo "Error fetching Buildings in cluster $cluster_rimo_id (".$cluster->name.")\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$buildingsResponse = json_decode($responseText);
|
||||
|
||||
if(is_object($buildingsResponse) && property_exists($buildingsResponse, "item") && is_array($buildingsResponse->item) && count($buildingsResponse->item)) {
|
||||
foreach($buildingsResponse->item as $building) {
|
||||
//var_dump($building);
|
||||
if($building->buildingType && $building->buildingType->userLabel != "Greenfield") {
|
||||
//var_dump($building);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if($building->buildingType && $building->buildingType->userLabel != "Greenfield" && $building->homesCount > 0 && property_exists($building->homes, "item") && is_array($building->homes->item) && count($building->homes->item)) {
|
||||
print_r($building);exit;
|
||||
foreach($building->homes->item as $home) {
|
||||
|
||||
//vaR_dump($home->ftus->item);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//echo $response;
|
||||
echo "\n";
|
||||
Reference in New Issue
Block a user