fix: [bug] Potential fix for SQL return size limit reached when fetching a list of attributes

pull/3427/head
iglocska 2018-07-02 10:38:24 +02:00
parent 8559af8c6a
commit c67b575ba6
1 changed files with 42 additions and 24 deletions

View File

@ -2605,18 +2605,35 @@ class Attribute extends AppModel {
));
return $results;
}
$results = $this->find('all', $params);
// return false if we're paginating
if (isset($options['limit']) && empty($results)) return false;
if ($options['enforceWarninglist']) {
$this->Warninglist = ClassRegistry::init('Warninglist');
$warninglists = $this->Warninglist->fetchForEventView();
}
if (empty($params['limit'])) {
$pagesToFetch = $this->find('count', array('conditions' => $params['conditions']));
$loopLimit = 100000;
$pagesToFetch = ceil($pagesToFetch / $loopLimit);
$loop = true;
} else {
$loop = false;
$pagesToFetch = 1;
}
$attributes = array();
for ($i = 0; $i < $pagesToFetch; $i++) {
if ($loop) {
$params['limit'] = $loopLimit;
$params['page'] = $i+1;
}
$results = $this->find('all', $params);
// return false if we're paginating
if (isset($options['limit']) && empty($results)) return false;
$results = array_values($results);
$proposals_block_attributes = Configure::read('MISP.proposals_block_attributes');
foreach ($results as $key => $attribute) {
if ($options['enforceWarninglist'] && !$this->Warninglist->filterWarninglistAttributes($warninglists, $attribute['Attribute'])) {
unset($results[$key]);
continue;
}
if (!empty($options['includeAttributeUuid']) || !empty($options['includeEventUuid'])) {
@ -2624,7 +2641,7 @@ class Attribute extends AppModel {
}
if ($proposals_block_attributes) {
if (!empty($attribute['ShadowAttribute'])) {
unset($results[$key]);
continue;
} else {
unset($results[$key]['ShadowAttribute']);
}
@ -2635,9 +2652,10 @@ class Attribute extends AppModel {
$results[$key]['Attribute']['data'] = $encodedFile;
}
}
$attributes[] = $results[$key];
}
$results = array_values($results);
return $results;
}
return $attributes;
}
// Method gets and converts the contents of a file passed along as a base64 encoded string with the original filename into a zip archive