Regarding AstDB, snapshots could be a challenge on larger systems, in part because there is so much Asterisk SIP state tracked there completely outside of the confines of the FreePBX GUI . When the GUI does manipulate the AstDB, it is probably going through the plumbing to reach commands like database put here:
}
$this->memAstDB[$keyUsed] = $value;
$write_through = true;
}
$this->memAstDBArray = array();
} else {
$write_through = true;
}
if ($write_through) {
$value = freepbx_str_replace('"','\\"',$value);
$r = $this->command("database put ".freepbx_str_replace(" ","/",$family)." ".freepbx_str_replace(" ","/",$key)." \"".$value."\"");
return (bool)strstr($r["data"] ?? '', "success");
}
return true;
}
/** Get an entry from the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @return mixed Value of the key, or false if error
*/
And here:
if (!isset($this->memAstDB[$keyUsed]) || $this->memAstDB[$keyUsed] != $value) {
$this->memAstDB[$keyUsed] = $value;
$write_through = true;
}
$this->memAstDBArray = array();
} else {
$write_through = true;
}
if ($write_through) {
$value = str_replace('"','\\"',$value);
$r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." \"".$value."\"");
return (bool)strstr($r["data"], "success");
}
return true;
}
/** Get an entry from the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @return mixed Value of the key, or false if error
*/
And here:
if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") {
$options[$key] = $args[$id];
}
}
/* Remove call me num from options - that is set in ast db */
unset($options["callmenum"]);
/* New account values to vmconf */
$vmconf[$context][$extension] = ["mailbox" => $extension, "pwd" => $pwd, "name" => $name, "email" => $email, "pager" => $pager, "options" => $options];
$callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension;
// Save call me num.
$cmd = "database put AMPUSER $extension/callmenum $callmenum";
if($astman->connected()) {
$astman->send_request("Command", ["Command" => $cmd]);
}
}
break;
case "bsettings":
if (!empty($extension)) {
/* Get user's old settings, since we are only replacing the basic settings. */
$vmbox = voicemail_mailbox_get($extension);
/* Delete user's old settings. */
And here:
} else if ($args[$id] == "undefined") {
unset($options[$basic_opt]);
}
}
/* Remove call me num from options - that is set in ast db. Should not be here anyway, since options are coming from the old settings... */
unset($options["callmenum"]);
/* New account values to vmconf */
$vmconf[$context][$extension] = ["mailbox" => $extension, "pwd" => $pwd, "name" => $name, "email" => $email, "pager" => $pager, "options" => $options];
$callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension;
// Save call me num.
$cmd = "database put AMPUSER $extension/callmenum $callmenum";
if($astman->connected()) {
$astman->send_request("Command", ["Command" => $cmd]);
}
}
break;
default:
return false;
}
if(!empty($vmconf)) {
$vmconf['general']['charset'] = "UTF-8";
And maybe more… but (hopefully not) here:
}
return $db;
}
/** Add an entry to the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @param mixed $value The value to add
* @return bool True if successful
*/
function database_put($family, $key, $value) {
$value = (trim($value ?? ' ') == '')?'"'.$value.'"':$value;
$r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value);
if (!empty($this->memAstDB)){
$keyUsed="/".str_replace(" ","/",$family)."/".str_replace(" ","/",$key);
$this->memAstDB[$keyUsed] = $value;
}
return (bool)strstr($r["data"], "success");
}
/** Get an entry from the asterisk database
Slightly aside, probably should add some upgrades from the generic command to more direct AMI commands in to the v18 milestone , so we can do nice things like DBPut and stuff… here is the GH issue.
2 Likes