sholinaty
(sholinaty)
November 1, 2021, 9:10pm
1
starting a thread around: https://issues.freepbx.org/browse/FREEPBX-22986
Goal:
I want to set FindMeFollowMe via the API, as designed
Problem:
someone submitted/approved broken code
an HTTP PUT call to /admin/api/api/rest/findmefollow/users/5136 fails
error is:
{
"error": {
"type": "Whoops\\Exception\\ErrorException",
"message": "Call to undefined function FreePBX\\modules\\Findmefollow\\Api\\Rest\\findmefollow_del()",
"file": "/var/www/html/admin/modules/findmefollow/Api/Rest/Findmefollow.php",
"line": 45
}
}
but what does that MEAN?
the PUT step here: https://github.com/FreePBX/findmefollow/blob/release/15.0/Api/Rest/Findmefollow.php#L45
calls findmefollow_del($args[‘id’]);
which doesn’t exist in
sholinaty
(sholinaty)
November 1, 2021, 9:10pm
2
but there IS a del() command…
}
$astman->database_put("AMPUSER",$grpnum."/followme/changecid",$changecid);
$fixedcid = preg_replace("/[^0-9\+]/" ,"", trim($fixedcid));
$astman->database_put("AMPUSER",$grpnum."/followme/fixedcid",$fixedcid);
} else {
\fatal("Cannot connect to Asterisk Manager with ".$conf->get("AMPMGRUSER")."/".$conf->get("AMPMGRPASS"));
}
}
public function del($grpnum) {
$astman = $this->FreePBX->astman;
$dbh = $this->db;
$conf = $this->FreePBX->Config();
$sql= "DELETE FROM findmefollow WHERE grpnum = :grpnum";
$stmt = $dbh->prepare($sql);
$results = $stmt->execute(array(':grpnum' => $grpnum));
if ($astman) {
$astman->database_deltree("AMPUSER/".$grpnum."/followme");
} else {
sholinaty
(sholinaty)
November 1, 2021, 9:13pm
3
BREADCRUMB!
the findmefollow_get is explicitly defined (thats janky AF…)
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$extdisplay = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : null;
$extension = isset($_REQUEST['extension']) ? $_REQUEST['extension'] : null;
$tech_hardware = isset($_REQUEST['tech_hardware']) ? $_REQUEST['tech_hardware'] : null;
if ($tech_hardware != null || $action == "add" || $extdisplay != '') {
findmefollow_users_configpageinit($dispnum);
}
}
}
function findmefollow_get($grpnum, $check_astdb=0) {
return FreePBX::Findmefollow()->get($grpnum, $check_astdb);
}
// we only return the destination that other modules might use, e.g. extenions/users
function findmefollow_getdest($exten) {
return array('ext-findmefollow,FM' . $exten . ',1');
}
function findmefollow_getdestinfo($dest) {
if (substr(trim($dest),0,17) == 'ext-findmefollow,' || substr(trim($dest),0,10) == 'ext-local,' && substr(trim($dest),-4) == 'dest') {
so we must just be missing it in the del.
sholinaty
(sholinaty)
November 1, 2021, 9:24pm
4
first (?) Pull request: https://git.freepbx.org/projects/FREEPBX/repos/findmefollow/pull-requests/38/overview
turns out the del( function exists already, it was just not actually tied to the findmefollow_del that was trying to call it.
1 Like
sholinaty
(sholinaty)
November 2, 2021, 5:22pm
5
@lgaetz hoping for a 2nd set of eyes…
Findmefollow_add seems to pass a big pile of comma separated args to a function that doesn’t exist…
/**
* @verb PUT
* @uri /findmefollow/users/:id
*/
$app->put('/users/{id}', function ($request, $response, $args) {
\FreePBX::Modules()->loadFunctionsInc('findmefollow');
$params = $request->getParsedBody();
findmefollow_del($args['id']);
return $response->withJson(findmefollow_add(
$args['id'],
$params['strategy'],
$params['grptime'],
$params['grplist'],
$params['postdest'],
$params['grppre'],
$params['annmsg_id'],
$params['dring'],
$params['needsconf'],
$params['remotealert_id'],
but the ADD takes in… a $Data blob, which has to be an array?
'reset' => array(
'name' => 'reset',
'id' => 'reset',
'value' => _('Reset')
)
);
break;
}
return $buttons;
}
function add($grpnum,$data) {
if(!is_array($data)) {
throw new \Exception("The format for adding a fmfm has changed. Please fix the calling code to reflect this");
}
$defaults = array(
'strategy' => $this->FreePBX->Config->get('FOLLOWME_RG_STRATEGY'),
'grptime' => $this->FreePBX->Config->get('FOLLOWME_TIME'),
'grplist' => $grpnum,
'postdest' => 'ext-local,'.$grpnum.',dest',
'grppre' => '',
'annmsg_id' => '',
more specifically… I just need to map the rest 'findmefollow_add" through an intermediary function to create an array from the list of params, then we should be good to call add properly…
does that pass a sanity check?
lgaetz
(Lorne Gaetz)
November 2, 2021, 5:49pm
6
Not something I have personal knowledge of. All engineering is pretty much focused on Astricon this week (most will be reachable at https://astricon.slack.com ). Prob best to open a ticket with your findings and engineering can review when they come up for air next week.
sholinaty
(sholinaty)
November 2, 2021, 6:09pm
7
how did i nearly miss astricon?!
time to burn the sprint, and gain some knowledge!
1 Like
sholinaty
(sholinaty)
November 2, 2021, 7:43pm
8
re-created the PR with a single commit, to get delete and ADD working in the same commit (for history / changelog)
https://git.freepbx.org/projects/FREEPBX/repos/findmefollow/pull-requests/39/overview
sholinaty
(sholinaty)
November 8, 2021, 7:06pm
9
Some progress… but not enough.
the current EDGE module, the Delete works.
but the following Add for FindMeFollow is failing. trying to sort out why.
sholinaty
(sholinaty)
November 8, 2021, 9:44pm
10
got it fixed, and functionally tested.
waiting for the next Pull Request to get merged.
2 Likes
system
(system)
Closed
December 9, 2021, 9:44pm
11
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.