mirror of https://github.com/MISP/MISP
parent
2b8af20cf4
commit
be472df5b5
|
@ -19,7 +19,8 @@ class Attribute extends AppModel {
|
|||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'
|
||||
));
|
||||
),// 'Trim' => array('fields' => array('value'))
|
||||
);
|
||||
|
||||
/**
|
||||
* Display field
|
||||
|
@ -450,7 +451,10 @@ class Attribute extends AppModel {
|
|||
}
|
||||
|
||||
public function beforeValidate($options = array()) {
|
||||
parent::beforeValidate();
|
||||
|
||||
// remove leading and trailing blanks
|
||||
//$this->trimStringFields(); // TODO
|
||||
$this->data['Attribute']['value'] = trim($this->data['Attribute']['value']);
|
||||
|
||||
if (!isset($this->data['Attribute']['type'])) {
|
||||
|
@ -940,10 +944,19 @@ class Attribute extends AppModel {
|
|||
);
|
||||
$eventDate = $this->Event->find('first', $params);
|
||||
|
||||
//// not needed seek original Org
|
||||
//$params = array(
|
||||
// 'conditions' => array('Event.id' => $attribute['event_id']),
|
||||
// 'recursive' => 0,
|
||||
// 'fields' => array('Event.org')
|
||||
//);
|
||||
//$eventOrg = $this->Event->find('first', $params);
|
||||
|
||||
$this->Correlation->create();
|
||||
$this->Correlation->save(array(
|
||||
'Correlation' => array(
|
||||
'1_event_id' => $attribute['event_id'], '1_attribute_id' => $attribute['id'], '1_private' => isset($attribute['private']) ? $attribute['private'] : false,
|
||||
//'1_org' => $eventOrg['Event']['org'], // TODO newest
|
||||
'event_id' => $relatedAttribute['Attribute']['event_id'], 'attribute_id' => $relatedAttribute['Attribute']['id'],
|
||||
'org' => $eventDate['Event']['org'],
|
||||
'private' => $relatedAttribute['Attribute']['private'],
|
||||
|
@ -974,6 +987,7 @@ class Attribute extends AppModel {
|
|||
$this->Correlation->save(array(
|
||||
'Correlation' => array(
|
||||
'1_event_id' => $relatedAttribute['Attribute']['event_id'], '1_attribute_id' => $relatedAttribute['Attribute']['id'], '1_private' => $relatedAttribute['Attribute']['private'],
|
||||
//'1_org' => $relatedAttribute['Event']['org'], // TODO newest
|
||||
'event_id' => $attribute['event_id'], 'attribute_id' => $attribute['id'],
|
||||
'org' => $eventDate['Event']['org'],
|
||||
'private' => isset($attribute['private']) ? $attribute['private'] : false,
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Behavior to trim all string fields in a model
|
||||
*
|
||||
* @author noud
|
||||
*
|
||||
*/
|
||||
class TrimBehavior extends ModelBehavior {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Model $Model
|
||||
* @param unknown_type $settings
|
||||
*/
|
||||
public function setup(Model $Model, $settings = array()) {
|
||||
if (!isset($this->settings[$Model->alias])) {
|
||||
$this->settings[$Model->alias] = array(
|
||||
'fields' => 'all',
|
||||
);
|
||||
}
|
||||
$this->settings[$Model->alias] = array_merge(
|
||||
$this->settings[$Model->alias], (array)$settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim String Fields
|
||||
*
|
||||
* @param Model $Model
|
||||
* @param unknown_type $array
|
||||
*/
|
||||
public function trimStringFields(Model $Model) {
|
||||
foreach ($Model->data[$Model->name] as &$field) {
|
||||
if (is_string($field)) {
|
||||
$field = trim($field);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ class Server extends AppModel {
|
|||
'userModel' => 'User',
|
||||
'userKey' => 'user_id',
|
||||
'change' => 'full'
|
||||
));
|
||||
), 'Trim');
|
||||
|
||||
/**
|
||||
* Display field
|
||||
|
@ -104,22 +104,6 @@ class Server extends AppModel {
|
|||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Trim Array Elements (this should probably be in a behavior)
|
||||
*
|
||||
* @param $array
|
||||
*/
|
||||
protected function _trimArray(&$array = array()) {
|
||||
// process some..
|
||||
foreach ($array as &$field) {
|
||||
// remove leading and trailing blanks
|
||||
if (is_string($field)) {
|
||||
$field = trim($field);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $options
|
||||
|
@ -128,7 +112,7 @@ class Server extends AppModel {
|
|||
parent::beforeValidate();
|
||||
|
||||
// process some..
|
||||
$this->_trimArray($this->data['Server']);
|
||||
$this->trimStringFields();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue