Merge branch 'fronkdev' into 'master'
RimoImport: Added option to delete Wohneinheiten not existant in Rimo See merge request fronk/thetool!1350
This commit is contained in:
@@ -43,7 +43,18 @@ class ADBHausnummer extends mfBaseModel {
|
||||
AddressDB::handleRimoStatusUpdate($wohneinheit->id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function refreshUnitCount() {
|
||||
if(!$this->id) return true;
|
||||
|
||||
$unit = ADBWohneinheitModel::getFirst(["hausnummer_id" => $this->id]);
|
||||
if($unit) {
|
||||
$unit->refreshUnitCount();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resetSaveNesting() {
|
||||
|
||||
@@ -198,6 +198,7 @@ foreach ($clusters as $cluster_data) {
|
||||
$option_create_preorder = $adb_netzgebiet->getOption("create_preorder");
|
||||
$preorder_only_oaid = $adb_netzgebiet->getOption("preorder_only_oaid");
|
||||
$option_wo_ignore_status = $adb_netzgebiet->getOption("wo_ignore_status");
|
||||
$option_delete_units = $adb_netzgebiet->getOption("delete_units");
|
||||
|
||||
$AddressHelper = new ADBAddressHelper\AddressHelper(["log" => $log, "db" => $adb, "netzgebiet" => $adb_netzgebiet]);
|
||||
|
||||
@@ -229,7 +230,6 @@ foreach ($clusters as $cluster_data) {
|
||||
foreach ($buildingsResponse->item as $building) {
|
||||
$hausnummer_count++;
|
||||
|
||||
|
||||
$rimo_building_id = $building->id;
|
||||
$hausnummer = $AddressHelper->findUpdateAddressFromRimoBuilding($building);
|
||||
if (!$hausnummer) {
|
||||
@@ -331,6 +331,8 @@ foreach ($clusters as $cluster_data) {
|
||||
|
||||
$rimo_home_count = count($building->homes->item);
|
||||
|
||||
$rimo_home_list = [];
|
||||
|
||||
foreach ($building->homes->item as $home) {
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
//print_r($home);exit;
|
||||
@@ -338,6 +340,8 @@ foreach ($clusters as $cluster_data) {
|
||||
$home_rimo_id = $home->id;
|
||||
$home_name = $home->name;
|
||||
|
||||
$rimo_home_list[] = $home_rimo_id;
|
||||
|
||||
//echo "$home_rimo_id\n";continue;
|
||||
|
||||
if (array_key_exists($home_rimo_id, $existing_units_extref)) {
|
||||
@@ -566,8 +570,38 @@ foreach ($clusters as $cluster_data) {
|
||||
|
||||
|
||||
}
|
||||
//continue;
|
||||
|
||||
if($option_delete_units) {
|
||||
// delete Homes not existing in Rimo
|
||||
foreach (\ADBWohneinheitModel::search(["hausnummer_id" => $hausnummer->id]) as $adb_unit) {
|
||||
$adb_unit->rimo_deleted = 1;
|
||||
if(!$adb_unit->extref) {
|
||||
$adb_unit->save(["no_updates" => 1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!in_array($adb_unit->extref, $rimo_home_list)) {
|
||||
if(count($adb_unit->active_preorders)) {
|
||||
$adb_unit->save(["no_updates" => 1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($adb_unit->oaid) {
|
||||
$oaid = \OpenAccessIdModel::getFirstOaid($adb_unit->oaid);
|
||||
$oaid_units_count = \ADBWohneinheitModel::count(["oaid" => $adb_unit->oaid]);
|
||||
if($oaid && $oaid->origin == "ofaa" && $oaid_units_count === 1) {
|
||||
// last unit with this OAID
|
||||
$adb_unit->save(["no_updates" => 1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
echo "[DD] Deleting Hausnummer ".$adb_unit->hausnummer_id." Wohneinheit ".$adb_unit->id."\n";
|
||||
$adb_unit->delete();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Geodata
|
||||
|
||||
Reference in New Issue
Block a user