Fixed updating existing Voicenumber when saving ContractConfig
This commit is contained in:
@@ -10,6 +10,7 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
private $voip_routing;
|
||||
|
||||
private $create_numbers = [];
|
||||
private $update_numbers = [];
|
||||
/*
|
||||
* Checks to determine if class needs to work on contract.
|
||||
*/
|
||||
@@ -53,10 +54,12 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
}
|
||||
|
||||
public function beforeSave() {
|
||||
// checking before save, to return errors before saving anything
|
||||
return $this->checkNewNumbers();
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// checking again, just to be sure
|
||||
$this->checkNewNumbers();
|
||||
// load voip routing again, in case it changed with the same config update
|
||||
$this->getVoipRouting();
|
||||
@@ -90,6 +93,22 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->update_numbers as $number) {
|
||||
$voicenumber = VoicenumberModel::getFirst(['number' => $number]);
|
||||
$this->log->debug("creating voicenumber $number in block $voicenumberblock_id");
|
||||
$voicenumber->update([
|
||||
"contract_id" => $this->contract->id,
|
||||
'active' => 1,
|
||||
'activated_date' => date('U'),
|
||||
'routing' => $this->voip_routing,
|
||||
'disabled' => 0
|
||||
]);
|
||||
if(!$voicenumber->save()) {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Error saving existing number $number";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(count($this->errors["voicenumberblock_voicenumber"])) {
|
||||
return false;
|
||||
}
|
||||
@@ -162,6 +181,9 @@ class Contractconfig_Hook_Voicenumberblock extends Contractconfig_Hook {
|
||||
$this->errors["voicenumberblock_voicenumber"][] = "Ungültige Rufnummer $number: Rufnummer wurde rausportiert ".$voicenumber->contract_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->update_numbers[] = $number;
|
||||
|
||||
} else {
|
||||
if(!array_key_exists($voicenumberblock->id, $this->create_numbers)) {
|
||||
$this->create_numbers[$voicenumberblock->id] = [];
|
||||
|
||||
Reference in New Issue
Block a user