89 lines
2.5 KiB
PHP
Executable File
89 lines
2.5 KiB
PHP
Executable File
#!/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);
|
|
|
|
$ignore_preorders = [];
|
|
|
|
$campaign_prem_nord = 5;
|
|
$same_unit_count = 0;
|
|
|
|
$i = 0;
|
|
foreach(PreorderModel::search(['preordercampaign_id' => $campaign_prem_nord, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling", "deleted" => 0]) as $preorder) {
|
|
if(in_array($preorder->id, $ignore_preorders)) continue;
|
|
//if($preorder->connection_type != "single-dwelling") continue;
|
|
|
|
if($preorder->adb_wohneinheit_id) {
|
|
echo "hat eh a unit\n";
|
|
continue;
|
|
}
|
|
if(!$preorder->adb_hausnummer_id) {
|
|
echo "missing hausnummer Preorder ".$preorder->id."\n";
|
|
continue;
|
|
}
|
|
|
|
$wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $preorder->adb_hausnummer_id]);
|
|
if(!count($wohneinheiten)) {
|
|
echo "Keine Wohneinheit gefunden. Preorder ".$preorder->id."\n";
|
|
}
|
|
$unit_count = count($wohneinheiten);
|
|
//echo "$unit_count\n";
|
|
if($unit_count === 1) {
|
|
$same_unit_count++;
|
|
$unit = $wohneinheiten[0];
|
|
$preorder->adb_wohneinheit_id = $unit->id;
|
|
$preorder->save();
|
|
continue;
|
|
}
|
|
|
|
|
|
if($unit_count > 1 && $unit_count <= 4) {
|
|
// assume its single-dwelling with erroneously high door count
|
|
$unit_candidates = [];
|
|
|
|
foreach($wohneinheiten as $unit) {
|
|
if(!$unit->tuer) continue;
|
|
if($unit->tuer > 1) {
|
|
$unit_candidates[$unit->tuer] = $unit;
|
|
}
|
|
}
|
|
|
|
/*if(!count($unit_candidates)) {
|
|
foreach($wohneinheiten as $unit) {
|
|
if(!$unit->zusatz) continue;
|
|
if(preg_match('/Top\s+\d+/i',$unit->zusatz)) {
|
|
$unit_candidates[$unit->zusatz] = $unit;
|
|
}
|
|
}
|
|
}*/
|
|
|
|
if(count($unit_candidates)) {
|
|
ksort($unit_candidates, SORT_NUMERIC);
|
|
$new_unit = array_shift($unit_candidates);
|
|
$preorder->adb_wohneinheit_id = $new_unit->id;
|
|
$preorder->save();
|
|
|
|
echo "$i Wohneinheit saved\n";
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$i++;
|
|
}
|
|
|
|
|
|
echo "Same unit count: $same_unit_count (".$i - $same_unit_count." with different unit count)\n";
|
|
echo "Processed $i Preorders\n";
|