-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApiGqlHelper.class.php
60 lines (52 loc) · 1.66 KB
/
ApiGqlHelper.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* This is the FreePBX Big Module Object.
*
* This is a very basic interface to the existing 'module_functions' class.
*
* License for all code of this FreePBX module can be found in the license file inside the module directory
* Copyright 2013-2021 Sangoma Technologies Inc.
*/
#[\AllowDynamicProperties]
class ApiGqlHelper extends \FreePBX_Helpers {
public function __construct($freepbx = null)
{
if ($freepbx == null) {
throw new \Exception("Not given a FreePBX Object");
}
$this->freepbx = $freepbx;
}
public function execGqlApi($args) {
$apiObj = $this->freepbx->Api();
$module = strtolower((string) $args[0]);
$action = strtolower((string) $args[1]);
$track = $args[2];
$txnId = $args[3];
$bin = $this->freepbx->Config()->get('AMPSBIN');
if($module == 'upgradeall'){
$action = $module;
$txnId = $args[2];
shell_exec($bin.'/fwconsole ma '.$action);
} else {
shell_exec($bin . '/fwconsole ma ' . $action . ' ' . $module . ' --' . $track);
}
$result = shell_exec($bin."/fwconsole ma list|grep ".$module ."|awk '{print $5 $6}'");
$reason = '';
$enabled = ['enable', 'install', 'upgrade'];
if (in_array($action, $enabled) && $result = "|Enabled") {
$status = "Executed";
}else if($action == "disable" && $result ="|Disabled"){
$status = "Executed";
}else if($action == "uninstall" && $result ="NotInstalled"){
$status = "Executed";
}else if($action == "delete" && $result =""){
$status = "Executed";
}elseif($action == 'upgradeall'){
$status = "Executed";
}else{
$status = "Failed";
$reason = "Status could not be found";
}
$apiObj->setTransactionStatus($txnId,$status,$reason);
}
}