From 73cf1098a517e2c9b1f8fc5b758eb2dc1268239a Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 20 Aug 2025 16:28:12 +0200 Subject: [PATCH] Fixed not setting flag 141 in rimo-import --- .../Preorder/include/preorder-detail.php | 4 +- application/ADBHausnummer/ADBHausnummer.php | 23 +++- .../ADBHausnummerStatusflagValue.php | 9 +- application/ADBWohneinheit/ADBWohneinheit.php | 11 +- .../ADBWohneinheitStatusflagValue.php | 9 +- application/AddressDB/AddressDB.php | 19 ++- application/Preorder/Preorder.php | 130 ++++++++++-------- lib/mvcfronk/mfBase/mfBaseModel.php | 3 + 8 files changed, 128 insertions(+), 80 deletions(-) diff --git a/Layout/default/Preorder/include/preorder-detail.php b/Layout/default/Preorder/include/preorder-detail.php index 7c91bfaf2..aaed3a381 100644 --- a/Layout/default/Preorder/include/preorder-detail.php +++ b/Layout/default/Preorder/include/preorder-detail.php @@ -672,10 +672,10 @@

ONT

- + - +
SNS/N citycomoan) ? $preorder->citycomoan->ont_sn : ""?>
FSANFSAN citycomoan) ? $preorder->citycomoan->ont_gpid : ""?>
diff --git a/application/ADBHausnummer/ADBHausnummer.php b/application/ADBHausnummer/ADBHausnummer.php index e6bf90aa0..9edb75609 100644 --- a/application/ADBHausnummer/ADBHausnummer.php +++ b/application/ADBHausnummer/ADBHausnummer.php @@ -11,6 +11,8 @@ class ADBHausnummer extends mfBaseModel { private $freigaben = []; private $wohneinheiten = []; + + protected function init() { $this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); $this->table = "Hausnummer"; @@ -19,7 +21,10 @@ class ADBHausnummer extends mfBaseModel { public function afterSave($_params = []) { if(array_key_exists("no_aftersave", $_params) && $_params["no_aftersave"]) return true; - + + $this->log->debug("[".$this->_ruid."] "."-----------------------------------------"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": hausnummer_id: ".$this->id); + // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("adbhausnummer-save-nesting-level-".$this->id); if(!$nesting_level) { @@ -30,6 +35,7 @@ class ADBHausnummer extends mfBaseModel { mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$this->id, $nesting_level); if($nesting_level > 1) { + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Preventing potential infinite loop"); return true; } @@ -45,6 +51,9 @@ class ADBHausnummer extends mfBaseModel { AddressDB::handleRimoStatusUpdate($wohneinheit->id); } + // reload self from database + $this->fetch($this->id); + return true; } @@ -81,7 +90,7 @@ class ADBHausnummer extends mfBaseModel { $me = new User(); $me->loadMe(); - $this->log->info(__CLASS__." Changes: User ".$me->username." $logstr"); + $this->log->info("[".$this->_ruid."] ".__CLASS__." Changes: User ".$me->username." $logstr"); return true; @@ -106,7 +115,7 @@ class ADBHausnummer extends mfBaseModel { public function setNewStatusCode($new_status_code) { if(!$new_status_code) return false; - $this->log->debug(__METHOD__.": Want new Hausnummer (".$this->id.") Status ".$new_status_code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Want new Hausnummer (".$this->id.") Status ".$new_status_code); $new_status = ADBStatusModel::getFirst(["code" => $new_status_code]); @@ -115,7 +124,7 @@ class ADBHausnummer extends mfBaseModel { $flag = ADBStatusflagModel::getFirst(["code" => $new_status_code]); if(!$flag) return false; - $this->log->debug(__METHOD__.": Statuscode $new_status_code is Flag"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Statuscode $new_status_code is Flag"); $flag_value = ADBHausnummerStatusflagValueModel::getFirst(["flag_id" => $flag->id, "hausnummer_id" => $this->id]); if(!$flag_value) { $flag_value = ADBHausnummerStatusflagValueModel::create([ @@ -130,7 +139,7 @@ class ADBHausnummer extends mfBaseModel { $old_status = $this->getProperty("status"); if($old_status->code < $new_status->code) { - $this->log->debug(__METHOD__.": Setting Hausnummer (".$this->id.") Status from ".$old_status->code." to ".$new_status->code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Setting Hausnummer (".$this->id.") Status from ".$old_status->code." to ".$new_status->code); $this->status_id = $new_status->id; } @@ -145,7 +154,7 @@ class ADBHausnummer extends mfBaseModel { 'street' => $this->getProperty("strasse")->name ]; if(!$search['country'] || !$search['city'] || !$search['zip'] || !$search['street']) { - $this->log->warning(__METHOD__.": Unable to retrieve GPS Coordinates. Search key missing (hausnummer_id: ".$this->id.")"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": Unable to retrieve GPS Coordinates. Search key missing (hausnummer_id: ".$this->id.")"); return false; } @@ -191,7 +200,7 @@ class ADBHausnummer extends mfBaseModel { } if(ADBHausnummerModel::search(['oaid' => $code])) { - $this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times."); + $this->log->warn("[".$this->_ruid."] ".__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times."); } else { // code is unique break; diff --git a/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php index a6a08bf34..66cc8188f 100644 --- a/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php +++ b/application/ADBHausnummerStatusflagValue/ADBHausnummerStatusflagValue.php @@ -9,13 +9,16 @@ class ADBHausnummerStatusflagValue extends mfBaseModel { } protected function afterSave() { + $this->log->debug("[".$this->_ruid."] "."-----------------------------------------"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": statusflagvalue_id: ".$this->id); + if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) { // cascade new status to all preorders foreach(PreorderModel::search(["adb_hausnummer_id" => $this->hausnummer_id]) as $preorder) { // get PreorederStatusflag $pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]); if(!$pflag) { - $this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found"); return true; } @@ -32,9 +35,9 @@ class ADBHausnummerStatusflagValue extends mfBaseModel { } if($new || $pflagval->value != $this->value) { $pflagval->value = $this->value; - //$this->log->debug(__METHOD__.": ".print_r($pflagval, true)); + //$this->log->debug("[".$this->_ruid."] ".__METHOD__.": ".print_r($pflagval, true)); $pflagval->save(); - $this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id); } } } diff --git a/application/ADBWohneinheit/ADBWohneinheit.php b/application/ADBWohneinheit/ADBWohneinheit.php index 4ac9e7e5b..491dde332 100644 --- a/application/ADBWohneinheit/ADBWohneinheit.php +++ b/application/ADBWohneinheit/ADBWohneinheit.php @@ -28,6 +28,9 @@ class ADBWohneinheit extends mfBaseModel { if(array_key_exists("no_aftersave", $_params) && $_params["no_aftersave"]) return true; + $this->log->debug("[".$this->_ruid."] "."-----------------------------------------"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": wohneinheit_id: ".$this->id); + // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("adbwohneinheit-save-nesting-level-".$this->id); if(!$nesting_level) { @@ -38,6 +41,7 @@ class ADBWohneinheit extends mfBaseModel { mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$this->id, $nesting_level); if($nesting_level > 1) { + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Preventing potential infinite loop"); return true; } @@ -48,8 +52,11 @@ class ADBWohneinheit extends mfBaseModel { AddressDB::handleRimoStatusUpdate($this->id); } - $this->refreshUnitCount(); + // reload self from database + $this->fetch($this->id); + + return true; } public function refreshUnitCount() { @@ -138,7 +145,7 @@ class ADBWohneinheit extends mfBaseModel { $me = new User(); $me->loadMe(); - $this->log->info(__CLASS__." Changes: User ".$me->username." $logstr"); + $this->log->info("[".$this->_ruid."] ".__CLASS__." Changes: User ".$me->username." $logstr"); return true; diff --git a/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php index f7c748fc5..d34e7ee98 100644 --- a/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php +++ b/application/ADBWohneinheitStatusflagValue/ADBWohneinheitStatusflagValue.php @@ -9,13 +9,16 @@ class ADBWohneinheitStatusflagValue extends mfBaseModel { } protected function afterSave($_params = []) { + $this->log->debug("[".$this->_ruid."] "."-----------------------------------------"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": statusflagvalue_id: ".$this->id); + if(!property_exists($this->_old_data, "value") || $this->_old_data->value != $this->data->value) { // cascade new status to all preorders foreach(PreorderModel::search(["adb_wohneinheit_id" => $this->wohneinheit_id]) as $preorder) { // get PreorederStatusflag $pflag = PreorderStatusflagModel::getFirst(["code" => $this->getProperty("flag")->code]); if(!$pflag) { - $this->log->debug(__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Preorder statusflag " . $this->getProperty("flag")->code . " not found"); return true; } @@ -32,9 +35,9 @@ class ADBWohneinheitStatusflagValue extends mfBaseModel { } if($new || $pflagval->value != $this->value) { $pflagval->value = $this->value; - //$this->log->debug(__METHOD__.": ".print_r($pflagval, true)); + //$this->log->debug("[".$this->_ruid."] ".__METHOD__.": ".print_r($pflagval, true)); $pflagval->save(); - $this->log->debug(__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": statusflag " . $this->getProperty("flag")->code . " saved for preorder " . $preorder->id); } } } diff --git a/application/AddressDB/AddressDB.php b/application/AddressDB/AddressDB.php index be6535b93..a12e969db 100644 --- a/application/AddressDB/AddressDB.php +++ b/application/AddressDB/AddressDB.php @@ -189,7 +189,6 @@ class AddressDB { $status_matrix = array_reverse(TT_PREORDER_RIMO_STATUS_MATRIX); - $log->debug(__METHOD__.": b_ex_state: ".$b_ex_state); $log->debug(__METHOD__.": b_op_state: ".$b_op_state); $log->debug(__METHOD__.": h_ex_state: ".$h_ex_state); @@ -224,6 +223,10 @@ class AddressDB { // seems all criteria match => set new status $log->debug(__METHOD__.": new Preorder Status: ".$matrix["p"]); + $log->debug(__METHOD__.": new Preorder Status flag: ".$matrix["pf"]); + + $preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]); + $preorder->resetSaveNesting(); if($preorder) { $preorderstatus = null; @@ -234,18 +237,22 @@ class AddressDB { if(array_key_exists("pf", $matrix) && $matrix["pf"]) { $preorderstatus_flag = $matrix["pf"]; } - if($preorderstatus) { $log->debug(__METHOD__.": Setting Preorder Status to ".$preorderstatus); $preorder->setNewStatusCode($preorderstatus); $preorder->save(); + $preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]); $preorder->resetSaveNesting(); } if($preorderstatus_flag) { - $log->debug(__METHOD__.": Setting Preorder Status Flag ".$preorderstatus); - $preorder->setNewStatusCode($preorderstatus); - $preorder->save(); - $preorder->resetSaveNesting(); + $log->debug(__METHOD__.": Setting Preorder Status Flag ".$preorderstatus_flag); + $preorder->setStatusFlag($preorderstatus_flag); + + /* + $sflag = PreorderStatusflagModel::getFirst(["code" => $preorderstatus_flag]); + $sflag->preorder_id = $preorder->id; + $log->debug(__METHOD__." Just set Preorder ".$preorder->id." status flag $preorderstatus_flag to 1. Actual value: ".$sflag->value->value); + */ } } diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index cf9a25116..85daabd01 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -61,6 +61,9 @@ class Preorder extends mfBaseModel { if(array_key_exists("no_aftersave", $_params) && $_params["no_aftersave"]) return true; + $this->log->debug("[".$this->_ruid."] "."-----------------------------------------"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": preorder_id: ".$this->id); + // prevent potential infinite loop $nesting_level = mfValuecache::singleton()->get("preorder-save-nesting-level-" . $this->id); if(!$nesting_level) { @@ -71,7 +74,7 @@ class Preorder extends mfBaseModel { mfValuecache::singleton()->set("preorder-save-nesting-level-" . $this->id, $nesting_level); if($nesting_level > 1) { - $this->log->debug(__METHOD__.": (Preorder ".$this->id.") Nesting level limit reached ($nesting_level) -> aborting"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": (Preorder ".$this->id.") Nesting level limit reached ($nesting_level) -> aborting"); return true; } @@ -162,7 +165,7 @@ class Preorder extends mfBaseModel { try { foreach($changed as $field) { - $this->log->debug(__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": $field changed from '" . $this->_old_data->$field . "' to '" . $this->data->$field . "'"); $history = PreorderHistoryModel::create([ "preorder_id" => $this->id, "key" => $field, @@ -173,7 +176,7 @@ class Preorder extends mfBaseModel { $history->save(); } } catch(Exception $e) { - $this->log->debug($e->getTraceAsString()); + $this->log->debug("[".$this->_ruid."] ".$e->getTraceAsString()); } } @@ -181,7 +184,7 @@ class Preorder extends mfBaseModel { if(!$this->id) return true; if(property_exists($this->_old_data, "status_id") && $this->status_id == $this->_old_data->status_id) return true; - $this->log->debug(__METHOD__ . " running"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . " running"); $new_status = $this->getProperty("status"); if(!property_exists($this->_old_data, "status_id")) { @@ -191,12 +194,12 @@ class Preorder extends mfBaseModel { $old_status = new Preorderstatus($this->_old_data->status_id); if(!$new_status->id || !$old_status->id) return true; - $this->log->debug(__METHOD__ . " status changed from '" . ($old_status ? $old_status->code : "") . "' to '" . $new_status->code . "'"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . " status changed from '" . ($old_status ? $old_status->code : "") . "' to '" . $new_status->code . "'"); if($new_status->code <= $old_status->code) return true; if(!defined("TT_PREORDER_STATUS_MATRIX") || !TT_PREORDER_STATUS_MATRIX) { - $this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!"); + $this->log->error("[".$this->_ruid."] "."config TT_PREORDER_STATUS_MATRIX not defined!"); } $actions = []; @@ -211,7 +214,7 @@ class Preorder extends mfBaseModel { $classname = "Preorder_Statustrigger_$code"; $filepath = __DIR__ . "/statustrigger/$code.php"; - $this->log->debug(__METHOD__ . ": Looking for $classname in $filepath"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Looking for $classname in $filepath"); if(file_exists($filepath)) { require_once $filepath; @@ -234,7 +237,7 @@ class Preorder extends mfBaseModel { } }*/ } else { - $this->log->debug(__METHOD__ . ": $classname not found"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": $classname not found"); } // TODO create email action if status templates configured in Campaign @@ -263,7 +266,7 @@ class Preorder extends mfBaseModel { - $this->log->debug(print_r($actions, true)); + $this->log->debug("[".$this->_ruid."] ".print_r($actions, true)); //var_dump($actions);exit; // run last email action if(array_key_exists("email", $actions) && is_array($actions["email"]) && count($actions["email"])) { @@ -285,23 +288,23 @@ class Preorder extends mfBaseModel { $current_status_mt = PreordercampaignStatusnotificationMailtemplate::getFirst(["preordercampaign_id" => $this->preordercampaign_id, "status_code" => $new_status->code]); if($current_status_mt && $current_status_mt->prevent_previous) { $send_email = false; - $this->log->debug(__METHOD__.": Sending disallowed by current status"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Sending disallowed by current status"); } // check if email action allows sending if skipped over it if(!$email_action["allow_on_skip"]) { $send_email = false; - $this->log->debug(__METHOD__.": Sending disallowed by previous status"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Sending disallowed by previous status"); } } if($send_email) { - $this->log->debug(__METHOD__.": Sending Email Action for Status ".$email_action["status_code"]); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Sending Email Action for Status ".$email_action["status_code"]); $email_to = $this->runTriggerEmailAction($email_action); if($email_to === false) { - $this->log->warning(__METHOD__ . ": Could not send preorder action email (Preorder " . $this->id . ")"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": Could not send preorder action email (Preorder " . $this->id . ")"); } elseif(is_string($email_to)) { // TODO Save history $psn_log = PreorderStatusnotificationLog::create([ @@ -312,7 +315,7 @@ class Preorder extends mfBaseModel { $psn_log->save(); } } else { - $this->log->warning(__METHOD__.": Not sending status (".$email_action["status_code"].") email because disallowed by current status or same or higher status email was sent already (Preorder ".$this->id.")"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": Not sending status (".$email_action["status_code"].") email because disallowed by current status or same or higher status email was sent already (Preorder ".$this->id.")"); } } @@ -337,7 +340,7 @@ class Preorder extends mfBaseModel { } if(!$to) { - $this->log->warning(__METHOD__.": Keine To Adresse (Preorder ".$this->id.")"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": Keine To Adresse (Preorder ".$this->id.")"); return false; } @@ -370,7 +373,7 @@ class Preorder extends mfBaseModel { $mailtemplate = MailtemplateModel::getFirst(["code" => $action["template"]]); if(!$mailtemplate) { - $this->log->warning(__METHOD__.": Mailtemplate nicht gefunden: ".$action["template"]." (Preorder ".$this->id.")"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": Mailtemplate nicht gefunden: ".$action["template"]." (Preorder ".$this->id.")"); return false; } @@ -409,15 +412,15 @@ class Preorder extends mfBaseModel { try { foreach ($mailtemplate->files as $file) { if (!$file->filename || !$file->file_id || !$file->file->store_filename) continue; - $this->log->debug($file->file->getFullPath()); + $this->log->debug("[".$this->_ruid."] ".$file->file->getFullPath()); $email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null); } $email->send(); } catch (Exception $e) { - $this->log->warning(__METHOD__.": ".$e->getMessage()); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": ".$e->getMessage()); } - $this->log->info(__METHOD__.": Sending StatusTrigger Email to $to"); + $this->log->info("[".$this->_ruid."] ".__METHOD__.": Sending StatusTrigger Email to $to"); return $to; @@ -447,7 +450,7 @@ class Preorder extends mfBaseModel { * Cascade status changes down to adb_hausnummer and adb_wohneinheit */ public function cascadeStatus() { - $this->log->debug(__METHOD__. " entered"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__. " entered"); /* * defines status alignments of preorder status to hausnummer (h) and wohneinheit (w) * if h or w are greater than defined here, don't change them @@ -465,13 +468,13 @@ class Preorder extends mfBaseModel { } if(!defined("TT_PREORDER_STATUS_MATRIX") || !is_array(TT_PREORDER_STATUS_MATRIX) || !count(TT_PREORDER_STATUS_MATRIX)) { - $this->log->warning(__METHOD__ . ": TT_PREORDER_STATUS_MATRIX undefined! Cannot cascade Preorder status to Hausnummer and Wohneinheit"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": TT_PREORDER_STATUS_MATRIX undefined! Cannot cascade Preorder status to Hausnummer and Wohneinheit"); return true; } $new_status = new Preorderstatus($this->status_id); if(!$new_status->id) { - $this->log->warning(__METHOD__ . ": Preorder has invalid status! ".print_r($this, true)); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": Preorder has invalid status! ".print_r($this, true)); return true; } @@ -485,21 +488,21 @@ class Preorder extends mfBaseModel { // set new hausnummer status $new_hausnummer_status = ADBStatusModel::getFirst(["code" => $cascade["h"]]); if(!$new_hausnummer_status) { - $this->log->warning(__METHOD__ . ": new ADBStatus code " . $cascade["h"] . " not found!"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": new ADBStatus code " . $cascade["h"] . " not found!"); return true; } $hausnummer = new ADBHausnummer($this->adb_hausnummer_id); if(!$hausnummer->id) { - $this->log->warning(__METHOD__ . ": hausnummer " . $this->adb_hausnummer_id . " not found!"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": hausnummer " . $this->adb_hausnummer_id . " not found!"); return true; } - $this->log->debug(__METHOD__ . ": new hausnummer status code " . $new_hausnummer_status->code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": new hausnummer status code " . $new_hausnummer_status->code); // only update if current status is less than new status if($hausnummer->status->code < $new_hausnummer_status->code) { - $this->log->debug(__METHOD__ . ": Setting new hausnummer status code: " . $new_hausnummer_status->code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Setting new hausnummer status code: " . $new_hausnummer_status->code); $hausnummer->status_id = $new_hausnummer_status->id; $hausnummer->save(); } @@ -509,17 +512,17 @@ class Preorder extends mfBaseModel { // set new wohneinheit status $new_wohneinheit_status = ADBStatusModel::getFirst(["code" => $cascade["w"]]); if(!$new_wohneinheit_status) { - $this->log->warning(__METHOD__ . ": new ADBStatus code " . $cascade["w"] . " not found!"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": new ADBStatus code " . $cascade["w"] . " not found!"); return true; } $wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); if(!$wohneinheit->id) return true; - $this->log->debug(__METHOD__ . ": new wohneinheit status code " . $new_wohneinheit_status->code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": new wohneinheit status code " . $new_wohneinheit_status->code); // only update if current status is less than new status if($wohneinheit->status->code < $new_wohneinheit_status->code) { - $this->log->debug(__METHOD__ . ": Setting new wohneinheit status code: " . $new_wohneinheit_status->code); + $this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Setting new wohneinheit status code: " . $new_wohneinheit_status->code); $wohneinheit->status_id = $new_wohneinheit_status->id; $wohneinheit->save(); } @@ -532,12 +535,12 @@ class Preorder extends mfBaseModel { if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_MATRIX)) { $flag_matrix_item = TT_PREORDER_STATUS_MATRIX[$flag->code]; if(!$flag_matrix_item["flag"]) continue; - + // set hausnummer flag if($flag_matrix_item["h"]) { $hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]); if(!$hflag) { - $this->log->warn("Statusflag Code ".$flag->code." does not exist"); + $this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist"); } $hflagval = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->adb_hausnummer_id, "flag_id" => $hflag->id]); @@ -550,14 +553,14 @@ class Preorder extends mfBaseModel { } $hflagval->value = $flag->value->value; $hflagval->save(); - $this->log->debug(__METHOD__.": Hausnummer flag ".$hflag->code." value '".$hflagval->value."' gespeichert"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Hausnummer flag ".$hflag->code." value '".$hflagval->value."' gespeichert"); } // set wohneiheit flag if($flag_matrix_item["w"] && $this->adb_wohneinheit_id) { $wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]); if(!$wflag) { - $this->log->warn("Statusflag Code ".$flag->code." does not exist"); + $this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist"); } $wflagval = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->adb_wohneinheit_id, "flag_id" => $wflag->id]); @@ -570,7 +573,7 @@ class Preorder extends mfBaseModel { } $wflagval->value = $flag->value->value; $wflagval->save(); - $this->log->debug(__METHOD__.": Wohneinheit flag ".$hflag->code." gespeichert"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Wohneinheit flag ".$hflag->code." gespeichert"); } } @@ -597,8 +600,8 @@ class Preorder extends mfBaseModel { $tmp_s = $preorder->getProperty("status"); /*if(!$preorder->status->code || !$status->code) { - $this->log->debug("Preorder->status->code". print_r($preorder->status, true)); - $this->log->debug("Status->code". print_r($status->code, true)); + $this->log->debug("[".$this->_ruid."] "."Preorder->status->code". print_r($preorder->status, true)); + $this->log->debug("[".$this->_ruid."] "."Status->code". print_r($status->code, true)); }*/ if($preorder->status->code < $status->code && $status->code <= 244) { @@ -630,7 +633,7 @@ class Preorder extends mfBaseModel { $pflag = PreorderStatusflagModel::getFirst(["preorder_id" => $this->id, "code" => $hflag->code]); if(!$pflag) { - $this->log->error(__METHOD__."PreorderStatusFlag with code ".$hflag->code." not found!"); + $this->log->error("[".$this->_ruid."] ".__METHOD__."PreorderStatusFlag with code ".$hflag->code." not found!"); continue; } $pflag_value = PreorderStatusflagValueModel::getFirst(["preorder_id" => $this->id, "flag_id" => $pflag->id]); @@ -782,7 +785,7 @@ class Preorder extends mfBaseModel { // oaid aus wohneinheit übernehmen, falls vorhanden - $this->log->debug(__METHOD__.": Kampagne unterstützt keine OAIDs"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Kampagne unterstützt keine OAIDs"); return true; }*/ @@ -798,7 +801,7 @@ class Preorder extends mfBaseModel { if($campaign->oaid_origin == "thetool") { $current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid); if($current_oaid) { - $this->log->warning("OAID of Preorder " . $this->id . " should be thetool, but is OFAA"); + $this->log->warning("[".$this->_ruid."] "."OAID of Preorder " . $this->id . " should be thetool, but is OFAA"); } else { if($wohneinheit->oaid != $this->oaid) { $this->oaid = $wohneinheit->oaid; @@ -809,7 +812,7 @@ class Preorder extends mfBaseModel { $current_oaid = OpenAccessIdModel::getFirstOaid($this->oaid); //var_dump($current_oaid);exit; if(!$current_oaid) { - $this->log->error("OAID of Preorder " . $this->id . " not found in OpenAccessIds"); + $this->log->error("[".$this->_ruid."] "."OAID of Preorder " . $this->id . " not found in OpenAccessIds"); // assume it's from a different origin } else { if($campaign->oaid_origin == $current_oaid->origin) { @@ -831,7 +834,7 @@ class Preorder extends mfBaseModel { if($this->type == "interest") return true; if(!$this->id) { - $this->log->error(__METHOD__ . ": Tried to create OAID in unsaved Preorder"); + $this->log->error("[".$this->_ruid."] ".__METHOD__ . ": Tried to create OAID in unsaved Preorder"); throw new Exception(__METHOD__ . ": Tried to create OAID in unsaved Preorder"); } @@ -848,12 +851,12 @@ class Preorder extends mfBaseModel { // else create new OAID if(!$campaign->network) { - $this->log->warning(__METHOD__ . ": Cannot create OAID: Invalid campaign Network"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": Cannot create OAID: Invalid campaign Network"); return false; } $netowner = new Address($campaign->network->owner_id); if(!$netowner->id) { - $this->log->warning(__METHOD__ . ": Cannot create OAID: Invalid campaign Network Owner"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": Cannot create OAID: Invalid campaign Network Owner"); return false; } @@ -871,7 +874,7 @@ class Preorder extends mfBaseModel { $oaid->loadRandomUnassigned($oaid_attributes); if(!$oaid->oaid) { - $this->log->error("Keine weiteren OAIDs verfügbar"); + $this->log->error("[".$this->_ruid."] "."Keine weiteren OAIDs verfügbar"); throw new Exception("Keine weiteren OAIDs verfügbar in " . $netowner->getCompanyOrName()); } else { // make sure this OAID is not in use on another wohneinheit by accident @@ -879,7 +882,7 @@ class Preorder extends mfBaseModel { $oaid_unit_try = 0; while($oaid_unit_count) { if($oaid_unit_try > 5) { - $this->log->error(__METHOD__ . ": Can't find random OAID which is not already used in Wohneinheit by accident after 5 tries. Giving up"); + $this->log->error("[".$this->_ruid."] ".__METHOD__ . ": Can't find random OAID which is not already used in Wohneinheit by accident after 5 tries. Giving up"); throw new Exception("Can't find random OAID which is not already used in Wohneinheit by accident after 5 tries. Giving up"); } $oaid_unit_try++; @@ -891,7 +894,7 @@ class Preorder extends mfBaseModel { } if(!$oaid->oaid) { - $this->log->error(__METHOD__ . ": Cannot generate OAID: OpenAccessId::loadRandomUnassigned() failed."); + $this->log->error("[".$this->_ruid."] ".__METHOD__ . ": Cannot generate OAID: OpenAccessId::loadRandomUnassigned() failed."); return false; } @@ -908,8 +911,8 @@ class Preorder extends mfBaseModel { $oaid->unit_string = (string)$wohneinheit; //var_dump($oaid);exit; if(!$oaid->save()) { - $this->log->error("Fehler beim Speichern der OAID für Preorder " . $this->id); - $this->redirect("Preordercampaign", "Admin"); + $this->log->error("[".$this->_ruid."] "."Fehler beim Speichern der OAID für Preorder " . $this->id); + return false; } if(!$this->save()) { $oaid->assigned = 0; @@ -957,7 +960,7 @@ class Preorder extends mfBaseModel { } $wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id); if(!$wohneinheit->id) { - $this->log->error(__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$this->id." ".$this->ucode." ".$this->oaid.")"); + $this->log->error("[".$this->_ruid."] ".__METHOD__.": Wohneinheit nicht gefunden (Preorder ".$this->id." ".$this->ucode." ".$this->oaid.")"); return false; } @@ -968,7 +971,7 @@ class Preorder extends mfBaseModel { $campaign = new Preordercampaign($this->preordercampaign_id); if($campaign->oaid_origin == "other") { - $this->log->debug(__METHOD__.": Kampagne unterstützt keine OAIDs"); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": Kampagne unterstützt keine OAIDs"); return false; } @@ -981,7 +984,7 @@ class Preorder extends mfBaseModel { $oaid = OpenAccessIdModel::getFirstOaid($wohneinheit->oaid); if(!$oaid) { - $this->log->warning(__METHOD__.": OAID '".$wohneinheit->oaid."' not found"); + $this->log->warning("[".$this->_ruid."] ".__METHOD__.": OAID '".$wohneinheit->oaid."' not found"); return false; } // create and assign OAID if not yet done @@ -999,7 +1002,7 @@ class Preorder extends mfBaseModel { $response = Rimoapi::createWorkorder($wohneinheit->extref, $data); //var_dump($response);exit; if(!$response) { - $this->log->error(__METHOD__."Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$this->ucode.")"); + $this->log->error("[".$this->_ruid."] ".__METHOD__."Cannot create RimoWorkorder! Invalid Response! (Preorder ucode: ".$this->ucode.")"); return false; } @@ -1034,12 +1037,24 @@ class Preorder extends mfBaseModel { return true; } + public function setStatusFlag($code, $value = 1) { + if(!$code) return false; + + $sflag = PreorderstatusflagModel::getFirst(["code" => $code]); + if(!$sflag) return false; + + $sflag->preorder_id = $this->id; + $sflag->value->value = $value; + $sflag->value->save(); + return true; + } + public function getNetowner() { if(!$this->id) return false; if(!$this->adb_hausnummer_id) return false; $network = $this->getProperty("campaign")->network; - $this->log->debug(__METHOD__.": campaign: ".$this->getProperty("campaign")->name); - $this->log->debug(__METHOD__.": network: ".$network->name); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": campaign: ".$this->getProperty("campaign")->name); + $this->log->debug("[".$this->_ruid."] ".__METHOD__.": network: ".$network->name); if(!$network) return false; return $network->owner; @@ -1198,7 +1213,7 @@ class Preorder extends mfBaseModel { $fs_filename = "$filename.jpg"; if(!file_put_contents(MFUPLOAD_FILE_SAVE_PATH."/preorder-borderpoint/$fs_filename", $image_content)) { - $this->log->error(__METHOD__.": Error saving Borderpoint Static Map Image File"); + $this->log->error("[".$this->_ruid."] ".__METHOD__.": Error saving Borderpoint Static Map Image File"); return false; } @@ -1212,7 +1227,7 @@ class Preorder extends mfBaseModel { "subfolder" => "preorder-borderpoint", ]); if(!$file->save()) { - $this->log->error(__METHOD__.": Error saving File Object"); + $this->log->error("[".$this->_ruid."] ".__METHOD__.": Error saving File Object"); return false; } @@ -1226,7 +1241,7 @@ class Preorder extends mfBaseModel { ]); if(!$pf->save()) { - $this->log->error(__METHOD__.": Error saving PreorderFile Object"); + $this->log->error("[".$this->_ruid."] ".__METHOD__.": Error saving PreorderFile Object"); return false; } @@ -1601,6 +1616,7 @@ class Preorder extends mfBaseModel { $old_id = $this->id; //$old_ucode = $this->ucode; $this->id = null; + $this->_ruid = bin2hex(random_bytes(16)); $this->data = clone($this->data); $this->_old_data = new StdClass(); diff --git a/lib/mvcfronk/mfBase/mfBaseModel.php b/lib/mvcfronk/mfBase/mfBaseModel.php index 5444b534e..9cf127d37 100644 --- a/lib/mvcfronk/mfBase/mfBaseModel.php +++ b/lib/mvcfronk/mfBase/mfBaseModel.php @@ -28,11 +28,14 @@ class mfBaseModel { protected $table = false; protected $fieldprefix = false; + protected $_ruid; + /** * Takes ID or DB row as arguments * @param id or table row $_ */ public function __construct($_ = NULL, $new_db_connection = false) { + $this->_ruid = substr(hash("sha256", random_bytes(32)), 0, 8); $this->log = mfLoghandler::singleton(); $this->table = get_class($this); $this->data = new stdClass();