2017-08-21 10:13:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
class ObjectRelationship extends AppModel
|
|
|
|
{
|
|
|
|
public $actsAs = array(
|
|
|
|
'Containable',
|
|
|
|
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
|
|
|
'userModel' => 'User',
|
|
|
|
'userKey' => 'user_id',
|
|
|
|
'change' => 'full'),
|
|
|
|
);
|
2017-08-21 10:13:19 +02:00
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
public $validate = array(
|
|
|
|
'name' => array(
|
|
|
|
'unique' => array(
|
|
|
|
'rule' => 'isUnique',
|
|
|
|
'message' => 'A relationship with this name already exists.'
|
|
|
|
),
|
|
|
|
'valueNotEmpty' => array(
|
|
|
|
'rule' => array('valueNotEmpty'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2017-08-21 10:13:19 +02:00
|
|
|
|
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
public function beforeValidate($options = array())
|
|
|
|
{
|
|
|
|
parent::beforeValidate();
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-21 10:13:19 +02:00
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
public function afterFind($results, $primary = false)
|
|
|
|
{
|
|
|
|
foreach ($results as $k => $result) {
|
|
|
|
if (!empty($results[$k]['ObjectRelationship']['format'])) {
|
|
|
|
$results[$k]['ObjectRelationship']['format'] = json_decode($results[$k]['ObjectRelationship']['format'], true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
2017-08-21 10:13:19 +02:00
|
|
|
|
2018-07-19 11:48:22 +02:00
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
$relationsFile = APP . 'files/misp-objects/relationships/definition.json';
|
|
|
|
if (file_exists($relationsFile)) {
|
|
|
|
$file = new File($relationsFile);
|
|
|
|
$relations = json_decode($file->read(), true);
|
|
|
|
if (!isset($relations['version'])) {
|
|
|
|
$relations['version'] = 1;
|
|
|
|
}
|
|
|
|
$this->deleteAll(array('version <' => $relations['version']));
|
|
|
|
foreach ($relations['values'] as $k => $relation) {
|
|
|
|
$relation['format'] = json_encode($relation['format'], true);
|
|
|
|
$relation['version'] = $relations['version'];
|
|
|
|
$this->create();
|
|
|
|
$this->save($relation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-21 10:13:19 +02:00
|
|
|
}
|