121 lines
4.3 KiB
PHP
121 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace application\Api\v1\Modules\Operationaldata;
|
|
use application\Api\v1\Modules;
|
|
use PreorderCtag;
|
|
|
|
require_once(APPDIR."/Api/v1/Modules/ApiControllerModule.php");
|
|
|
|
/*
|
|
* API Endpoints for Operationaldata from SNOPP
|
|
*/
|
|
class SnoppCitycom extends Modules\ApiControllerModule
|
|
{
|
|
|
|
public function init()
|
|
{
|
|
|
|
}
|
|
|
|
public function orderService($req_id) {
|
|
if(!$req_id) {
|
|
return \mfResponse::BadRequest(["message" => "id missing"]);
|
|
}
|
|
|
|
$bb_up = $this->post["bb_up"];
|
|
$bb_down = $this->post["bb_down"];
|
|
$execution_date = false;
|
|
|
|
if($this->post["execution_date"]) {
|
|
try {
|
|
$execution_date = new \DateTime($this->post["execution_date"]);
|
|
} catch(\Exception $e) {
|
|
return \mfResponse::BadRequest(["message" => "Invalid Timestamp format"]);
|
|
}
|
|
}
|
|
|
|
|
|
if(!is_numeric($bb_down) || !$bb_down || !is_numeric($bb_up) || !$bb_up || !$bb_down > 10000 || $bb_up > 10000) {
|
|
return \mfResponse::BadRequest(["message" => "Invalid bandwidth"]);
|
|
}
|
|
|
|
$wohneinheit = false;
|
|
if(is_numeric($req_id)) {
|
|
$id = $req_id;
|
|
$wohneinheit = new \ADBWohneinheit($id);
|
|
}
|
|
if(!$wohneinheit || !$wohneinheit->id) {
|
|
$oaid = $req_id;
|
|
$wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]);
|
|
if (!$wohneinheit) {
|
|
return \mfResponse::NotFound(["message" => "Home not found"]);
|
|
}
|
|
}
|
|
|
|
$preorder = \PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
|
if(!$preorder) {
|
|
return \mfResponse::NotFound(["message" => "Home not found"]);
|
|
}
|
|
|
|
// if all services are ordered and active, finish order and return active
|
|
$ctag = PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => "inet"]);
|
|
if($ctag->ext_id && $ctag->ext_status == "finished") {
|
|
if($preorder->status->code < 500) {
|
|
$preorder->setNewStatusCode(500);
|
|
$preorder->save();
|
|
}
|
|
return \mfResponse::Ok(["message" => "Service active already", "activation_status" => "active"]);
|
|
}
|
|
|
|
|
|
// Home must have Status 300, else return deferred
|
|
if($wohneinheit->status->code < 300) {
|
|
return \mfResponse::Ok(["message" => "ONT not yet installed. Deferred", "activation_status" => "deferred"]);
|
|
}
|
|
|
|
|
|
$cc_home_id = \Citycom_OanApiHelper::hausnummerExtrefToCitycomId($wohneinheit->extref);
|
|
$data["up"] = $bb_up;
|
|
$data["down"] = $bb_down;
|
|
$data["product_name"] = false;
|
|
$data["execution_date"] = ($execution_date) ? $execution_date->format("Y-m-d") : false;
|
|
$data["services"] = CITYCOM_OAN_API_SERVICES_FOR_ORDER;
|
|
|
|
// check if mgmt ctag is set
|
|
// so we use the same ctag set for the real services
|
|
$mgmt_ctag = \PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => "mgmt"]);
|
|
if($mgmt_ctag) {
|
|
$data["ctag_range_search"] = $mgmt_ctag->ctag;
|
|
}
|
|
|
|
|
|
if($preorder->campaign->name == "Citycom - Graz") {
|
|
$data["product_name"] = "Estmk Greenstream OAN $bb_down/$bb_up";
|
|
}
|
|
|
|
|
|
$cc_api_client = new \Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS);
|
|
$cc_api = new \Citycom_OanApiHelper($cc_api_client);
|
|
|
|
// order Service at Citycom and set Preorder to 500 Finished
|
|
if(!$cc_api->orderServices($preorder, $cc_home_id, $data)) {
|
|
return \mfResponse::InternalServerError(["message" => "Error activating service"]);
|
|
}
|
|
|
|
// live check if service is active, if not return deferred
|
|
$ctag = PreorderCtag::getFirstActive(["preorder_id" => $preorder->id, "service_type" => "inet"]);
|
|
if($ctag->ext_id && $ctag->ext_status == "finished") {
|
|
if($preorder->status->code < 500) {
|
|
$preorder->setNewStatusCode(500);
|
|
$preorder->save();
|
|
}
|
|
return \mfResponse::Ok(["message" => "Service active already", "activation_status" => "active"]);
|
|
}
|
|
|
|
return \mfResponse::Ok(["message" => "Services ordered, not yet finished", "activation_status" => "deferred"]);
|
|
|
|
}
|
|
|
|
|
|
}
|