public function xGetListAction() { $this->request->defineParams(array('query', 'sort' => array('type' => 'json'))); $hist = new WebhookHistory(); $sql = "SELECT " . $hist->fields('h') . ", w.name AS webhookName, e.url\n FROM " . $hist->table() . " h\n INNER JOIN webhook_endpoints e ON h.endpoint_id = e.endpoint_id\n INNER JOIN webhook_configs w ON h.webhook_id = w.webhook_id\n WHERE e.env_id = ?\n AND :FILTER:\n "; $args = array($this->getEnvironmentId()); if ($this->getParam('eventId')) { $sql .= ' AND h.event_id = ?'; $args[] = $this->getParam('eventId'); } $response = $this->buildResponseFromSql2($sql, array('created'), array('e.url', 'h.event_type'), $args); foreach ($response['data'] as $index => $row) { $hist = new WebhookHistory(); $hist->load($row); $item = array(); foreach (get_object_vars($hist) as $k => $v) { $item[$k] = $v; } $item['url'] = $row['url']; $item['webhookName'] = $row['webhookName']; $item['created'] = Scalr_Util_DateTime::convertTz($hist->created); unset($hist); $response['data'][$index] = $item; } $this->response->data($response); }
/** * @param string $eventId optional * @throws Exception */ public function xGetListAction($eventId = null) { $this->request->defineParams(array('query', 'sort' => array('type' => 'json'))); $hist = new WebhookHistory(); $sql = "SELECT " . $hist->fields('h') . ", w.name AS webhookName, e.url\n FROM " . $hist->table() . " h\n INNER JOIN webhook_endpoints e ON h.endpoint_id = e.endpoint_id\n INNER JOIN webhook_configs w ON h.webhook_id = w.webhook_id\n WHERE :FILTER:\n "; if ($eventId) { $sql .= ' AND h.event_id = ?'; $args[] = $eventId; } if ($this->request->getScope() == WebhookConfig::SCOPE_SCALR) { $sql .= ' AND w.account_id IS NULL'; $sql .= ' AND w.env_id IS NULL'; } elseif ($this->request->getScope() == WebhookConfig::SCOPE_ACCOUNT) { $sql .= ' AND (w.account_id = ? OR w.account_id IS NULL)'; $args[] = $this->user->getAccountId(); $sql .= ' AND w.env_id IS NULL'; } elseif ($this->request->getScope() == WebhookConfig::SCOPE_ENVIRONMENT) { $sql .= ' AND (w.account_id = ? OR w.account_id IS NULL)'; $args[] = $this->user->getAccountId(); $sql .= ' AND (w.env_id = ? OR w.env_id IS NULL)'; $args[] = $this->getEnvironmentId(); } $response = $this->buildResponseFromSql2($sql, array('created'), array('e.url', 'h.event_type'), $args); foreach ($response['data'] as $index => $row) { $hist = new WebhookHistory(); $hist->load($row); $item = array(); foreach (get_object_vars($hist) as $k => $v) { $item[$k] = $v; } $item['url'] = $row['url']; $item['webhookName'] = $row['webhookName']; $item['created'] = Scalr_Util_DateTime::convertTz($hist->created); unset($item['payload']); unset($hist); $response['data'][$index] = $item; } $this->response->data($response); }