Changed Citycom order flow to new estmk activation workflow

This commit is contained in:
Frank Schubert
2026-01-15 14:16:22 +01:00
parent 6bbf023b85
commit 76be480f7b
9 changed files with 195 additions and 33 deletions

View File

@@ -219,6 +219,21 @@ class Citycom_OanApiClient {
$url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_SERVICES);
$ctx_options = [
"http" => [
"ignore_errors" => true,
"method" => "PUT",
"content" => json_encode($data),
"header" => [
"Accept: application/json",
"Content-type: application/json",
"Authorization: Bearer ".$this->token,
],
]
];
$result = $this->runApiRequest($url, $ctx_options);
return $result;
}
public function cancelService($service_id, $data) {
@@ -449,7 +464,7 @@ class Citycom_OanApiClient {
$output = file_get_contents($final_url, false, $ctx);
$resp = json_decode($output);
//var_dump($resp);
//var_dump($resp);exit;
if(!is_object($resp) || (property_exists($resp, "success") && !$resp->success)) {
$this->lastError = $output;
return false;
@@ -459,6 +474,8 @@ class Citycom_OanApiClient {
if(is_array($response)) {
$return_data = $response;
} elseif(is_object($response) && (!property_exists($response, "data") || !is_array($response->data))) {
$return_data = $response;
} elseif(is_object($response) && property_exists($response, "data") && is_array($response->data)) {
$return_data = $response->data;

View File

@@ -94,7 +94,7 @@ class Citycom_OanApiHelper {
$execution_date = date("Y-m-d");
}
$ctag_range_search = false;
if(array_key_exists("ctag_range_search", $data) && $data["ctag_range_search"]) {
$ctag_range_search = $data["ctag_range_search"];
@@ -116,21 +116,21 @@ class Citycom_OanApiHelper {
// order all services and save ctags
$cc_service_types = $this->api->getServiceTypes();
$this->log->debug(print_r($want_services, true));
$this->log->debug(__METHOD__.": Want services: ".print_r($want_services, true));
$allowed_service_types = array_merge(CITYCOM_OAN_API_SERVICES_FOR_ORDER, CITYCOM_OAN_API_SERVICES_FOR_RESERVATION);
// check if we have these services already
foreach($cc_service_types as $stype) {
if(!in_array($stype->name, $allowed_service_types)) continue;
$ctag_service_type = array_flip($allowed_service_types)[$stype->name];
$ctag_service_type = (array_flip($allowed_service_types))[$stype->name];
if(PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => $ctag_service_type])) {
// service was ordered already, remove from want_services
unset($want_services[$ctag_service_type]);
}
}
$this->log->debug(print_r($want_services, true));
$this->log->debug(__METHOD__.": Want services after filtering: ".print_r($want_services, true));
$new_services = [];
@@ -140,26 +140,32 @@ class Citycom_OanApiHelper {
list($ctags, $mgmt_ctag) = $preorder->getNextFreeCtags();
}
$this->log->debug(print_r($ctags, true));
//var_dump($ctags);
//var_dump($mgmt_ctag);
$this->log->debug(__METHOD__.": ctags: ".print_r($ctags, true));
$this->log->debug(__METHOD__.": mgmt ctag: ".print_r($mgmt_ctag, true));
if(!is_array($ctags)) {
$this->log->error(__METHOD__.": No Free Ctags (Preorder ".$preorder->id.")");
return false;
}
if(count($ctags) < count($want_services)) {
$ctag_count = count($ctags);
if($mgmt_ctag) $ctag_count++;
if($ctag_count < count($want_services)) {
$this->log->error(__METHOD__.": Not enough New Free CTags for Preorder ".$preorder->id);
return false;
}
$preorder_ctag_data = [
"preorder_id" => $preorder->id,
"network" => "citycom-oan",
"stag" => $preorder->adb_hausnummer->vlan_stag,
];
$service_count = 0;
foreach($cc_service_types as $stype) {
// was this service type requested
@@ -169,7 +175,7 @@ class Citycom_OanApiHelper {
if($mgmt_ctag && $stype->name == $allowed_service_types["mgmt"]) {
$ctag = $mgmt_ctag;
} else {
$ctag = $ctags[$service_count];
$ctag = array_shift($ctags);
}
$ctag_service_type = array_flip($allowed_service_types)[$stype->name];
if(!$ctag_service_type) {
@@ -185,6 +191,7 @@ class Citycom_OanApiHelper {
"ctag" => $ctag,
];
//echo "Creating Service ".$stype->name." on sublocation $sublocation_id with product_id $product_id and ctag $ctag\n";
$this->log->info(__METHOD__.": Creating Service ".$stype->name." on sublocation $sublocation_id with product_id $product_id and ctag $ctag");
//continue;
@@ -247,11 +254,61 @@ class Citycom_OanApiHelper {
}
return true;
}
/**
* Updates service values if nesseccary
*
* @param $service_ext_num
* @param $data
* @return bool
*/
public function updateService($service_ext_id, $data) {
// get service and compare data
$services = $this->api->getServices();
if(!$services) {
$this->log->error(__METHOD__.": Error getting services.");
return false;
}
$service = false;
foreach($services as $cc_service) {
if($cc_service->id == $service_ext_id) {
$service = $cc_service;
break;
}
}
if(!$service) {
$this->log->error(__METHOD__.": Service not available.");
return false;
}
$service_data = [];
// update service if nesseccary
if(array_key_exists("product_name", $data) && $data["product_name"] && $service->product->name != $data["product_name"]) {
$product_data["up"] = $data["up"];
$product_data["down"] = $data["down"];
$product_data["name"] = $data["product_name"];
$product_id = $this->findOrCreateProduct($product_data);
if(!$product_id) {
$this->log->error(__METHOD__.": Cannot find or create product ".$product_data["name"]);
return false;
}
$service_data["product_id"] = $product_id;
}
if(!count($service_data)) return true;
$result = $this->api->updateService($service, $service_data);
if($result) return true;
return false;
}
public static function citycomIdToHausnummerExtref($id) {