Automation API #FIX
This commit is contained in:
parent
7ea4a90980
commit
8b32ecc619
@ -7,15 +7,7 @@ class AutomationsApi extends ApiController
|
|||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
$response = [];
|
$response = [];
|
||||||
$automationsData = AutomationManager::getAll();
|
$response = AutomationManager::getAll(["automation_id","name","enabled"]);
|
||||||
|
|
||||||
foreach ($automationsData as $automationKey => $automation) {
|
|
||||||
$response[] = [
|
|
||||||
"automation_id" => $automation['automation_id'],
|
|
||||||
"name" => $automation['name'],
|
|
||||||
"enabled" => $automation['enabled'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
@ -23,19 +15,9 @@ class AutomationsApi extends ApiController
|
|||||||
public function detail($automationId)
|
public function detail($automationId)
|
||||||
{
|
{
|
||||||
//$this->requireAuth();
|
//$this->requireAuth();
|
||||||
|
$response = [];
|
||||||
$response = null;
|
$response = AutomationManager::getById($automationId, ["automation_id", "last_execution_time", "owner_id", "conditions", "tasks"]);
|
||||||
$automationData = AutomationManager::getById($automationId);
|
|
||||||
|
|
||||||
$response = [
|
|
||||||
'automation_id' => $automationData['automation_id'],
|
|
||||||
'last_execution_time' => $automationData['last_execution_time'],
|
|
||||||
'owner' => $automationData['owner_id'],
|
|
||||||
'conditions' => $automationData['conditions'],
|
|
||||||
'tasks' => $automationData['tasks'],
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->response($response);
|
$this->response($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function deactive($automationId) {
|
public static function deactive($automationId) {
|
||||||
$automation = Db::loadOne ("SELECT * FROM automation WHERE automation_id=?" , array ($automationId));
|
$automation = self::getById($automationId,["enabled"]);
|
||||||
$flipedValue = ($automation['active'] == 1 ? 0 : 1);
|
$flipedValue = ($automation['enabled'] == 1 ? 0 : 1);
|
||||||
return Db::command ('UPDATE automation SET active = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
return Db::command ('UPDATE automation SET enabled = ? WHERE automation_id=?', array ($flipedValue,$automationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function restart($automationId) {
|
public static function restart($automationId) {
|
||||||
@ -38,13 +38,12 @@ class AutomationManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAll(){
|
public static function getAll($collums = ['*']){
|
||||||
return Db::loadAll ("SELECT * FROM automation");
|
return Db::loadAll ("SELECT ". implode("," , $collums)." FROM automation");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getById($automationId){
|
public static function getById($automationId, $collums = ['*']){
|
||||||
return Db::loadOne("SELECT * FROM automation WHERE automation_id = ?", [$automationId]);
|
return Db::loadOne("SELECT ". implode("," , $collums)." FROM automation WHERE automation_id = ?", [$automationId]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user