diff --git a/application/OpenAccessId/OpenAccessId.php b/application/OpenAccessId/OpenAccessId.php index 5d00553d0..68c24745b 100644 --- a/application/OpenAccessId/OpenAccessId.php +++ b/application/OpenAccessId/OpenAccessId.php @@ -115,54 +115,60 @@ class OpenAccessId extends mfBaseModel { */ $existing_rimo_export_data = $this->getExportData("rimo"); - if(!is_object($existing_rimo_export_data) || (!isset($existing_rimo_export_data->oaid_id) || !$existing_rimo_export_data->oaid_id) || (!isset($existing_rimo_export_data->name) || !$existing_rimo_export_data->name)) { + //if(!is_object($existing_rimo_export_data) || (!isset($existing_rimo_export_data->oaid_id) || !$existing_rimo_export_data->oaid_id) || (!isset($existing_rimo_export_data->name) || !$existing_rimo_export_data->name)) { + + $oaid_data = $rimo->getOaid(); + // try to create, if it fails, it already exists + if(!$oaid_data) { $this->createInRimo(); - } else { - $this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already created in RIMO"); + } + + //$this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already created in RIMO"); + + /************************************************************************* + * get OAID from rimo and check if it's the same FTU as our Wohneinheit + */ + + $ftu_data = $wohneinheit->ftu_data; + if($ftu_data['id'] && $ftu_data['name']) { - /************************************************************************* - * get OAID from rimo and check if it's the same FTU as our Wohneinheit - */ + $resp_data = $rimo->getOaid(); - $ftu_data = $wohneinheit->ftu_data; - if($ftu_data['id'] && $ftu_data['name']) { - + if(!$resp_data) { + // oaid was not found in rimo, try creating it + $this->createInRimo(); $resp_data = $rimo->getOaid(); - - if(!$resp_data) { - // oaid was not found in rimo, try creating it - $resp_data = $this->createInRimo(); - } - - $assign_oaid = false; - - if($resp_data && $resp_data->terminiationUnit && $resp_data->terminiationUnit->id) { - if($ftu_data['id'] != $resp_data->terminiationUnit->id) { - $old_ftu_id = $resp_data->terminiationUnit->id; - - // unassign oaid from FTU - $resp_data = $rimo->unassignOaid($old_ftu_id); - $assign_oaid = true; - - } - } else { - $assign_oaid = true; - } - - if ($assign_oaid) { - // assign oaid to Wohneinheit FTU - $resp_data = $rimo->assignOaid($ftu_data['id']); + } + + $assign_oaid = false; + + if($resp_data && $resp_data->terminiationUnit && $resp_data->terminiationUnit->id) { + if($ftu_data['id'] != $resp_data->terminiationUnit->id) { + $old_ftu_id = $resp_data->terminiationUnit->id; + + // unassign oaid from FTU + $resp_data = $rimo->unassignOaid($old_ftu_id); + $assign_oaid = true; - // update OAID export data - $exp_data_update = json_decode($this->export_data); - $exp_data_update->rimo->ftu_id = $ftu_data['id']; - $exp_data_update->rimo->ftu_name = $ftu_data['name']; - $exp_data_update->rimo->ftu_assigned_date = date("U"); - $this->export_data = json_encode($exp_data_update); - $this->save(); } + } else { + $assign_oaid = true; + } + + if ($assign_oaid) { + // assign oaid to Wohneinheit FTU + $resp_data = $rimo->assignOaid($ftu_data['id']); + + // update OAID export data + $exp_data_update = json_decode($this->export_data); + $exp_data_update->rimo->ftu_id = $ftu_data['id']; + $exp_data_update->rimo->ftu_name = $ftu_data['name']; + $exp_data_update->rimo->ftu_assigned_date = date("U"); + $this->export_data = json_encode($exp_data_update); + $this->save(); } } + //} @@ -172,39 +178,10 @@ class OpenAccessId extends mfBaseModel { * assign OAID to FTU - POST /v1/oaid-management/oaids/{oaidName}/ftu/{ftuExternalId} */ + /* // check if we assigned the OAID to a RIMO FTU already $existing_rimo_export_data = $this->getExportData("rimo"); if(!is_object($existing_rimo_export_data) || !isset($existing_rimo_export_data->oaid_id) || !isset($existing_rimo_export_data->ftu_id)) { - /* - $params = []; - $params['apiKey'] = RIMO_API_JSON_APIKEY; - - $ctx_opts = [ - 'http' => [ - 'method' => 'POST', - 'header' => 'accept: application/json' - ] - ]; - - $qs = http_build_query($params); - //echo $qs."\n"; - - $createOrderEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_ASSIGN_OAID_TO_FTU; - $createOrderEp = str_replace("{oaidName}", $this->oaid, $createOrderEp); - $createOrderEp = str_replace("{ftuExternalId}", $unit_extdata->rimo->ftu->id, $createOrderEp); - $post_url = $createOrderEp."?".$qs; - - $ctx = stream_context_create($ctx_opts); - $this->log->debug(__METHOD__.": Assigning OAID to FTU in Rimo: $post_url"); - - $response = file_get_contents($post_url, false, $ctx); - - if($response === false) { - $this->log->error("Fehler beim Zuweisen der OAID '".$this->oaid."' zu RIMO FTU '".$unit_extdata->rimo->ftu->id."'\n"); - $workorders_failed++; - return false; - } - */ $resp_data = $rimo->assignOaid($unit_extdata->rimo->ftu->id); // add FTU id to external_data @@ -227,7 +204,7 @@ class OpenAccessId extends mfBaseModel { } else { $this->log->debug(__METHOD__.": OAID ".$this->oaid.": Already assigned to FTU in Rimo"); } - + */ return true; } diff --git a/application/OpenAccessId/helper/rimo.php b/application/OpenAccessId/helper/rimo.php index c506d91ca..65cd69ead 100644 --- a/application/OpenAccessId/helper/rimo.php +++ b/application/OpenAccessId/helper/rimo.php @@ -32,7 +32,7 @@ class OpenAccessId_Helper_Rimo { $response = file_get_contents($get_url, false, $ctx); if($response === false) { - $this->log->error("Fehler beim auslesen der FTU ".$this->oaid."\n"); + $this->log->error("Fehler beim auslesen der FTU ".$this->oaid); return false; } @@ -67,7 +67,7 @@ class OpenAccessId_Helper_Rimo { $response = file_get_contents($get_url, false, $ctx); //var_dump($response);exit; if($response === false) { - $this->log->error("Fehler beim abfragen der OAID in RIMO ".$this->oaid."\n"); + $this->log->error("Fehler beim abfragen der OAID in RIMO ".$this->oaid); return false; } @@ -102,7 +102,7 @@ class OpenAccessId_Helper_Rimo { $response = file_get_contents($post_url, false, $ctx); //var_dump($response);exit; if($response === false) { - $this->log->error("Fehler beim Erstellen der OAID in RIMO ".$this->oaid."\n"); + $this->log->error("Fehler beim Erstellen der OAID in RIMO ".$this->oaid); return false; } @@ -138,7 +138,7 @@ class OpenAccessId_Helper_Rimo { $response = file_get_contents($delete_url, false, $ctx); if($response === false) { - $this->log->error("Fehler beim Unassignen der OAID in RIMO ".$this->oaid.": $delete_url\n"); + $this->log->error("Fehler beim Unassignen der OAID in RIMO ".$this->oaid.": $delete_url"); return false; } @@ -169,7 +169,7 @@ class OpenAccessId_Helper_Rimo { $response = file_get_contents($post_url, false, $ctx); if($response === false) { - $this->log->error("Fehler beim Assignen der OAID ".$this->oaid." in RIMO ".$this->oaid."\n"); + $this->log->error("Fehler beim Assignen der OAID ".$this->oaid." in RIMO ".$this->oaid); return false; } diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php index 7d6d9346b..ad4cd6840 100644 --- a/application/Preordercampaign/PreordercampaignController.php +++ b/application/Preordercampaign/PreordercampaignController.php @@ -529,7 +529,7 @@ class PreordercampaignController extends mfBaseController { $assigned_oaids = 0; $multiple_unit = 0; - foreach(PreorderModel::search(["preordercampaign_id" => $id, "oaid" => null, 'deleted' => 0]) as $preorder) { + foreach(PreorderModel::search(["preordercampaign_id" => $id, "oaid" => null, "connection_count" => 1, 'deleted' => 0]) as $preorder) { if($preorder->type == "interest") { continue; } @@ -608,7 +608,7 @@ class PreordercampaignController extends mfBaseController { $workorders_created = 0; $workorders_failed = 0; - foreach(PreorderModel::search(["preordercampaign_id" => $id, "rimo_workorder" => false, 'deleted' => 0]) as $preorder) { + foreach(PreorderModel::search(["preordercampaign_id" => $id, "rimo_workorder" => false, "connection_count" => 1, 'deleted' => 0]) as $preorder) { if($preorder->workorder_export_date) { $this->log->warning(__METHOD__.": workorder_export_date not null"); } @@ -754,7 +754,7 @@ class PreordercampaignController extends mfBaseController { $missing_extrefs = 0; $missing_oaid = 0; - foreach(PreorderModel::search(["preordercampaign_id" => $id, 'deleted' => 0]) as $preorder) { + foreach(PreorderModel::search(["preordercampaign_id" => $id, "connection_count" => 1, 'deleted' => 0]) as $preorder) { if($preorder->type == "interest") { $this->log->debug(__METHOD__.": Ignoring Preorder ".$preorder->id.": is interest"); continue; diff --git a/scripts/fibu-check/files/.~lock.Kontaktliste.csv# b/scripts/fibu-check/files/.~lock.Kontaktliste.csv# deleted file mode 100644 index ff8d884ed..000000000 --- a/scripts/fibu-check/files/.~lock.Kontaktliste.csv# +++ /dev/null @@ -1 +0,0 @@ -,fronk,fronk-nb,23.01.2024 21:03,file:///home/fronk/.config/libreoffice/4; \ No newline at end of file