118 lines
4.5 KiB
PHP
118 lines
4.5 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
/*
|
|
* Looks for new Citycom OAN Orders and orders all services with ctags
|
|
* from Citycom OAN API
|
|
*/
|
|
|
|
//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);
|
|
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) continue;
|
|
|
|
$sublocation_id = \Citycom_OanApiHelper::hausnummerExtrefToCitycomId($preorder->adb_wohneinheit->extref);
|
|
$data = [
|
|
"down" => 100,
|
|
"up" => 100,
|
|
"product_name" => "Estmk Greenstream OAN Default",
|
|
"execution_date" => (new DateTime("+1 month"))->format("Y-m-d"),
|
|
"company" => $preorder->company,
|
|
"firstname" => $preorder->firstname,
|
|
"lastname" => $preorder->lastname,
|
|
"phone" => $preorder->phone,
|
|
"mobile" => $preorder->mobile,
|
|
];
|
|
|
|
$services_to_order = array_merge(CITYCOM_OAN_API_SERVICES_FOR_RESERVATION, CITYCOM_OAN_API_SERVICES_FOR_ORDER);
|
|
if($has_mgmt_service) {
|
|
$services_to_order = CITYCOM_OAN_API_SERVICES_FOR_ORDER;
|
|
}
|
|
$data["services"] = $services_to_order;
|
|
|
|
$existing_ctag = \PreorderCtag::getFirstActive(["preorder_id" => $preorder->id]);
|
|
if($existing_ctag) {
|
|
$data["ctag_range_search"] = $existing_ctag->ctag;
|
|
}
|
|
|
|
$log->info(__FILE__.": Ordering Citycom services for preorder ".$preorder->id);
|
|
if(!$cc_helper->orderServices($preorder, $sublocation_id, $data)) {
|
|
$log->error(__FILE__.": Error ordering Citycom services for preorder ".$preorder->id);
|
|
continue;
|
|
}
|
|
//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->id) {
|
|
$ctag->ext_id = $cc_service->id;
|
|
$ctag->save();
|
|
}
|
|
if($ctag && $ctag->ext_name != $cc_service->service_number) {
|
|
$ctag->ext_name = $cc_service->service_number;
|
|
$ctag->save();
|
|
}
|
|
if($ctag && $ctag->ext_status != $cc_service->state) {
|
|
$ctag->ext_status = $cc_service->state;
|
|
$ctag->save();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} |