mirror of https://github.com/MISP/MISP
chg: [internal] fetchEventIds refactored
- the stupid ordered params were driving me nutspull/7360/head
parent
a30c6899c7
commit
e711fcc7c5
|
@ -270,7 +270,9 @@ class SightingsController extends AppController
|
|||
if ($eventid) {
|
||||
$conditions['eventid'] = $sightedEvents;
|
||||
}
|
||||
$events = $this->Event->fetchEventIds($this->Auth->user(), false, false, false, false, false, false, $sightedEvents);
|
||||
$events = $this->Event->fetchEventIds($this->Auth->user(), [
|
||||
'eventIdList' => $sightedEvents
|
||||
]);
|
||||
$sightings = array();
|
||||
if (!empty($events)) {
|
||||
foreach ($events as $k => $event) {
|
||||
|
|
|
@ -18,7 +18,12 @@ class MispStatusWidget
|
|||
$data = array();
|
||||
$data[] = array(
|
||||
'title' => __('Events modified'),
|
||||
'value' => count($this->Event->fetchEventIds($user, false, false, false, true, $lastLogin)),
|
||||
'value' => count(
|
||||
$this->Event->fetchEventIds($user, [
|
||||
'list' => true,
|
||||
'timestamp' => $lastLogin
|
||||
])
|
||||
),
|
||||
'html' => sprintf(
|
||||
' (<a href="%s">%s</a>)',
|
||||
Configure::read('MISP.baseurl') . '/events/index/timestamp:' . (time() - 86400),
|
||||
|
@ -27,7 +32,12 @@ class MispStatusWidget
|
|||
);
|
||||
$data[] = array(
|
||||
'title' => __('Events published'),
|
||||
'value' => count($this->Event->fetchEventIds($user, false, false, false, true, false, $lastLogin)),
|
||||
'value' => count(
|
||||
$this->Event->fetchEventIds($user, [
|
||||
'list' => true,
|
||||
'publish_timestamp' => $lastLogin
|
||||
])
|
||||
),
|
||||
'html' => sprintf(
|
||||
' (<a href="%s">%s</a>)',
|
||||
Configure::read('MISP.baseurl') . '/events/index/published:1/timestamp:' . (time() - 86400),
|
||||
|
|
|
@ -2126,7 +2126,11 @@ class Attribute extends AppModel
|
|||
$typeArray[] = 'malware-sample';
|
||||
}
|
||||
$rules = array();
|
||||
$eventIds = $this->Event->fetchEventIds($user, $from, $to, $last);
|
||||
$eventIds = $this->Event->fetchEventIds($user, [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'last' => $last
|
||||
]);
|
||||
if (!empty($tags)) {
|
||||
$tag = ClassRegistry::init('Tag');
|
||||
$args = $this->dissectArgs($tags);
|
||||
|
@ -2184,7 +2188,11 @@ class Attribute extends AppModel
|
|||
if (empty($user)) {
|
||||
throw new MethodNotAllowedException(__('Could not read user.'));
|
||||
}
|
||||
$eventIds = $this->Event->fetchEventIds($user, $from, $to, $last);
|
||||
$eventIds = $this->Event->fetchEventIds($user, [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'last' => $last
|
||||
]);
|
||||
|
||||
// If we sent any tags along, load the associated tag names for each attribute
|
||||
if ($tags) {
|
||||
|
|
|
@ -1740,31 +1740,24 @@ class Event extends AppModel
|
|||
return $this->find('all', $params);
|
||||
}
|
||||
|
||||
public function fetchEventIds($user, $from = false, $to = false, $last = false, $list = false, $timestamp = false, $publish_timestamp = false, $eventIdList = false)
|
||||
public function fetchEventIds($user, $options)
|
||||
{
|
||||
// restricting to non-private or same org if the user is not a site-admin.
|
||||
$conditions = $this->createEventConditions($user);
|
||||
$fields = array('Event.id', 'Event.org_id', 'Event.distribution', 'Event.sharing_group_id');
|
||||
|
||||
if ($from) {
|
||||
$conditions['AND'][] = array('Event.date >=' => $from);
|
||||
$paramMapping = [
|
||||
'from' => 'Event.date >=',
|
||||
'to' => 'Event.date <=',
|
||||
'last' => 'Event.publish_timestamp >=',
|
||||
'timestamp' => 'Event.timestamp >=',
|
||||
'publish_timestamp' => 'Event.publish_timestamp >=',
|
||||
'eventIdList' => 'Event.id',
|
||||
];
|
||||
foreach ($paramMapping as $paramName => $paramLookup) {
|
||||
if (isset($options[$paramName])) {
|
||||
$conditions['AND'][] = [$paramLookup => $options[$paramName]];
|
||||
}
|
||||
}
|
||||
if ($to) {
|
||||
$conditions['AND'][] = array('Event.date <=' => $to);
|
||||
}
|
||||
if ($last) {
|
||||
$conditions['AND'][] = array('Event.publish_timestamp >=' => $last);
|
||||
}
|
||||
if ($timestamp) {
|
||||
$conditions['AND'][] = array('Event.timestamp >=' => $timestamp);
|
||||
}
|
||||
if ($publish_timestamp) {
|
||||
$conditions['AND'][] = array('Event.publish_timestamp >=' => $publish_timestamp);
|
||||
}
|
||||
if ($eventIdList) {
|
||||
$conditions['AND'][] = array('Event.id' => $eventIdList);
|
||||
}
|
||||
if ($list) {
|
||||
if (isset($options['list'])) {
|
||||
$params = array(
|
||||
'conditions' => $conditions,
|
||||
'fields' => ['Event.id'],
|
||||
|
@ -1774,7 +1767,7 @@ class Event extends AppModel
|
|||
$params = array(
|
||||
'conditions' => $conditions,
|
||||
'recursive' => -1,
|
||||
'fields' => $fields,
|
||||
'fields' => ['Event.id', 'Event.org_id', 'Event.distribution', 'Event.sharing_group_id'],
|
||||
);
|
||||
$results = $this->find('all', $params);
|
||||
}
|
||||
|
|
|
@ -877,7 +877,9 @@ class GalaxyCluster extends AppModel
|
|||
public function getTags($galaxyType, $clusterValue = false, $user)
|
||||
{
|
||||
$this->Event = ClassRegistry::init('Event');
|
||||
$event_ids = $this->Event->fetchEventIds($user, false, false, false, true);
|
||||
$event_ids = $this->Event->fetchEventIds($user, [
|
||||
'list' => true
|
||||
]);
|
||||
$tags = $this->Event->EventTag->Tag->find('list', array(
|
||||
'conditions' => array('name LIKE' => 'misp-galaxy:' . $galaxyType . '="' . ($clusterValue ? $clusterValue : '%') .'"'),
|
||||
'fields' => array('name', 'id'),
|
||||
|
|
Loading…
Reference in New Issue