86 lines
3.0 KiB
PHP
86 lines
3.0 KiB
PHP
#!/usr/bin/php
|
|
<?php
|
|
|
|
//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);
|
|
|
|
|
|
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
|
|
|
$sql = "SELECT Hausnummer.* FROM Hausnummer
|
|
LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id)
|
|
WHERE Netzgebiet.name NOT LIKE 'SBIDI%' AND Netzgebiet.name NOT LIKE 'Liezen%'
|
|
AND Hausnummer.visibility = 'private'";
|
|
|
|
$res = $db->query($sql);
|
|
while($hausnummer_data = $db->fetch_object($res)) {
|
|
$hausnummer = new ADBHausnummer($hausnummer_data->id);
|
|
$unit_count = count($hausnummer->wohneinheiten);
|
|
|
|
$can_delete_address = true;
|
|
$units_to_delete = [];
|
|
foreach($hausnummer->wohneinheiten as $unit) {
|
|
if(count($unit->active_preorders)) {
|
|
$can_delete_address = false;
|
|
continue;
|
|
}
|
|
$units_to_delete[] = $unit;
|
|
}
|
|
|
|
if(count($units_to_delete) != $unit_count) {
|
|
echo "!! Hausnummer ".$hausnummer->id.": cannot delete ".($unit_count - count($units_to_delete))." of $unit_count units\n";
|
|
}
|
|
|
|
foreach($units_to_delete as $del_unit) {
|
|
if(PreorderModel::getFirstActive(["adb_wohneinheit_id" => $del_unit->id])) {
|
|
// this shouldn't happen
|
|
echo "!! Hausnummer ".$hausnummer->id.": cannot delete unit ".$del_unit->id." because of active preorders\n";
|
|
$can_delete_address = false;
|
|
continue;
|
|
}
|
|
|
|
if($del_unit->oaid) {
|
|
$oaid = OpenAccessIdModel::getFirstOaid($del_unit->oaid);
|
|
if($oaid && $oaid->origin == "ofaa") {
|
|
if(ADBWohneinheitModel::count(["oaid" => $del_unit->oaid]) == 1) {
|
|
//echo "!! Hausnummer ".$hausnummer->id.": cannot delete unit ".$del_unit->id." because it's the last Unit with OAID ".$oaid->oaid."\n";
|
|
$ftu_id = $del_unit->ftu_data["id"];
|
|
//RimoApi::unassignOaid($oaid->oaid, $ftu_id);
|
|
|
|
echo "Deleting OAID ".$oaid->oaid." from FTU ".$ftu_id."\n";
|
|
|
|
|
|
$oaid->assigned = 0;
|
|
$oaid->adb_wohneinheit_id = null;
|
|
$oaid->exported = 0;
|
|
$oaid->exported_to = null;
|
|
$oaid->exported_data = null;
|
|
$oaid->address = null;
|
|
$oaid->unit_string = null;
|
|
$oaid->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Deleting unit ".$del_unit->id." from Hausnummer ".$hausnummer->id."\n";
|
|
$del_unit->delete();
|
|
|
|
}
|
|
|
|
if($can_delete_address) {
|
|
echo "Deleting Hausnummer ".$hausnummer->id."\n";
|
|
$hausnummer->delete();
|
|
}
|
|
} |