119 lines
3.1 KiB
PHP
Executable File
119 lines
3.1 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_ids = [];
|
|
$campaign_ids["premnord"] = 5;
|
|
$campaign_ids["premsued"] = 6;
|
|
$campaign_ids["gsf"] = 7;
|
|
$campaign_ids["kalwang"] = 41;
|
|
$campaign_ids["st_stefan_stainz"] = 36;
|
|
$campaign_ids["wettmannst"] = 37;
|
|
$campaign_ids["mureck"] = 42;
|
|
|
|
if(!array_key_exists(1,$argv)) {
|
|
|
|
echo "Bitte eines der folgenden Netzgebiete angeben:\n\n";
|
|
echo implode("\n", array_keys($campaign_ids));
|
|
echo "\n\n";
|
|
exit(1);
|
|
}
|
|
|
|
if(!array_key_exists($argv[1], $campaign_ids)) {
|
|
die("Ungültige Kampagne\n");
|
|
}
|
|
|
|
$selected_campaign = $campaign_ids[$argv[1]];
|
|
|
|
if(!$selected_campaign) {
|
|
echo "Keine Kampagne ausgewählt.\n";
|
|
exit;
|
|
}
|
|
|
|
echo "selected campaign: $selected_campaign - ".$argv[1]."\n";
|
|
|
|
$same_unit_count = 0;
|
|
|
|
$i = 0;
|
|
foreach(PreorderModel::searchActive(['preordercampaign_id' => $selected_campaign, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling"]) 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) {
|
|
// legacy comment: assume its single-dwelling with erroneously high door count
|
|
// current comment: Just use any unit
|
|
$unit_candidates = [];
|
|
|
|
foreach($wohneinheiten as $unit) {
|
|
if(!$unit->tuer) continue;
|
|
if($unit->tuer > 1) {
|
|
$unit_candidates[$unit->tuer] = $unit;
|
|
}
|
|
}
|
|
|
|
// no candidates with door number -> use any
|
|
|
|
if(!count($unit_candidates)) {
|
|
foreach($wohneinheiten as $unit) {
|
|
$unit_candidates[] = $unit;
|
|
}
|
|
}
|
|
|
|
if(count($unit_candidates)) {
|
|
ksort($unit_candidates, SORT_NUMERIC);
|
|
$new_unit = array_shift($unit_candidates);
|
|
$preorder->adb_wohneinheit_id = $new_unit->id;
|
|
//var_dump($preorder, $new_unit);exit;
|
|
$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";
|