updating Rimo subAddress when changing Home tuer
This commit is contained in:
@@ -189,6 +189,12 @@ class ADBHausnummerModel {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @param $limit
|
||||
* @param $returnDBRessource
|
||||
* @return ADBHausnummer[] ADBHausnummer Objects
|
||||
*/
|
||||
public static function search($filter, $limit = false, $returnDBRessource = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
@@ -50,6 +50,8 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
if(!array_key_exists("no_updates", $_params) || !$_params['no_updates']) {
|
||||
// Statuschange from Rimo statuschange
|
||||
AddressDB::handleRimoStatusUpdate($this->id);
|
||||
// Check if tuer has changed and sync to RIMO
|
||||
$this->syncTuerToRimo();
|
||||
}
|
||||
|
||||
$this->refreshUnitCount();
|
||||
@@ -59,6 +61,59 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function syncTuerToRimo() {
|
||||
// Check if tuer field has changed
|
||||
$changes = $this->getChangedFields();
|
||||
if(!in_array("tuer", $changes)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if we have a RIMO external ID
|
||||
if(!$this->extref) {
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": No extref set, skipping RIMO sync");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the hausnummer to access network owner
|
||||
$hausnummer = $this->getProperty("hausnummer");
|
||||
if(!$hausnummer || !$hausnummer->id) {
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": No hausnummer found, skipping RIMO sync");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get RIMO API credentials
|
||||
$creds = $hausnummer->getNetownerRimoApiCredentials();
|
||||
if(!$creds) {
|
||||
$this->log->warn("[".$this->_ruid."] ".__METHOD__.": No API credentials found for network owner");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the API key (using prod environment)
|
||||
$apikey = $creds["prod"]["key"];
|
||||
if(!$apikey) {
|
||||
$this->log->warn("[".$this->_ruid."] ".__METHOD__.": No API key found in credentials");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Call RIMO API to update subAddress (tuer)
|
||||
$this->log->info("[".$this->_ruid."] ".__METHOD__.": Syncing tuer change to RIMO for home ".$this->extref.": '".$this->tuer."'");
|
||||
|
||||
$subaddress = "";
|
||||
if($this->tuer) {
|
||||
$subaddress = "Top ".$this->tuer;
|
||||
}
|
||||
|
||||
$result = Rimoapi::changeHomeSubAddress($apikey, $this->extref, $subaddress);
|
||||
|
||||
if($result) {
|
||||
$this->log->info("[".$this->_ruid."] ".__METHOD__.": Successfully synced tuer to RIMO");
|
||||
} else {
|
||||
$this->log->error("[".$this->_ruid."] ".__METHOD__.": Failed to sync tuer to RIMO");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function refreshUnitCount() {
|
||||
// ADBWohneinheit_onSave_noAutoUnitCount can be defined if doing bulk
|
||||
// operations where unit count is calculated seperately
|
||||
|
||||
@@ -482,6 +482,13 @@ class PreorderModel
|
||||
return self::count($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @param $limit
|
||||
* @param $returnDBRessource
|
||||
* @param $returnArray
|
||||
* @return Preorder[]
|
||||
*/
|
||||
public static function searchActive($filter = [], $limit = false, $returnDBRessource = false, $returnArray = false)
|
||||
{
|
||||
if (!is_array($filter)) return false;
|
||||
|
||||
Reference in New Issue
Block a user