#!/usr/bin/php id); define("INTERNAL_USER_USERNAME", $me->username); define("MFBASE_BYPASS_LOGIN", true); $log = mfLoghandler::singleton(); $cc = new Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS); $cc_helper = new Citycom_OanApiHelper($cc); foreach(PreordercampaignModel::search(["fulfillment" => "citycom_oan"]) as $campaign) { foreach($campaign->active_preorders as $preorder) { if(!$preorder->adb_wohneinheit_id) continue; $has_inet_service = false; $has_mgmt_service = false; if(is_array($preorder->ctags) && count($preorder->ctags)) { foreach ($preorder->ctags as $ctag) { if ($ctag->network != "citycom-oan") continue; if ($ctag->service_type == "inet") $has_inet_service = true; if ($ctag->service_type == "mgmt") $has_mgmt_service = true; } } if($has_inet_service || $has_mgmt_service) continue; $sublocation_id = \Citycom_OanApiHelper::hausnummerExtrefToCitycomId($preorder->adb_wohneinheit->extref); $data = [ "down" => 100, "up" => 100, "product_name" => "Estmk Greenstream OAN Mgmt", "execution_date" => false, "services" => CITYCOM_OAN_API_SERVICES_FOR_RESERVATION, ]; $log->info(__METHOD__.": Ordering mgmt service for preorder ".$preorder->id); if(!$cc_helper->orderServices($preorder, $sublocation_id, $data)) { $log->error(__METHOD__.": Error ordering mgmt service for preorder ".$preorder->id); continue; } // TODO check for new service @ citycom -> 230 $cc_services = $cc->getServices(); if(!$cc_services) { $log->error(__METHOD__.": Error getting services from Citycom Api"); continue; } foreach($cc_services as $cc_service) { if(!property_exists($cc_service, "location") || !$cc_service->location || !$cc_service->location->id) continue; if(!property_exists($cc_service->location, "sublocation") || !$cc_service->location->sublocation || !$cc_service->location->sublocation->id) continue; if($cc_service->location->sublocation->id != $sublocation_id) continue; // service is available -> set preorder status 230 $preorder->setNewStatusCode(230); $preorder->save(); // update ctag data $valid_stypes = array_merge(CITYCOM_OAN_API_SERVICES_FOR_ORDER, CITYCOM_OAN_API_SERVICES_FOR_RESERVATION); $stypes = array_flip($valid_stypes); $stag = $preorder->adb_hausnummer->vlan_stag; if(!$stag) continue; $ctag = \PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "stag" => $stag, "service_type" => $stypes[$cc_service->service_type]]); if($ctag && $ctag->ext_id != $cc_service->service_number) { $ctag->ext_id = $cc_service->service_number; $ctag->save(); } if($ctag && $ctag->ext_status != $cc_service->state) { $ctag->ext_status = $cc_service->state; $ctag->save(); } } } }