From 4af34a999cf8f94539100d1188bd5634a1c603d3 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sun, 27 Mar 2022 18:45:14 +0200 Subject: [PATCH] chg [galaxy] Simplify saving galaxies --- app/Model/Galaxy.php | 26 ++++++++++++++------------ app/Model/GalaxyCluster.php | 1 + app/Model/GalaxyClusterRelation.php | 5 ----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/Model/Galaxy.php b/app/Model/Galaxy.php index a14da5c44..8faa91fa4 100644 --- a/app/Model/Galaxy.php +++ b/app/Model/Galaxy.php @@ -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) { $temp = $this->GalaxyCluster->find('all', array( @@ -110,11 +115,7 @@ class Galaxy extends AppModel 'recursive' => -1, 'fields' => array('version', 'id', 'value', 'uuid') )); - $existingClusters = []; - foreach ($temp as $v) { - $existingClusters[$v['GalaxyCluster']['value']] = $v; - } - return $existingClusters; + return array_column(array_column($temp, 'GalaxyCluster'), null, 'value'); } private function __deleteOutdated(bool $force, array $cluster_package, array $existingClusters) @@ -132,19 +133,20 @@ class Galaxy extends AppModel } else { $cluster_package['values'][$k]['version'] = 0; } - if (!empty($existingClusters[$cluster['value']])) { - if ($force || $existingClusters[$cluster['value']]['GalaxyCluster']['version'] < $cluster_package['values'][$k]['version']) { - $cluster_ids_to_delete[] = $existingClusters[$cluster['value']]['GalaxyCluster']['id']; - $cluster_uuids_to_delete[] = $existingClusters[$cluster['value']]['GalaxyCluster']['uuid']; + if (isset($existingClusters[$cluster['value']])) { + $existing = $existingClusters[$cluster['value']]; + if ($force || $existing['version'] < $cluster_package['values'][$k]['version']) { + $cluster_ids_to_delete[] = $existing['id']; + $cluster_uuids_to_delete[] = $existing['uuid']; } else { unset($cluster_package['values'][$k]); } } } if (!empty($cluster_ids_to_delete)) { - $this->GalaxyCluster->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $cluster_ids_to_delete), false, false); - $this->GalaxyCluster->GalaxyClusterRelation->deleteRelations(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $cluster_uuids_to_delete)); - $this->GalaxyCluster->deleteAll(array('GalaxyCluster.id' => $cluster_ids_to_delete), false, false); + $this->GalaxyCluster->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $cluster_ids_to_delete), false); + $this->GalaxyCluster->GalaxyClusterRelation->deleteAll(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $cluster_uuids_to_delete)); + $this->GalaxyCluster->deleteAll(array('GalaxyCluster.id' => $cluster_ids_to_delete), false); } return $cluster_package; } diff --git a/app/Model/GalaxyCluster.php b/app/Model/GalaxyCluster.php index addfdb26a..ef62bea99 100644 --- a/app/Model/GalaxyCluster.php +++ b/app/Model/GalaxyCluster.php @@ -5,6 +5,7 @@ App::uses('TmpFileTool', 'Tools'); /** * @property Tag $Tag * @property GalaxyClusterRelation $GalaxyClusterRelation + * @property GalaxyElement $GalaxyElement */ class GalaxyCluster extends AppModel { diff --git a/app/Model/GalaxyClusterRelation.php b/app/Model/GalaxyClusterRelation.php index 00b69153b..7119c9417 100644 --- a/app/Model/GalaxyClusterRelation.php +++ b/app/Model/GalaxyClusterRelation.php @@ -157,11 +157,6 @@ class GalaxyClusterRelation extends AppModel return array_unique(array_merge($existingRelationships, $objectRelationships)); } - public function deleteRelations($conditions) - { - $this->deleteAll($conditions, false, false); - } - /** * saveRelations *