correlation

fixed correlations being double accounted.
pull/63/head
noud 2012-11-15 15:53:07 +01:00
parent c1207184f5
commit fdd999ef35
2 changed files with 24 additions and 2 deletions

View File

@ -329,6 +329,16 @@ class AppController extends Controller {
}
}
public function migratemisp11to2() {
if (!self::_isAdmin()) {
throw new NotFoundException();
}
$this->generatePrivate();
$this->generateCorrelation(); // TODO
$this->generateCount();
}
public function generateCorrelation() {
if (!self::_isAdmin()) throw new NotFoundException();
@ -340,7 +350,7 @@ class AppController extends Controller {
$attributes = $this->Attribute->find('all',array('recursive' => 0));
// for all attributes..
foreach ($attributes as $attribute) {
$this->Attribute->setRelatedAttributes($attribute['Attribute'], $fields = array());
$this->Attribute->setInitialRelatedAttributes($attribute['Attribute'], $fields = array());
//// i want to keep this in repo for a moment
//$relatedAttributes = $this->Attribute->getRelatedAttributes($attribute['Attribute'], $fields);

View File

@ -823,6 +823,7 @@ class Attribute extends AppModel {
private function __afterSaveCorrelation($attribute) {
$this->Correlation = ClassRegistry::init('Correlation');
$dummy = $this->Correlation->deleteAll(array('OR' => array('Correlation.attribute_id' => $attribute)));
$dummy = $this->Correlation->deleteAll(array('OR' => array('Correlation.1_attribute_id' => $attribute)));
// re-add
$this->setRelatedAttributes($attribute, array('Attribute.id', 'Attribute.event_id', 'Attribute.private', 'Attribute.cluster', 'Event.date', 'Event.org'));
@ -898,7 +899,7 @@ class Attribute extends AppModel {
// TODO what if value1/2 changes??
}
public function setRelatedAttributes($attribute, $fields=array()) {
public function setInitialRelatedAttributes($attribute, $fields=array()) {
$this->Event = ClassRegistry::init('Event');
$relatedAttributes = $this->getRelatedAttributes($attribute, $fields);
if ($relatedAttributes) {
@ -923,6 +924,17 @@ class Attribute extends AppModel {
'cluster' => $relatedAttribute['Attribute']['cluster'],
'date' => $eventDate['Event']['date']))
);
}
}
}
public function setRelatedAttributes($attribute, $fields=array()) {
$this->setInitialRelatedAttributes($attribute, $fields);
$this->Event = ClassRegistry::init('Event');
$relatedAttributes = $this->getRelatedAttributes($attribute, $fields);
if ($relatedAttributes) {
$this->Correlation = ClassRegistry::init('Correlation');
foreach ($relatedAttributes as $relatedAttribute) {
// and vise versa
$params = array(