From 37acdc21fa32f343525f404d100e1e83689b6839 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sun, 27 Dec 2020 15:37:31 +0100 Subject: [PATCH] chg: [internal] Use find('column') on more places --- app/Model/Event.php | 13 ++++++------- app/Model/Server.php | 19 +++++++++---------- app/Model/SharingGroupOrg.php | 7 +++---- app/Model/SharingGroupServer.php | 7 +++---- app/Model/User.php | 5 ++--- 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/app/Model/Event.php b/app/Model/Event.php index 87926efb8..ab2ac7e7d 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -1805,11 +1805,10 @@ class Event extends AppModel { $conditions = $this->createEventConditions($user); $conditions['AND'][] = $params['conditions']; - $results = array_values($this->find('list', array( + $results = $this->find('column', array( 'conditions' => $conditions, - 'recursive' => -1, 'fields' => array('Event.id') - ))); + )); return $results; } @@ -1885,9 +1884,9 @@ class Event extends AppModel if ($list) { $params = array( 'conditions' => $conditions, - 'recursive' => -1, + 'fields' => ['Event.id'], ); - $results = array_values($this->find('list', $params)); + $results = $this->find('column', $params); } else { $params = array( 'conditions' => $conditions, @@ -2700,7 +2699,7 @@ class Event extends AppModel $existingOrg = $this->Orgc->find('first', array( 'recursive' => -1, 'conditions' => array('Orgc.name' => $org), - 'fields' => array('Orgc.name', 'Orgc.id') + 'fields' => array('Orgc.id') )); if (empty($existingOrg)) { $params['org']['OR'][$k] = -1; @@ -2717,7 +2716,7 @@ class Event extends AppModel $existingOrg = $this->Orgc->find('first', array( 'recursive' => -1, 'conditions' => array('Orgc.name' => $org), - 'fields' => array('Orgc.name', 'Orgc.id') + 'fields' => array('Orgc.id') )); if (!empty($existingOrg)) { $temp[] = $existingOrg['Orgc']['id']; diff --git a/app/Model/Server.php b/app/Model/Server.php index 31cf60c91..65da0475e 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -2627,11 +2627,10 @@ class Server extends AppModel } elseif ("update" === $technique) { $eventIds = $this->getEventIdsFromServer($server, false, null, true, 'events', $force); $eventModel = ClassRegistry::init('Event'); - $local_event_ids = $eventModel->find('list', array( - 'fields' => array('uuid'), - 'recursive' => -1, + $localEventUuids = $eventModel->find('column', array( + 'fields' => array('Event.uuid'), )); - return array_intersect($eventIds, $local_event_ids); + return array_intersect($eventIds, $localEventUuids); } elseif (is_numeric($technique)) { return array(intval($technique)); } elseif (Validation::uuid($technique)) { @@ -3166,11 +3165,11 @@ class Server extends AppModel } else { if (Configure::read('MISP.enableEventBlocklisting') !== false) { $this->EventBlocklist = ClassRegistry::init('EventBlocklist'); - $blocklistHits = $this->EventBlocklist->find('list', array( - 'recursive' => -1, + $blocklistHits = $this->EventBlocklist->find('column', array( 'conditions' => array('EventBlocklist.event_uuid' => array_column($eventArray, 'uuid')), - 'fields' => array('EventBlocklist.event_uuid', 'EventBlocklist.event_uuid'), + 'fields' => array('EventBlocklist.event_uuid'), )); + $blocklistHits = array_flip($blocklistHits); foreach ($eventArray as $k => $event) { if (isset($blocklistHits[$event['uuid']])) { unset($eventArray[$k]); @@ -3180,11 +3179,11 @@ class Server extends AppModel if (Configure::read('MISP.enableOrgBlocklisting') !== false) { $this->OrgBlocklist = ClassRegistry::init('OrgBlocklist'); - $blocklistHits = $this->OrgBlocklist->find('list', array( - 'recursive' => -1, + $blocklistHits = $this->OrgBlocklist->find('column', array( 'conditions' => array('OrgBlocklist.org_uuid' => array_unique(array_column($eventArray, 'orgc_uuid'))), - 'fields' => array('OrgBlocklist.org_uuid', 'OrgBlocklist.org_uuid'), + 'fields' => array('OrgBlocklist.org_uuid'), )); + $blocklistHits = array_flip($blocklistHits); foreach ($eventArray as $k => $event) { if (isset($blocklistHits[$event['orgc_uuid']])) { unset($eventArray[$k]); diff --git a/app/Model/SharingGroupOrg.php b/app/Model/SharingGroupOrg.php index afbd5a395..5580fc501 100644 --- a/app/Model/SharingGroupOrg.php +++ b/app/Model/SharingGroupOrg.php @@ -78,12 +78,11 @@ class SharingGroupOrg extends AppModel */ public function fetchAllAuthorised($org_id) { - $sgs = $this->find('list', array( + $sgs = $this->find('column', array( 'conditions' => array('org_id' => $org_id), - 'recursive' => -1, - 'fields' => array('sharing_group_id'), + 'fields' => array('SharingGroupOrg.sharing_group_id'), )); - return array_values($sgs); + return $sgs; } // pass a sharing group ID and an organisation ID, returns true if it has a matching attached organisation object diff --git a/app/Model/SharingGroupServer.php b/app/Model/SharingGroupServer.php index e7135ebfd..952de6f43 100644 --- a/app/Model/SharingGroupServer.php +++ b/app/Model/SharingGroupServer.php @@ -87,12 +87,11 @@ class SharingGroupServer extends AppModel // This basically lists all SGs that allow everyone on the instance to see events tagged with it public function fetchAllAuthorised() { - $sgs = $this->find('list', array( + $sgs = $this->find('column', array( 'conditions' => array('all_orgs' => 1, 'server_id' => 0), - 'recursive' => -1, - 'fields' => array('sharing_group_id'), + 'fields' => array('SharingGroupServer.sharing_group_id'), )); - return array_values($sgs); + return $sgs; } // pass a sharing group ID, returns true if it has an attached server object with "all_orgs" ticked diff --git a/app/Model/User.php b/app/Model/User.php index d2920233a..4395d88c0 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -959,10 +959,9 @@ class User extends AppModel public function getOrgAdminsForOrg($org_id, $excludeUserId = false) { - $adminRoles = $this->Role->find('list', array( - 'recursive' => -1, + $adminRoles = $this->Role->find('column', array( 'conditions' => array('perm_admin' => 1), - 'fields' => array('Role.id', 'Role.id') + 'fields' => array('Role.id') )); $conditions = array( 'User.org_id' => $org_id,