mirror of https://github.com/MISP/MISP
fix: [internal] Capturing org
parent
5c4a126aaa
commit
b5b26455f0
|
@ -107,32 +107,33 @@ class Organisation extends AppModel
|
||||||
public function beforeValidate($options = array())
|
public function beforeValidate($options = array())
|
||||||
{
|
{
|
||||||
parent::beforeValidate();
|
parent::beforeValidate();
|
||||||
if (empty($this->data['Organisation']['uuid'])) {
|
$org = &$this->data[$this->alias];
|
||||||
$this->data['Organisation']['uuid'] = CakeText::uuid();
|
if (empty($org['uuid'])) {
|
||||||
|
$org['uuid'] = CakeText::uuid();
|
||||||
} else {
|
} else {
|
||||||
$this->data['Organisation']['uuid'] = strtolower(trim($this->data['Organisation']['uuid']));
|
$org['uuid'] = strtolower(trim($org['uuid']));
|
||||||
}
|
}
|
||||||
$date = date('Y-m-d H:i:s');
|
$date = date('Y-m-d H:i:s');
|
||||||
if (array_key_exists('restricted_to_domain', $this->data['Organisation'])) {
|
if (array_key_exists('restricted_to_domain', $org)) {
|
||||||
if (!is_array($this->data['Organisation']['restricted_to_domain'])) {
|
if (!is_array($org['restricted_to_domain'])) {
|
||||||
$this->data['Organisation']['restricted_to_domain'] = str_replace("\r", '', $this->data['Organisation']['restricted_to_domain']);
|
$org['restricted_to_domain'] = str_replace("\r", '', $org['restricted_to_domain']);
|
||||||
$this->data['Organisation']['restricted_to_domain'] = explode("\n", $this->data['Organisation']['restricted_to_domain']);
|
$org['restricted_to_domain'] = explode("\n", $org['restricted_to_domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data['Organisation']['restricted_to_domain'] = array_values(
|
$org['restricted_to_domain'] = array_values(
|
||||||
array_filter(
|
array_filter(
|
||||||
array_map('trim', $this->data['Organisation']['restricted_to_domain'])
|
array_map('trim', $org['restricted_to_domain'])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->data['Organisation']['restricted_to_domain'] = json_encode($this->data['Organisation']['restricted_to_domain']);
|
$org['restricted_to_domain'] = json_encode($org['restricted_to_domain']);
|
||||||
}
|
}
|
||||||
if (!isset($this->data['Organisation']['id'])) {
|
if (!isset($org['id'])) {
|
||||||
$this->data['Organisation']['date_created'] = $date;
|
$org['date_created'] = $date;
|
||||||
}
|
}
|
||||||
$this->data['Organisation']['date_modified'] = $date;
|
$org['date_modified'] = $date;
|
||||||
if (!isset($this->data['Organisation']['nationality']) || empty($this->data['Organisation']['nationality'])) {
|
if (empty($org['nationality'])) {
|
||||||
$this->data['Organisation']['nationality'] = '';
|
$org['nationality'] = '';
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -206,13 +207,10 @@ class Organisation extends AppModel
|
||||||
'fields' => $fieldsToFetch,
|
'fields' => $fieldsToFetch,
|
||||||
));
|
));
|
||||||
if (empty($existingOrg)) {
|
if (empty($existingOrg)) {
|
||||||
$date = date('Y-m-d H:i:s');
|
|
||||||
$organisation = array(
|
$organisation = array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'local' => 0,
|
'local' => 0,
|
||||||
'created_by' => $user['id'],
|
'created_by' => $user['id'],
|
||||||
'date_modified' => $date,
|
|
||||||
'date_created' => $date
|
|
||||||
);
|
);
|
||||||
// If we have the UUID set, then we have only made sure that the org doesn't exist by UUID
|
// If we have the UUID set, then we have only made sure that the org doesn't exist by UUID
|
||||||
// We want to create a new organisation for pushed data, even if the same org name exists
|
// We want to create a new organisation for pushed data, even if the same org name exists
|
||||||
|
@ -229,17 +227,17 @@ class Organisation extends AppModel
|
||||||
return $this->id;
|
return $this->id;
|
||||||
} else {
|
} else {
|
||||||
$changed = false;
|
$changed = false;
|
||||||
if (isset($org['uuid']) && empty($existingOrg['Organisation']['uuid'])) {
|
if (isset($org['uuid']) && empty($existingOrg[$this->alias]['uuid'])) {
|
||||||
$existingOrg['Organisation']['uuid'] = $org['uuid'];
|
$existingOrg[$this->alias]['uuid'] = $org['uuid'];
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
if ($force) {
|
if ($force) {
|
||||||
$fields = array('type', 'date_created', 'date_modified', 'nationality', 'sector', 'contacts');
|
$fields = array('type', 'date_created', 'date_modified', 'nationality', 'sector', 'contacts');
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if (isset($org[$field])) {
|
if (isset($org[$field])) {
|
||||||
if ($existingOrg['Organisation'][$field] != $org[$field]) {
|
if ($existingOrg[$this->alias][$field] != $org[$field]) {
|
||||||
$existingOrg['Organisation'][$field] = $org[$field];
|
$existingOrg[$this->alias][$field] = $org[$field];
|
||||||
if ($field != 'date_modified') {
|
if ($field !== 'date_modified') {
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue