Merge branch 'fronkdev' into 'master'
WIP 2025-07-31 Citycom OAN Api WIP See merge request fronk/thetool!1591
This commit is contained in:
@@ -76,9 +76,7 @@ class SnoppCitycom extends Modules\ApiControllerModule
|
||||
return \mfResponse::InternalServerError(["message" => "Error activating service"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
return \mfResponse::Ok();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -598,7 +598,7 @@ class Preorder extends mfBaseModel {
|
||||
}*/
|
||||
|
||||
if($preorder->status->code < $status->code && $status->code <= 244) {
|
||||
$preorder->status_id = $this->status_id;
|
||||
$preorder->status_id = $status->id;
|
||||
$preorder->save();
|
||||
}
|
||||
}
|
||||
@@ -669,6 +669,50 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
public function getNextFreeCtags() {
|
||||
if(!$this->getProperty("adb_hausnummer")->vlan_stag) {
|
||||
echo "no stag\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$stag = $this->adb_hausnummer->vlan_stag;
|
||||
$new_ctag = false;
|
||||
$ctags_per_home = 1;
|
||||
|
||||
$network_name = "";
|
||||
if($this->adb_hausnummer->netzgebiet->source == "citycom-oan-api") {
|
||||
$network_name = "citycom-oan";
|
||||
$first_ctag = CITYCOM_OAN_FIRST_CTAG;
|
||||
$ctags_per_home = count(CITYCOM_OAN_API_SERVICES_FOR_ORDER) + count(CITYCOM_OAN_API_SERVICES_FOR_RESERVATION); // Service VLANS + mgmt VLANS
|
||||
}
|
||||
|
||||
if(!$network_name) {
|
||||
echo "no network\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$last_ctag = PreorderCtag::getLast(["stag" => $stag, "network" => $network_name]);
|
||||
if(!$last_ctag) {
|
||||
$new_ctag = $first_ctag;
|
||||
} else {
|
||||
$last_ctag_num = $last_ctag->ctag;
|
||||
|
||||
$miss = $last_ctag_num % $ctags_per_home;
|
||||
if($miss) {
|
||||
$last_ctag_num = $last_ctag_num - $miss;
|
||||
}
|
||||
|
||||
$new_ctag = $last_ctag_num + $ctags_per_home;
|
||||
}
|
||||
|
||||
$new_ctags = [];
|
||||
for($i = $new_ctag; $i < $new_ctag + $ctags_per_home; $i++) {
|
||||
$new_ctags[] = $i;
|
||||
}
|
||||
|
||||
return $new_ctags;
|
||||
}
|
||||
|
||||
public function setOrCreateOaid($oaid_attributes = false) {
|
||||
$campaign = new Preordercampaign($this->preordercampaign_id);
|
||||
//var_dump($campaign);exit;
|
||||
|
||||
199
application/PreorderCitycomOan/PreorderCitycomOan.php
Normal file
199
application/PreorderCitycomOan/PreorderCitycomOan.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
class PreorderCitycomOan extends mfBaseModel {
|
||||
protected $forcestr = ["product_name","product_info","matchcode"];
|
||||
private $preorder;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name . "_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderCitycomOan();
|
||||
|
||||
$table_fields = [
|
||||
"preorder_id", "ont_id", "ont_sn", "ont_gpid", "ont_mac",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreorderCitycomOan", "*", "1 = 1 ORDER BY preorder_id,ont_sn");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderCitycomOan($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT PreorderCitycomOan.* FROM PreorderCitycomOan
|
||||
WHERE $where
|
||||
ORDER BY preorder_id,ont_sn LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderCitycomOan($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM PreorderCitycomOan
|
||||
WHERE $where";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "preorder_id,ont_sn ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT PreorderCitycomOan.* FROM PreorderCitycomOan
|
||||
LEFT JOIN Preorder ON Preorder.id = PreorderCitycomOan.preorder_id
|
||||
WHERE $where
|
||||
ORDER BY $order";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new PreorderCitycomOan($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if(is_numeric($preorder_id)) {
|
||||
$where .= " AND PreorderCitycomOan.preorder_id=$preorder_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ont_id", $filter)) {
|
||||
$ont_id = FronkDB::singleton()->escape($filter['ont_id']);
|
||||
if($ont_id) {
|
||||
$where .= " AND PreorderCitycomOan.ont_id LIKE '$ont_id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ont_sn", $filter)) {
|
||||
$ont_sn = FronkDB::singleton()->escape($filter['ont_sn']);
|
||||
if($ont_sn) {
|
||||
$where .= " AND PreorderCitycomOan.ont_sn LIKE '$ont_sn'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ont_gpid", $filter)) {
|
||||
$ont_gpid = FronkDB::singleton()->escape($filter['ont_gpid']);
|
||||
if($ont_gpid) {
|
||||
$where .= " AND PreorderCitycomOan.ont_gpid LIKE '$ont_gpid'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ont_mac", $filter)) {
|
||||
$ont_mac = FronkDB::singleton()->escape($filter['ont_mac']);
|
||||
if($ont_mac) {
|
||||
$where .= " AND PreorderCitycomOan.ont_mac LIKE '$ont_mac'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
316
application/PreorderCtag/PreorderCtag.php
Normal file
316
application/PreorderCtag/PreorderCtag.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
class PreorderCtag extends mfBaseModel {
|
||||
protected $forcestr = ["product_name","product_info","matchcode"];
|
||||
private $preorder;
|
||||
private $invoice;
|
||||
private $adb_wohneinheit;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
/**
|
||||
* Configures Networking equipment depending on network type
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function configureNetwork() {
|
||||
if($this->network == "citycom-oan-api") {
|
||||
return $this->configureNetworkCitycom();
|
||||
}
|
||||
|
||||
// nothing to do
|
||||
return true;
|
||||
}
|
||||
|
||||
private function configureNetworkCitycom() {
|
||||
$stag = $this->stag;
|
||||
if(!$stag) {
|
||||
$this->log->error(__METHOD__.": No stag");
|
||||
return false;
|
||||
}
|
||||
|
||||
$ctag = $this->ctag;
|
||||
if(!$ctag) {
|
||||
$this->log->error(__METHOD__.": No ctag");
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $this->service_type;
|
||||
|
||||
$preorder = $this->getProperty("preorder");
|
||||
if(!$preorder->id) {
|
||||
$this->log->error(__METHOD__.": No preorder id");
|
||||
return false;
|
||||
}
|
||||
|
||||
$oaid = $preorder->oaid;
|
||||
if(!$oaid) {
|
||||
$oaid = $preorder->adb_wohneinheit->oaid;
|
||||
}
|
||||
if(!$oaid) {
|
||||
$this->log->error(__METHOD__.": No OAID in Preorder ".$preorder->id." or Wohneinheit ".$preorder->adb_wohneinheit->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
$oaid = preg_replace('/[^a-z0-9._-]+/i', '', $oaid);
|
||||
if(!$oaid) {
|
||||
$this->log->error(__METHOD__.": OAID invalid after cleanup in Preorder ".$preorder->id." or Wohneinheit ".$preorder->adb_wohneinheit->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
$stag_name = "";
|
||||
|
||||
try {
|
||||
$ros = new mfRouteros(CITYCOM_OAN_NNI_HOST, CITYCOM_OAN_NNI_USERNAME, CITYCOM_OAN_NNI_PASSWORD, CITYCOM_OAN_NNI_PORT,CITYCOM_OAN_NNI_USE_SSL);
|
||||
|
||||
// get all vlan interfaces
|
||||
$vlans = $ros->get("/interface vlan");
|
||||
|
||||
// find stag vlan
|
||||
foreach($vlans as $vlan) {
|
||||
if($vlan->{'vlan-id'} == $stag) {
|
||||
if($stag_name) {
|
||||
$this->log->error(__METHOD__.": Found VLAN Interface again for stag $stag");
|
||||
}
|
||||
$stag_name = $vlan->name;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$stag_name) {
|
||||
$this->log->error(__METHOD__.": Vlan for stag $stag not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($vlans as $vlan) {
|
||||
if($vlan->{'interface'} == $stag_name && $vlan->{'vlan-id'} == $this->ctag) {
|
||||
$this->log->info(__METHOD__." ctag vlan $ctag already exists in stag $stag (ifname: $stag_name)");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ctag not found -> create ctag
|
||||
$vlan_name = "vl_{$oaid}_{$type}_ctag$ctag";
|
||||
$vlan_data = [
|
||||
"vlan-id" => $ctag,
|
||||
"interface" => $stag_name,
|
||||
"name" => $vlan_name,
|
||||
];
|
||||
if(!$ros->add("/interface vlan", $vlan_data)) {
|
||||
$this->log->error(__METHOD__." error creating vlan interface for ctag $ctag (ifname: ".$vlan_data["name"].") in stag $stag (ifname: $stag_name)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// add to interface-list
|
||||
|
||||
$ros->add("/interface list member", ["interface" => $vlan_name, "list" => CITYCOM_OAN_API_NNI_IFLIST_NAME]);
|
||||
return true;
|
||||
|
||||
} catch(Exception $e) {
|
||||
$this->log->error(__METHOD__.": Exception: ".$e->getMessage()."\n".$e->getTraceAsString());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name . "_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderCtag();
|
||||
|
||||
$table_fields = [
|
||||
"preorder_id", "network", "stag", "ctag", "service_type", "deleted",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreorderCtag", "*", "1 = 1 ORDER BY preorder_id,stag,ctag");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderCtag($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT PreorderCtag.* FROM PreorderCtag
|
||||
WHERE $where
|
||||
ORDER BY preorder_id,stag,ctag LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderCtag($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getLast($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT PreorderCtag.* FROM PreorderCtag
|
||||
WHERE $where
|
||||
ORDER BY preorder_id DESC,stag DESC,ctag DESC LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderCtag($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM PreorderCtag
|
||||
WHERE $where";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "preorder_id,stag,ctag ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT PreorderCtag.* FROM PreorderCtag
|
||||
LEFT JOIN Preorder ON Preorder.id = PreorderCtag.preorder_id
|
||||
WHERE $where
|
||||
ORDER BY $order";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new PreorderCtag($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("stag", $filter)) {
|
||||
$stag = $filter['stag'];
|
||||
if(is_numeric($stag)) {
|
||||
$where .= " AND PreorderCtag.stag=$stag";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ctag", $filter)) {
|
||||
$ctag = $filter['ctag'];
|
||||
if(is_numeric($ctag)) {
|
||||
$where .= " AND PreorderCtag.ctag=$ctag";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
if($oaid) {
|
||||
$where .= " AND PreorderCtag.oaid = '$oaid'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
40
db/migrations/20250722143248_create_preorder_ctag.php
Normal file
40
db/migrations/20250722143248_create_preorder_ctag.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePreorderCtag extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("PreorderCtag");
|
||||
$table->addColumn("preorder_id", "integer", ["null" => false]);
|
||||
$table->addColumn("network", "string", ["null" => false, "length" => 64]);
|
||||
$table->addColumn("stag", "integer", ["null" => false]);
|
||||
$table->addColumn("ctag", "integer", ["null" => false]);
|
||||
$table->addColumn("service_type", "enum", ["null" => true, "default" => null, "values" => ["inet", "voice", "iptv", "prio", "mgmt"]]);
|
||||
$table->addColumn("deleted", "integer", ["null" => true, "default" => null]);
|
||||
$table->addColumn("create_by", "integer", ["null" => false]);
|
||||
$table->addColumn("edit_by", "integer", ["null" => false]);
|
||||
$table->addColumn("create", "integer", ["null" => false]);
|
||||
$table->addColumn("edit", "integer", ["null" => false]);
|
||||
$table->create();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("PreorderCtag")->drop()->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
42
db/migrations/20250729120645_create_preorder_citycom_oan.php
Normal file
42
db/migrations/20250729120645_create_preorder_citycom_oan.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePreorderCitycomOan extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("PreorderCitycomOan");
|
||||
$table->addColumn("preorder_id", "integer", ["null" => false]);
|
||||
$table->addColumn("ont_id", "string", ["null" => true]);
|
||||
$table->addColumn("ont_sn", "string", ["null" => true]);
|
||||
$table->addColumn("ont_gpid", "string", ["null" => true]);
|
||||
$table->addColumn("ont_mac", "string", ["null" => true]);
|
||||
|
||||
$table->addColumn("create_by", "integer", ["null" => false]);
|
||||
$table->addColumn("edit_by", "integer", ["null" => false]);
|
||||
$table->addColumn("create", "integer", ["null" => false]);
|
||||
$table->addColumn("edit", "integer", ["null" => false]);
|
||||
|
||||
$table->create();
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("PreorderCitycomOan")->drop()->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
echo "$url\n";
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
|
||||
@@ -107,7 +106,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_PRODUCT;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -136,7 +134,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_PRODUCT);
|
||||
echo $url;
|
||||
|
||||
}
|
||||
|
||||
@@ -149,7 +146,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{product_id}", $product_id, $this->baseurl.CITYCOM_OAN_API_EP_DELETE_PRODUCT);
|
||||
echo "$url\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -163,7 +159,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -181,7 +176,7 @@ class Citycom_OanApiClient {
|
||||
|
||||
}
|
||||
|
||||
public function createService($home_id, $data) {
|
||||
public function createService($data) {
|
||||
if(!$this->token) {
|
||||
$this->getAuthToken();
|
||||
if(!$this->token) {
|
||||
@@ -189,8 +184,11 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
if(!array_key_exists("billing_date", $data) || !$data["billing_date"]) {
|
||||
$data["billing_date"] = date("Y-m-d");
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
@@ -217,7 +215,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_UPDATE_SERVICES);
|
||||
echo $url;
|
||||
|
||||
}
|
||||
|
||||
@@ -230,7 +227,6 @@ class Citycom_OanApiClient {
|
||||
}
|
||||
|
||||
$url = str_replace("{service_id}", $service_id, $this->baseurl.CITYCOM_OAN_API_EP_CANCEL_SERVICES);
|
||||
echo "$url\n";
|
||||
|
||||
}
|
||||
|
||||
@@ -264,8 +260,6 @@ class Citycom_OanApiClient {
|
||||
|
||||
$types = $resp->data;
|
||||
|
||||
var_dump($types);exit;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ class Citycom_OanApiHelper {
|
||||
|
||||
public function __construct(Citycom_OanApiClient $apiClient) {
|
||||
$this->api = $apiClient;
|
||||
$this->log = mfLoghandler::singleton();
|
||||
}
|
||||
|
||||
public function findOrCreateProduct($specs = []) {
|
||||
@@ -54,6 +55,22 @@ class Citycom_OanApiHelper {
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates services in Citycom API
|
||||
*
|
||||
* $data = [
|
||||
* "up" = 300,
|
||||
* "down" = 300,
|
||||
* "execution_date" = [Y-m-d | false],
|
||||
* "services" = CITYCOM_OAN_API_SERVICES_FOR_ORDER,
|
||||
* "product_name" = "thetool-test OAN 300/300"
|
||||
* ]
|
||||
*
|
||||
* @param $preorder Preorder
|
||||
* @param $sublocation_id integer
|
||||
* @param $data Array
|
||||
* @return boolean
|
||||
*/
|
||||
public function orderServices($preorder, $sublocation_id, $data) {
|
||||
if(!is_numeric($sublocation_id) || !$sublocation_id) {
|
||||
return false;
|
||||
@@ -63,7 +80,7 @@ class Citycom_OanApiHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!array_key_exists("services", $data) || is_array($data["services"]) || !count($data["services"])) {
|
||||
if(!array_key_exists("services", $data) || !is_array($data["services"]) || !count($data["services"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -71,7 +88,7 @@ class Citycom_OanApiHelper {
|
||||
$down = $data["down"];
|
||||
$product_name = $data["product_name"];
|
||||
$execution_date = $data["execution_date"];
|
||||
$services = $data["services"];
|
||||
$want_services = $data["services"];
|
||||
|
||||
if(!$execution_date) {
|
||||
$execution_date = date("Y-m-d");
|
||||
@@ -79,33 +96,98 @@ class Citycom_OanApiHelper {
|
||||
|
||||
|
||||
$product_data = [
|
||||
"bb_up" => $up,
|
||||
"bb_down" => $down,
|
||||
"up" => $up,
|
||||
"down" => $down,
|
||||
"name" => $product_name
|
||||
];
|
||||
|
||||
// find or craete product
|
||||
$product_id = $this->findOrCreateProduct($product_data);
|
||||
if(!$product_id) {
|
||||
$this->log->debug(__METHOD__.": no citycom product for query ".print_r($product_data, true));
|
||||
$this->log->error(__METHOD__.": no citycom product found for ".print_r($product_data, true));
|
||||
return false;
|
||||
}
|
||||
|
||||
// order all services and save ctags
|
||||
$cc_service_types = $this->api->getServices();
|
||||
$cc_service_types = $this->api->getServiceTypes();
|
||||
|
||||
$new_services = [];
|
||||
|
||||
$ctags = $preorder->getNextFreeCtags();
|
||||
|
||||
if(!$ctags) {
|
||||
$this->log->error(__METHOD__.": No New Free Ctags (Preorder ".$preorder->id.")");
|
||||
}
|
||||
|
||||
if(count($ctags) < count($want_services)) {
|
||||
$this->log->error(__METHOD__.": Not enough New Free CTags for Preorder ".$preorder->id);
|
||||
}
|
||||
|
||||
$preorder_ctag_data = [
|
||||
"preorder_id" => $preorder->id,
|
||||
"network" => "citycom-oan-api",
|
||||
"stag" => $preorder->adb_hausnummer->vlan_stag,
|
||||
];
|
||||
|
||||
$service_count = 0;
|
||||
foreach($cc_service_types as $stype) {
|
||||
// was this service type requested
|
||||
if(!in_array($stype->name, $want_services)) continue;
|
||||
|
||||
$ctag = $ctags[$service_count];
|
||||
$ctag_service_type = array_flip(CITYCOM_OAN_API_SERVICES_FOR_ORDER)[$stype->name];
|
||||
if(!$ctag_service_type) {
|
||||
$this->log->error(__METHOD__.": Cannot create Service ".$stype->name." for preorder ".$preorder->id." because no ctag service type defined");
|
||||
}
|
||||
|
||||
$service_data = [
|
||||
"sublocation" => $sublocation_id,
|
||||
"service_type" => $stype->id,
|
||||
"product" => $product_id,
|
||||
"billing_date" => $execution_date,
|
||||
"ctag"
|
||||
"ctag" => $ctag,
|
||||
];
|
||||
$new_service = $this->api->createService($sublocation_id, $service_data);
|
||||
|
||||
$this->log->info(__METHOD__.": Creating Service ".$stype->name." on sublocation $sublocation_id with product_id $product_id and ctag $ctag");
|
||||
//continue;
|
||||
|
||||
// register new Service with Citycom
|
||||
/*$new_service = $this->api->createService($service_data);
|
||||
if(!$new_service) {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
$service_return = [
|
||||
"ont" => [
|
||||
"serial" => "ONT123456",
|
||||
"fsan" => "FSAN7890",
|
||||
],
|
||||
];
|
||||
|
||||
// save ctag
|
||||
$ctag_data = $preorder_ctag_data;
|
||||
$ctag_data["ctag"] = $ctag;
|
||||
$ctag_data["service_type"] = $ctag_service_type;
|
||||
$pct = PreorderCtag::create($ctag_data);
|
||||
|
||||
$service_count++;
|
||||
|
||||
if(!$pct->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving PreorderCtag (Preorder ".$preorder->id.")");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$pct->configureNetwork();
|
||||
} catch(Exception $e) {
|
||||
$this->log->error(__METHOD__.": Error configuring network equipment (Preorder ".$preorder->id.")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class mfRouteros {
|
||||
private $password;
|
||||
private $ros = false;
|
||||
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = true) {
|
||||
public function __construct($hostname, $username, $password, $port = 8729, $use_ssl = "auto") {
|
||||
$this->hostname = $hostname;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
@@ -25,7 +25,9 @@ class mfRouteros {
|
||||
|
||||
private function _connect() {
|
||||
$crypto = NetworkStream::CRYPTO_OFF;
|
||||
if($this->use_ssl) {
|
||||
if($this->use_ssl === true) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
} elseif($this->use_ssl == "auto" && $this->port == 8729) {
|
||||
$crypto = NetworkStream::CRYPTO_TLS;
|
||||
}
|
||||
|
||||
@@ -104,6 +106,60 @@ class mfRouteros {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function add($table, $set = []) {
|
||||
if(!$this->ros) $this->_connect();
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
$req = new RouterOS\Request("$table add");
|
||||
|
||||
if(count($set)) {
|
||||
foreach($set as $name => $value) {
|
||||
$req->setArgument($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$resp = $this->ros->sendSync($req);
|
||||
|
||||
if($resp->getType() !== RouterOS\Response::TYPE_FINAL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function remove($table, $filter = []) {
|
||||
if(!$filter) {
|
||||
// no filter would remove every entry in table -> disallowed
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->ros) $this->_connect();
|
||||
$util = new RouterOS\Util($this->ros);
|
||||
|
||||
if(substr($table, 0, 1) != '/') {
|
||||
$table = "/".$table;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query = false;
|
||||
if(count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
if(!$query) {
|
||||
$query = RouterOS\Query::where($name, $value);
|
||||
} else {
|
||||
$query->andWhere($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$util->setMenu($table);
|
||||
$util->remove($query);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* accessors */
|
||||
public function hostname($hostname=false) {
|
||||
|
||||
@@ -196,6 +196,41 @@ class CitycomImporter {
|
||||
|
||||
}
|
||||
|
||||
// get Services to save ONT data
|
||||
$services = $ccapi->getServices();
|
||||
foreach($services as $service) {
|
||||
|
||||
if(!property_exists($service, "ont") || !$service->ont || !$service->ont->id) continue;
|
||||
|
||||
if(!property_exists($service, "location") || !$service->location || !$service->location->id) continue;
|
||||
if(!property_exists($service->location, "sublocation") || !$service->location->sublocation || !$service->location->sublocation->id) continue;
|
||||
//var_dump($service);
|
||||
|
||||
$extref = $this->citycomIdToHausnummerExtref($service->location->sublocation->id);
|
||||
$unit = \ADBWohneinheitModel::getFirst(["extref" => $extref]);
|
||||
if(!$unit) continue;
|
||||
|
||||
$preorder = \PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id]);
|
||||
if(!$preorder) continue;
|
||||
|
||||
$pco = \PreorderCitycomOan::getFirst(["preorder_id" => $preorder->id]);
|
||||
if(!$pco) {
|
||||
$pco = \PreorderCitycomOan::create([
|
||||
"preorder_id" => $preorder->id
|
||||
]);
|
||||
}
|
||||
|
||||
$ont_sn = $service->ont->serial;
|
||||
$ont_gpid = $service->ont->fsan;
|
||||
|
||||
if($pco->ont_sn != $ont_sn || $pco->ont_gpid != $ont_gpid) {
|
||||
$pco->ont_sn = $ont_sn;
|
||||
$pco->ont_gpid = $ont_gpid;
|
||||
$pco->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user