mirror of https://github.com/MISP/MISP
new: [sync] Event index cleaned up, total count of listd events added as X-Result-Count header
parent
5f9e04aa4f
commit
7b9b58356c
|
@ -291,40 +291,9 @@ class EventsController extends AppController
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function index()
|
||||
private function __setIndexFilterConditions($passedArgs, $urlparams)
|
||||
{
|
||||
// list the events
|
||||
$passedArgsArray = array();
|
||||
$urlparams = "";
|
||||
$overrideAbleParams = array('all', 'attribute', 'published', 'eventid', 'datefrom', 'dateuntil', 'org', 'eventinfo', 'tag', 'tags', 'distribution', 'sharinggroup', 'analysis', 'threatlevel', 'email', 'hasproposal', 'timestamp', 'publishtimestamp', 'publish_timestamp', 'minimal');
|
||||
$paginationParams = array('limit', 'page', 'sort', 'direction', 'order');
|
||||
$passedArgs = $this->passedArgs;
|
||||
if (isset($this->request->data)) {
|
||||
if (isset($this->request->data['request'])) {
|
||||
$this->request->data = $this->request->data['request'];
|
||||
}
|
||||
foreach ($this->request->data as $k => $v) {
|
||||
if (substr($k, 0, 6) === 'search' && in_array(strtolower(substr($k, 6)), $overrideAbleParams)) {
|
||||
unset($this->request->data[$k]);
|
||||
$this->request->data[strtolower(substr($k, 6))] = $v;
|
||||
} else if (in_array(strtolower($k), $overrideAbleParams)) {
|
||||
unset($this->request->data[$k]);
|
||||
$this->request->data[strtolower($k)] = $v;
|
||||
}
|
||||
}
|
||||
foreach ($overrideAbleParams as $oap) {
|
||||
if (isset($this->request->data[$oap])) {
|
||||
$passedArgs['search' . $oap] = $this->request->data[$oap];
|
||||
}
|
||||
}
|
||||
foreach ($paginationParams as $paginationParam) {
|
||||
if (isset($this->request->data[$paginationParam])) {
|
||||
$passedArgs[$paginationParam] = $this->request->data[$paginationParam];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set('passedArgs', json_encode($passedArgs));
|
||||
// check each of the passed arguments whether they're a filter (could also be a sort for example) and if yes, add it to the pagination conditions
|
||||
foreach ($passedArgs as $k => $v) {
|
||||
if (substr($k, 0, 6) === 'search') {
|
||||
if (!is_array($v)) {
|
||||
|
@ -687,6 +656,43 @@ class EventsController extends AppController
|
|||
$passedArgsArray[$searchTerm] = $v;
|
||||
}
|
||||
}
|
||||
return $passedArgsArray;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// list the events
|
||||
$urlparams = "";
|
||||
$overrideAbleParams = array('all', 'attribute', 'published', 'eventid', 'datefrom', 'dateuntil', 'org', 'eventinfo', 'tag', 'tags', 'distribution', 'sharinggroup', 'analysis', 'threatlevel', 'email', 'hasproposal', 'timestamp', 'publishtimestamp', 'publish_timestamp', 'minimal');
|
||||
$paginationParams = array('limit', 'page', 'sort', 'direction', 'order');
|
||||
$passedArgs = $this->passedArgs;
|
||||
if (isset($this->request->data)) {
|
||||
if (isset($this->request->data['request'])) {
|
||||
$this->request->data = $this->request->data['request'];
|
||||
}
|
||||
foreach ($this->request->data as $k => $v) {
|
||||
if (substr($k, 0, 6) === 'search' && in_array(strtolower(substr($k, 6)), $overrideAbleParams)) {
|
||||
unset($this->request->data[$k]);
|
||||
$this->request->data[strtolower(substr($k, 6))] = $v;
|
||||
} else if (in_array(strtolower($k), $overrideAbleParams)) {
|
||||
unset($this->request->data[$k]);
|
||||
$this->request->data[strtolower($k)] = $v;
|
||||
}
|
||||
}
|
||||
foreach ($overrideAbleParams as $oap) {
|
||||
if (isset($this->request->data[$oap])) {
|
||||
$passedArgs['search' . $oap] = $this->request->data[$oap];
|
||||
}
|
||||
}
|
||||
foreach ($paginationParams as $paginationParam) {
|
||||
if (isset($this->request->data[$paginationParam])) {
|
||||
$passedArgs[$paginationParam] = $this->request->data[$paginationParam];
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set('passedArgs', json_encode($passedArgs));
|
||||
// check each of the passed arguments whether they're a filter (could also be a sort for example) and if yes, add it to the pagination conditions
|
||||
$passedArgsArray = $this->__setIndexFilterConditions($passedArgs, $urlparams);
|
||||
if (!$this->_isRest()) {
|
||||
$this->paginate['contain'] = array_merge($this->paginate['contain'], array('User.email', 'EventTag'));
|
||||
} else {
|
||||
|
@ -731,6 +737,14 @@ class EventsController extends AppController
|
|||
$rules[$paginationRule] = $passedArgs[$paginationRule];
|
||||
}
|
||||
}
|
||||
$counting_rules = $rules;
|
||||
if (!empty($counting_rules['limit'])) {
|
||||
unset($counting_rules['limit']);
|
||||
}
|
||||
if (!empty($counting_rules['page'])) {
|
||||
unset($counting_rules['page']);
|
||||
}
|
||||
$absolute_total = $this->Event->find('count', $counting_rules);
|
||||
if (empty($rules['limit'])) {
|
||||
$events = array();
|
||||
$i = 1;
|
||||
|
@ -818,12 +832,12 @@ class EventsController extends AppController
|
|||
if ($this->response->type() === 'application/xml') {
|
||||
$events = array('Event' => $events);
|
||||
}
|
||||
return $this->RestResponse->viewData($events, $this->response->type());
|
||||
return $this->RestResponse->viewData($events, $this->response->type(), false, false, false, array('X-Result-Count' => $absolute_total));
|
||||
} else {
|
||||
foreach ($events as $key => $event) {
|
||||
$events[$key] = $event['Event'];
|
||||
}
|
||||
return $this->RestResponse->viewData($events, $this->response->type());
|
||||
return $this->RestResponse->viewData($events, $this->response->type(), false, false, false, array('X-Result-Count' => $absolute_total));
|
||||
}
|
||||
} else {
|
||||
$events = $this->paginate();
|
||||
|
|
Loading…
Reference in New Issue