From 202a7fd47856d5f6211cea39c61007310ded15b1 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 15 Jul 2025 16:48:04 +0200 Subject: [PATCH] Added basic Citycom ADB Import --- .../ADBNetzgebiet/ADBNetzgebietModel.php | 14 + lib/Citycom/OanApi.php | 307 ++++++++++++++++++ .../ADBAddressHelper/address_helper.php | 166 +++++++++- scripts/adb-rimo-import/importer/citycom.php | 218 +++++++++++++ scripts/adb-rimo-import/rimo-import.php | 43 ++- 5 files changed, 735 insertions(+), 13 deletions(-) create mode 100644 lib/Citycom/OanApi.php create mode 100644 scripts/adb-rimo-import/importer/citycom.php diff --git a/application/ADBNetzgebiet/ADBNetzgebietModel.php b/application/ADBNetzgebiet/ADBNetzgebietModel.php index 2bc3c731a..c53692260 100644 --- a/application/ADBNetzgebiet/ADBNetzgebietModel.php +++ b/application/ADBNetzgebiet/ADBNetzgebietModel.php @@ -157,6 +157,20 @@ class ADBNetzgebietModel { $where .= " AND Netzgebiet.`rimo_id` LIKE '%$rimo_id%'"; } } + + if(array_key_exists("source_id", $filter)) { + $source_id = FronkDB::singleton()->escape($filter['source_id']); + if($source_id) { + $where .= " AND Netzgebiet.`source_id` LIKE '%$source_id%'"; + } + } + + if(array_key_exists("source", $filter)) { + $source = FronkDB::singleton()->escape($filter['source']); + if($source) { + $where .= " AND Netzgebiet.`source` = '$source'"; + } + } if(array_key_exists("borderpoly", $filter)) { $borderpoly = $filter['borderpoly']; diff --git a/lib/Citycom/OanApi.php b/lib/Citycom/OanApi.php new file mode 100644 index 000000000..874c07b21 --- /dev/null +++ b/lib/Citycom/OanApi.php @@ -0,0 +1,307 @@ +baseurl = CITYCOM_OAN_API_URL; + $this->username = $user; + $this->password = $pass; + } + + public function getLocations() { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_LOCATIONS; + + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $locations = $this->sendGetRequest($url, $ctx_options); + return $locations; + } + + public function getHomes($location_id) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_HOMES; + $url = str_replace("{location_id}", $location_id, $url); + + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $homes = $this->sendGetRequest($url, $ctx_options); + return $homes; + } + + + public function getProducts() { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS; + echo $url; + + } + + public function createProduct($data) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_PRODUCT; + echo "$url\n"; + + } + + public function updateProduct($product_id, $data) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_PRODUCT); + echo $url; + + } + + public function deleteProduct($product_id) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_DELETE_PRODUCT); + echo "$url\n"; + + } + + + public function getServices() { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_SERVICES; + echo "$url\n"; + + } + + public function createService($home_id, $data) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_SERVICES; + echo "$url\n"; + + } + + public function updateService($service_id, $data) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_SERVICES); + echo $url; + + } + + public function cancelService($service_id, $data) { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_CANCEL_SERVICES); + echo "$url\n"; + + } + + public function getServiceTypes() { + if(!$this->token) { + $this->getAuthToken(); + if(!$this->token) { + return false; + } + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_GET_SERVICE_TYPES; + $ctx_options = [ + "http" => [ + "ignore_errors" => true, + "method" => "GET", + "header" => [ + "Accept: application/json", + "Authorization: Bearer ".$this->token, + ], + ] + ]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + $resp = json_decode($output); + if(!is_object($resp) || !property_exists($resp, "success") || !$resp->success) { + return false; + } + + $types = $resp->data; + + var_dump($types);exit; + + return $types; + } + + private function getAuthToken() { + $token = new mfConfig("adb.import.citycom.auth.token"); + if($token && $token->value()) { + $this->token = $token->value(); + return true; + } + + $url = $this->baseurl.CITYCOM_OAN_API_EP_LOGIN; + + $ctx_options = ["http" => [ + "ignore_errors" => true, + "method" => "POST", + "headers" => [ + "Accept: application/json", + "Content-Type: multipart/form-data", + ], + "content" => http_build_query([ + "email" => $this->username, + "password" => $this->password, + ]), + ]]; + + $ctx = stream_context_create($ctx_options); + $output = file_get_contents($url, false, $ctx); + + $resp = json_decode($output); + if(!is_object($resp) || !property_exists($resp, "success") || !$resp->success) { + return false; + } + + if(!$resp->data->token) { + return false; + } + + $this->token = $resp->data->token; + + // save token + $token->value($this->token); + $token->save(); + + return true; + } + + private function sendGetRequest($url, $ctx_opts, $url_params = [], $page_num = 1) { + $current_page = $page_num; + $return_data = []; + + $ctx = stream_context_create($ctx_opts); + + // build final url with url_params and page_num + $final_url_params = $url_params; + if($page_num > 1) { + $final_url_params["page"] = $page_num; + } + + if(count($final_url_params)) { + $qs = http_build_query($final_url_params); + $final_url = "$url?$qs"; + } else { + $final_url = "$url"; + } + + // run request + //echo "URL: $final_url\n"; + $output = file_get_contents($final_url, false, $ctx); + + $resp = json_decode($output); + //var_dump($resp); + if(!is_object($resp) || !property_exists($resp, "success") || !$resp->success) { + return false; + } + + $response = $resp->data; + + if(is_array($response)) { + $return_data = $response; + } elseif(is_object($response) && property_exists($response, "data") && is_array($response->data)) { + $return_data = $response->data; + + if(property_exists($response, "last_page") && $response->last_page > 1) { + if($current_page < $response->last_page) { + $next_page = $current_page + 1; + $next_data = $this->sendGetRequest($url, $ctx_opts, $url_params, $next_page); + if(!$next_data) { + return $return_data; + } + $return_data = array_merge($return_data, $next_data); + } + } + } else { + throw new Exception(__METHOD__.": Unknown API return type"); + } + + return $return_data; + + } + + + +} \ No newline at end of file diff --git a/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php b/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php index 95c4d4d84..4cb99d99b 100644 --- a/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php +++ b/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php @@ -110,6 +110,171 @@ class AddressHelper return [$strasse_name, $hausnummer_name, $addresszusatz]; } + public function findUpdateAddressFromCitycomLocation($location) { + $create_address_parts = false; + $update_freigabe = false; + $update_address = true; + if ($this->netzgebiet) { + $create_address_parts = $this->netzgebiet->getOption("create_address_parts"); + $update_freigabe = $this->netzgebiet->getOption("update_freigabe"); + $option_update_address = $this->netzgebiet->getOption("update_address"); + if($option_update_address !== null) { + $update_address = $option_update_address; + } + } + + $cc_id = $location->id; + $strasse_name = $location->street; + $hausnummer_name = $location->number; + $plz_name = $location->zip; + $gem_name = $location->city; + $stag = $location->stag; + + if($gem_name == "Raaba") { + $gem_name = "Raaba-Grambach"; + } + + $addresszusatz = false; + + $addr_dbg_str = "gem_name: $gem_name | plz_name: $plz_name | cc-id: $cc_id"; + + $extref = $this->citycomIdToHausnummerExtref($cc_id); + + // get Gemeinde + $gemeinde = ADBGemeindeModel::getFirst(["name" => $gem_name]); + if (!$gemeinde) { + //$this->log->warning("[EE] Gemeinde $gem_name $gem_kz nicht gefunden ($addr_dbg_str)"); + $this->logFindAddressError("[EE] Gemeinde '$gem_name' nicht gefunden ($addr_dbg_str)"); + return false; + } + $gemeinde_id = $gemeinde->id; + + + // find by Extref + $hausnummer = ADBHausnummerModel::getFirst(["extref" => $extref]); + if(!$hausnummer) { + // find by address + $hausnummer = $this->findHausnummerByStreet($strasse_name, $hausnummer_name, $gemeinde_id); + } + if(!$hausnummer) { + // hausnummer anlegen + $plz = ADBPlzModel::getFirst(["gemeinde_id" => $gemeinde_id, "plz" => $plz_name]); + if (!$plz) { + $this->logFindAddressError("[EE] PLZ '$plz_name' nicht gefunden ($addr_dbg_str)"); + return false; + } + + $strasse = ADBStrasseModel::getFirst(["gemeinde_id" => $gemeinde_id, "name" => $strasse_name]); + + if (!$strasse && $create_address_parts) { + $strasse = $this->createStreet($gemeinde_id, $strasse_name); + } + + if (!$strasse) { + $this->logFindAddressError("[EE] Konnte Strasse '$strasse_name' in Gemeinde '$gemeinde_id' nicht finden bzw. anlegen ($addr_dbg_str)"); + return false; + } + + $hausnummer_data = [ + "netzgebiet_id" => $this->netzgebiet->id, + "extref" => $extref, + "plz_id" => $plz->id, + "strasse_id" => $strasse->id, + "hausnummer" => $hausnummer_name, + "zusatz" => ($addresszusatz) ? $addresszusatz : null, + ]; + $hausnummer = ADBHausnummerModel::create($hausnummer_data); + //var_dump($hausnummer);exit; + //echo "----------------------\ncreating hausnummer:\n"; + //print_r($hausnummer); + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving new Hausnummer ($addr_dbg_str)"); + return false; + } + } + + if(!$hausnummer->id) { + $this->logFindAddressError("[EE] Unable to find or create Hausnummer ($addr_dbg_str)"); + return false; + } + + + $this->checkGemeindeNetzgebiet($gemeinde, $this->netzgebiet); + + // update hausnummer + if ($hausnummer->netzgebiet_id != $this->netzgebiet->id) { + // only if overwriting netzgebiet_id is allowed in old netzgebiet + $dont_overwrite_netzgbiet = $hausnummer->netzgebiet->getOption("hausnummer_dont_overwrite_netzgebiet"); + if (!$dont_overwrite_netzgbiet) { + $hausnummer->netzgebiet_id = $this->netzgebiet->id; + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving Hausnummer ($addr_dbg_str)"); + return false; + } + } + } + + if($update_address) { + if ($strasse_name != $hausnummer->strasse->name) { + $new_strasse = ADBStrasseModel::getFirst(["gemeinde_id" => $gemeinde_id, "name" => $strasse_name]); + if ($new_strasse) { + $this->logFindAddressError("[II] Updating Strasse from " . $hausnummer->strasse->name . " to " . $new_strasse->name . " ($addr_dbg_str)"); + $hausnummer->strasse_id = $new_strasse->id; + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving Hausnummer ($addr_dbg_str)"); + return false; + } + } else { + $this->logFindAddressError("[WW] Cannot update Strasse from " . $hausnummer->strasse->name . " to " . $strasse_name . " because not found ($addr_dbg_str)"); + } + } + + if ($hausnummer_name != $hausnummer->hausnummer) { + $this->logFindAddressError("[II] Updating Hausnummer from " . $hausnummer->hausnummer . " to " . $hausnummer_name . " ($addr_dbg_str)"); + $hausnummer->hausnummer = $hausnummer_name; + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving Hausnummer ($addr_dbg_str)"); + return false; + } + } + + if ($plz_name != $hausnummer->plz->plz) { + $new_plz = ADBPlzModel::getFirst(["gemeinde_id" => $gemeinde_id, "plz" => $plz_name]); + if ($new_plz) { + $this->logFindAddressError("[II] Updating PLZ from " . $hausnummer->plz->plz . " to " . $new_plz->plz . " ($addr_dbg_str)"); + $hausnummer->plz_id = $new_plz->id; + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving Hausnummer ($addr_dbg_str)"); + return false; + } + } else { + $this->logFindAddressError("[WW] Cannot update PLZ from " . $hausnummer->plz->plz . " to " . $plz_name . " because not found ($addr_dbg_str)"); + } + } + } + + if ($hausnummer->extref != $extref) { + $hausnummer->extref = $extref; + if(!$hausnummer->save()) { + $this->logFindAddressError("[EE] Error saving Hausnummer ($addr_dbg_str)"); + return false; + } + } + + return $hausnummer; + + } + + public function citycomIdToHausnummerExtref($id) { + if(!$id) return false; + return "citycom-$id"; + } + + public function hausnummerExtrefToCitycomId($extref) { + if(!$extref) return false; + return str_replace("citycom-", "", $extref); + } + public function findUpdateAddressFromRimoBuilding($building) { $hausnummer = false; @@ -134,7 +299,6 @@ class AddressHelper } } - $name = $this->trimExtra($building->name); $strasse_hausnummer = trim($this->trimExtra($building->address->name)); $split_result = $this->splitStreetHausnummer($strasse_hausnummer); diff --git a/scripts/adb-rimo-import/importer/citycom.php b/scripts/adb-rimo-import/importer/citycom.php new file mode 100644 index 000000000..b99b0574f --- /dev/null +++ b/scripts/adb-rimo-import/importer/citycom.php @@ -0,0 +1,218 @@ +$type = $dependencies[$type]; + } + } + + } + + + public function runImport() { + // get locations (Hausnummer) + Sublocations (Wohneinheiten) + $hausnummer_found_count = 0; + + $ccapi = new \Citycom_OanApi(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS); + + $locations = $ccapi->getLocations(); + if(!is_array($locations)) { + $this->log->debug(__METHOD__.": Keine Locations von Citycom OAN API. Exiting Import."); + return true; + } + + $AddressHelper = new AddressHelper(["log" => $this->log, "db" => $this->db, "netzgebiet" => $this->netzgebiet]); + + foreach($locations as $location) { + // find Hausnummer or create it + $hausnummer = $AddressHelper->findUpdateAddressFromCitycomLocation($location); + + if (!$hausnummer) { + //echo "Adresse nicht gefunden: $rimo_building_id\n"; + + if ($AddressHelper->find_address_error) { + $this->addressErrors[] = $AddressHelper->find_address_error; + } + + continue; + } + $hausnummer_found_count++; + $hausnummer_id = $hausnummer->id; + + $homes = $ccapi->getHomes($location->id); + if(!is_array($homes)) { + continue; + } + + $homes_count = 0; + + // find Wohneinheit or create it + $last_unit_num = 0; + $existing_units = []; + $existing_units_extref = []; + foreach (\ADBWohneinheitModel::search(["hausnummer_id" => $hausnummer->id]) as $unit) { + $existing_units[] = $unit; + $existing_units_extref[$unit->extref] = $unit; + if ($last_unit_num < $unit->num) { + $last_unit_num++; + } + } + + //var_dump($existing_units);exit; + + $rimo_home_count = 0; + if (is_array($homes) && count($homes)) { + $rimo_home_count = count($homes); + } + $to_create_count = $rimo_home_count - count($existing_units); + + if ($rimo_home_count && $to_create_count > 0) { + for ($i = 0; $i < $to_create_count; $i++) { + $unit = \ADBWohneinheitModel::create([ + "hausnummer_id" => $hausnummer->id, + "num" => ++$last_unit_num + ]); + if (!$unit->save()) { + die("Error saving new unit\n" . print_r($unit, true)); + } + } + } + + $rimo_home_list = []; + + foreach($homes as $home) { + if(!$home->id) continue; + $extref = $this->citycomIdToHausnummerExtref($home->id); + + //$hausnummer = new \ADBHausnummer($hausnummer_id); + $homes_count++; + $home_cc_id = $home->id; + $home_oaid = $home->oan_id; + + $rimo_home_list[] = $extref; + + //echo "$home_rimo_id\n";continue; + + if (array_key_exists($extref, $existing_units_extref)) { + $unit = $existing_units_extref[$extref]; + } else { + // find free home without rimo_id + $unit = \ADBWohneinheitModel::getFirst(["hausnummer_id" => $hausnummer->id, "extref" => null]); + //echo "-- Using free unit\n"; + } + + if (!$unit) { + // create unit + $unit = \ADBWohneinheitModel::create([ + "hausnummer_id" => $hausnummer->id, + "extref" => $extref, + "num" => ++$last_unit_num + ]); + if (!$unit->save()) { + die("Error saving new unit\n" . print_r($home, true)); + } + + //$unit = new \ADBWohneinheit($unit->id); + + } + + if($home->oan_id) { + if($unit->oaid != $home->oan_id) { + $unit->oaid = $home->oan_id; + $unit->save(); + } + + $status_300 = \ADBStatusModel::getFirst(["code" => 300]); + if(!$status_300) { + die("ADB Status 245 not found"); + } + if($unit->status->code < 300) { + $unit->status_id = $status_300->id; + $unit->save(); + + } + + $status_code_241 = \ADBStatusModel::getFirst(["code" => 241]); + if($hausnummer->status->code < 241) { + $hausnummer->status_id = $status_code_241->id; + $hausnummer->save(); + } + } + + \mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0); + \mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0); + + if($unit->rimo_deleted) { + $unit->rimo_deleted = 0; + $unit->save(["no_updates" => 1]); + } + + if ($unit->extref != $extref) { + $unit->extref = $extref; + if (!$unit->save()) { + die("Error saving new extref on unit\n" . print_r($home, true)); + } + //$unit = new \ADBWohneinheit($unit->id); + \mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0); + \mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0); + } + + + + } + + + } + + return true; + } + + public function citycomIdToHausnummerExtref($id) { + if(!$id) return false; + return "citycom-$id"; + } + + public function hausnummerExtrefToCitycomId($extref) { + if(!$extref) return false; + return str_replace("citycom-", "", $extref); + } + + private function deleteHomesIfEligible($ext_home_list, $hausnummer) { + $return_strings = []; + foreach (\ADBWohneinheitModel::search(["hausnummer_id" => $hausnummer->id]) as $adb_unit) { + $adb_unit->rimo_deleted = 1; + /*if(!$adb_unit->extref) { + $adb_unit->save(["no_updates" => 1]); + continue; + } + */ // auskommentiert, um auch homes ohne rimo_id zu löschen + + if(!in_array($adb_unit->extref, $ext_home_list)) { + if(count($adb_unit->active_preorders)) { + // don't delete if there is an active order + $adb_unit->save(["no_updates" => 1]); + continue; + } + + echo "[DD] Deleting Hausnummer ".$adb_unit->hausnummer_id." Wohneinheit ".$adb_unit->id." (extref ".$adb_unit->extref.")\n"; + $return_strings[] = "[DD] Deleting Hausnummer ".$adb_unit->hausnummer_id." Wohneinheit ".$adb_unit->id." (extref ".$adb_unit->extref.")"; + + $adb_unit->delete(); + + } + } + return $return_strings; + } +} \ No newline at end of file diff --git a/scripts/adb-rimo-import/rimo-import.php b/scripts/adb-rimo-import/rimo-import.php index 4f480a701..36427b0a5 100755 --- a/scripts/adb-rimo-import/rimo-import.php +++ b/scripts/adb-rimo-import/rimo-import.php @@ -113,7 +113,7 @@ foreach ($netowners as $apiOwner) { } foreach ($clustersResponse->item as $cluster) { - $cluster_data = ["apiOwner" => $apiOwner, "apiKey" => $apiToken, "apiUrl" => $apiUrl, "cluster" => $cluster]; + $cluster_data = ["apiOwner" => $apiOwner, "apiKey" => $apiToken, "apiUrl" => $apiUrl, "source_id" => $cluster->id, "cluster" => $cluster]; $clusters[$cluster->id] = $cluster_data; } } @@ -126,12 +126,13 @@ foreach(\ADBNetzgebietModel::getAll() as $adb_cluster) { } if(!array_key_exists($adb_cluster->source_id, $clusters)) { - //$clusters[$adb_cluster->source_id] = ["apiOwner" => "", "apiKey" => "", "apiUrl" => "", "cluster" => $adb_cluster]; + $clusters[$adb_cluster->source_id] = ["apiOwner" => "", "apiKey" => "", "apiUrl" => "", "source_id" => $adb_cluster->source_id, "cluster" => $adb_cluster]; } } foreach ($clusters as $cluster_data) { $cluster = $cluster_data["cluster"]; + $cluster_source_id = $cluster_data["source_id"]; $apiOwner = $cluster_data["apiOwner"]; $apiUrl = $cluster_data["apiUrl"]; $apiToken = $cluster_data["apiKey"]; @@ -142,34 +143,52 @@ foreach ($clusters as $cluster_data) { $cluster_name = $cluster->name; if ($command == "list-rimo-clusters") { - echo "($apiOwner) $cluster_rimo_id | name: " . $cluster->name . "; label: " . $cluster->userLabel . "\n"; + echo "($apiOwner) $cluster_source_id | name: " . $cluster->name . "; label: " . $cluster->userLabel . "\n"; continue; } - $adb_netzgebiet = \ADBNetzgebietModel::getFirst(['rimo_id' => $cluster_rimo_id]); + $adb_netzgebiet = \ADBNetzgebietModel::getFirst(['source_id' => $cluster_source_id]); if (!$adb_netzgebiet) { //echo "Kein Netzgebiet für Salescluster $cluster_rimo_id (".$cluster->name.")\n"; continue; } + //echo "command: $command request_cluster: $request_cluster - cluster_source_id $cluster_source_id\n"; + if ($command == "cluster_only" && $request_cluster) { + if ($cluster_source_id != $request_cluster) { + continue; + } + } + /* * import non-rimo clusters */ + //echo $adb_netzgebiet->source." ".$adb_netzgebiet->source_id."\n";continue; if($adb_netzgebiet->source == "citycom-oan-api" ) { // load and run citycom importer - /* - $citycom_importer = new CitycomImporter(["db" => $adb, "log" => $log, "netzgebiet" => $adb_netzgebiet]); + echo "Netzgebiet ".$adb_netzgebiet->name." is Citycom OAN\n"; + + require_once __DIR__."/importer/citycom.php"; + $citycom_importer = new importer\CitycomImporter(["db" => $adb, "log" => $log, "netzgebiet" => $adb_netzgebiet]); $citycom_importer->runImport(); - */ + + // log errors + if ($citycom_importer->addressErrors) { + $netzname = preg_replace('/[^a-z0-9.-]/i', "_", $adb_netzgebiet->name); + + $out_folder = dirname(__FILE__) . "/output/$startdate"; + if (!file_exists($out_folder)) { + mkdir($out_folder); + } + $out_filename = $out_folder . "/output-$netzname-$starttime.log"; + file_put_contents($out_filename, join("\n", $citycom_importer->addressErrors)); + } + continue; } $addressErrors = []; - if ($command == "cluster_only" && $request_cluster) { - if ($cluster_rimo_id != $request_cluster) { - continue; - } - } + $baseParams = ['apiKey' => $apiToken];