diff --git a/app/Console/Command/EventShell.php b/app/Console/Command/EventShell.php index 8940673d8..f8e2399f0 100644 --- a/app/Console/Command/EventShell.php +++ b/app/Console/Command/EventShell.php @@ -636,6 +636,13 @@ class EventShell extends AppShell } } + public function reportValidationIssuesAttributes() + { + foreach ($this->Event->Attribute->reportValidationIssuesAttributes() as $validationIssue) { + echo $this->json($validationIssue) . "\n"; + } + } + /** * @param int $userId * @return array diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index d35c06e5d..2d6f13691 100644 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -1917,7 +1917,7 @@ class AttributesController extends AppController public function reportValidationIssuesAttributes($eventId = false) { // search for validation problems in the attributes - $this->set('result', $this->Attribute->reportValidationIssuesAttributes($eventId)); + $this->set('result', iterator_to_array($this->Attribute->reportValidationIssuesAttributes($eventId))); } public function generateCorrelation() diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index feb58d529..8e2d9670a 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -1224,38 +1224,58 @@ class Attribute extends AppModel $this->Correlation->purgeCorrelations($eventId); } - public function reportValidationIssuesAttributes($eventId) + /** + * @param array $conditions + * @return Generator|void + */ + private function fetchAttributesInChunks(array $conditions = []) + { + while (true) { + $attributes = $this->find('all', [ + 'recursive' => -1, + 'conditions' => $conditions, + 'limit' => 500, + 'order' => 'Attribute.id', + ]); + if (empty($attributes)) { + return; + } + foreach ($attributes as $attribute) { + yield $attribute; + } + $count = count($attributes); + $lastAttribute = $attributes[$count - 1]; + $conditions['Attribute.id >'] = $lastAttribute['Attribute']['id']; + } + } + + /** + * @param int|null $eventId + * @return Generator + */ + public function reportValidationIssuesAttributes($eventId = null) { $conditions = array(); if ($eventId && is_numeric($eventId)) { $conditions = array('event_id' => $eventId); } - $attributeIds = $this->find('column', array( - 'fields' => array('id'), - 'conditions' => $conditions - )); - $chunks = array_chunk($attributeIds, 500); + $attributes = $this->fetchAttributesInChunks($conditions); - $result = array(); - foreach ($chunks as $chunk) { - $attributes = $this->find('all', array('recursive' => -1, 'conditions' => array('id' => $chunk))); - foreach ($attributes as $attribute) { - $this->set($attribute); - if (!$this->validates()) { - $resultErrors = array(); - foreach ($this->validationErrors as $field => $error) { - $resultErrors[$field] = array('value' => $attribute['Attribute'][$field], 'error' => $error[0]); - } - $result[] = [ - 'id' => $attribute['Attribute']['id'], - 'error' => $resultErrors, - 'details' => 'Event ID: [' . $attribute['Attribute']['event_id'] . "] - Category: [" . $attribute['Attribute']['category'] . "] - Type: [" . $attribute['Attribute']['type'] . "] - Value: [" . $attribute['Attribute']['value'] . ']', - ]; + foreach ($attributes as $attribute) { + $this->set($attribute); + if (!$this->validates()) { + $resultErrors = []; + foreach ($this->validationErrors as $field => $error) { + $resultErrors[$field] = ['value' => $attribute['Attribute'][$field], 'error' => $error[0]]; } + yield [ + 'id' => $attribute['Attribute']['id'], + 'error' => $resultErrors, + 'details' => 'Event ID: [' . $attribute['Attribute']['event_id'] . "] - Category: [" . $attribute['Attribute']['category'] . "] - Type: [" . $attribute['Attribute']['type'] . "] - Value: [" . $attribute['Attribute']['value'] . ']', + ]; } } - return $result; } /** @@ -1610,6 +1630,7 @@ class Attribute extends AppModel * @param array $user * @param array $options * @param int|false $result_count If false, count is not fetched + * @param bool $real_count * @return array * @throws Exception */ diff --git a/app/View/Pages/administration.ctp b/app/View/Pages/administration.ctp index 79a3729bd..c1f3baf16 100644 --- a/app/View/Pages/administration.ctp +++ b/app/View/Pages/administration.ctp @@ -1,11 +1,3 @@ - -
- -