mirror of https://github.com/MISP/MISP
chg [galaxy] Simplify saving galaxies
parent
67fd15f543
commit
4af34a999c
|
@ -101,6 +101,11 @@ class Galaxy extends AppModel
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $galaxies
|
||||||
|
* @param array $cluster_package
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function __getPreExistingClusters(array $galaxies, array $cluster_package)
|
private function __getPreExistingClusters(array $galaxies, array $cluster_package)
|
||||||
{
|
{
|
||||||
$temp = $this->GalaxyCluster->find('all', array(
|
$temp = $this->GalaxyCluster->find('all', array(
|
||||||
|
@ -110,11 +115,7 @@ class Galaxy extends AppModel
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'fields' => array('version', 'id', 'value', 'uuid')
|
'fields' => array('version', 'id', 'value', 'uuid')
|
||||||
));
|
));
|
||||||
$existingClusters = [];
|
return array_column(array_column($temp, 'GalaxyCluster'), null, 'value');
|
||||||
foreach ($temp as $v) {
|
|
||||||
$existingClusters[$v['GalaxyCluster']['value']] = $v;
|
|
||||||
}
|
|
||||||
return $existingClusters;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function __deleteOutdated(bool $force, array $cluster_package, array $existingClusters)
|
private function __deleteOutdated(bool $force, array $cluster_package, array $existingClusters)
|
||||||
|
@ -132,19 +133,20 @@ class Galaxy extends AppModel
|
||||||
} else {
|
} else {
|
||||||
$cluster_package['values'][$k]['version'] = 0;
|
$cluster_package['values'][$k]['version'] = 0;
|
||||||
}
|
}
|
||||||
if (!empty($existingClusters[$cluster['value']])) {
|
if (isset($existingClusters[$cluster['value']])) {
|
||||||
if ($force || $existingClusters[$cluster['value']]['GalaxyCluster']['version'] < $cluster_package['values'][$k]['version']) {
|
$existing = $existingClusters[$cluster['value']];
|
||||||
$cluster_ids_to_delete[] = $existingClusters[$cluster['value']]['GalaxyCluster']['id'];
|
if ($force || $existing['version'] < $cluster_package['values'][$k]['version']) {
|
||||||
$cluster_uuids_to_delete[] = $existingClusters[$cluster['value']]['GalaxyCluster']['uuid'];
|
$cluster_ids_to_delete[] = $existing['id'];
|
||||||
|
$cluster_uuids_to_delete[] = $existing['uuid'];
|
||||||
} else {
|
} else {
|
||||||
unset($cluster_package['values'][$k]);
|
unset($cluster_package['values'][$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($cluster_ids_to_delete)) {
|
if (!empty($cluster_ids_to_delete)) {
|
||||||
$this->GalaxyCluster->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $cluster_ids_to_delete), false, false);
|
$this->GalaxyCluster->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $cluster_ids_to_delete), false);
|
||||||
$this->GalaxyCluster->GalaxyClusterRelation->deleteRelations(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $cluster_uuids_to_delete));
|
$this->GalaxyCluster->GalaxyClusterRelation->deleteAll(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $cluster_uuids_to_delete));
|
||||||
$this->GalaxyCluster->deleteAll(array('GalaxyCluster.id' => $cluster_ids_to_delete), false, false);
|
$this->GalaxyCluster->deleteAll(array('GalaxyCluster.id' => $cluster_ids_to_delete), false);
|
||||||
}
|
}
|
||||||
return $cluster_package;
|
return $cluster_package;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ App::uses('TmpFileTool', 'Tools');
|
||||||
/**
|
/**
|
||||||
* @property Tag $Tag
|
* @property Tag $Tag
|
||||||
* @property GalaxyClusterRelation $GalaxyClusterRelation
|
* @property GalaxyClusterRelation $GalaxyClusterRelation
|
||||||
|
* @property GalaxyElement $GalaxyElement
|
||||||
*/
|
*/
|
||||||
class GalaxyCluster extends AppModel
|
class GalaxyCluster extends AppModel
|
||||||
{
|
{
|
||||||
|
|
|
@ -157,11 +157,6 @@ class GalaxyClusterRelation extends AppModel
|
||||||
return array_unique(array_merge($existingRelationships, $objectRelationships));
|
return array_unique(array_merge($existingRelationships, $objectRelationships));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteRelations($conditions)
|
|
||||||
{
|
|
||||||
$this->deleteAll($conditions, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saveRelations
|
* saveRelations
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue