From 5acf0a922c116ba46c2b1e3c4806ab761321d186 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 4 Mar 2024 15:36:34 +0100 Subject: [PATCH] fix: [pull] Fix pulling from remote server when analyst data is not supported --- app/Lib/Tools/ServerSyncTool.php | 17 +++++++++-------- app/Model/AnalystData.php | 12 +++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/Lib/Tools/ServerSyncTool.php b/app/Lib/Tools/ServerSyncTool.php index ce8088f2423..ca2efe9eeca 100644 --- a/app/Lib/Tools/ServerSyncTool.php +++ b/app/Lib/Tools/ServerSyncTool.php @@ -217,7 +217,7 @@ public function pushGalaxyCluster(array $cluster) } /** - * @param array $rules + * @param array $candidates * @return HttpSocketResponseExtended * @throws HttpSocketHttpException * @throws HttpSocketJsonException @@ -225,7 +225,7 @@ public function pushGalaxyCluster(array $cluster) public function filterAnalystDataForPush(array $candidates) { if (!$this->isSupported(self::PERM_ANALYST_DATA)) { - return []; + throw new RuntimeException("Remote server do not support analyst data"); } return $this->post('/analyst_data/filterAnalystDataForPush', $candidates); @@ -240,20 +240,23 @@ public function filterAnalystDataForPush(array $candidates) public function fetchIndexMinimal(array $rules) { if (!$this->isSupported(self::PERM_ANALYST_DATA)) { - return []; + throw new RuntimeException("Remote server do not support analyst data"); } return $this->post('/analyst_data/indexMinimal', $rules); } /** + * @param string $type + * @param array $uuids + * @return HttpSocketResponseExtended * @throws HttpSocketJsonException * @throws HttpSocketHttpException */ public function fetchAnalystData($type, array $uuids) { if (!$this->isSupported(self::PERM_ANALYST_DATA)) { - return []; + throw new RuntimeException("Remote server do not support analyst data"); } $params = [ @@ -264,12 +267,10 @@ public function fetchAnalystData($type, array $uuids) $url .= $this->createParams($params); $url .= '.json'; return $this->get($url); - - // $response = $this->post('/analyst_data/restSearch' , $params); - // return $response->json(); } - /** + /** + * @param string $type * @param array $analystData * @return HttpSocketResponseExtended * @throws HttpSocketHttpException diff --git a/app/Model/AnalystData.php b/app/Model/AnalystData.php index 6594d2d325c..16e0ae1710a 100644 --- a/app/Model/AnalystData.php +++ b/app/Model/AnalystData.php @@ -1007,9 +1007,14 @@ private function updateAnalystDataForSync($type, array $analystData, array $serv * * @param array $user * @param ServerSyncTool $serverSync + * @return int Number of saved analysis */ public function pull(array $user, ServerSyncTool $serverSync) { + if (!$serverSync->isSupported(ServerSyncTool::PERM_ANALYST_DATA)) { + return 0; + } + $this->Server = ClassRegistry::init('Server'); $this->AnalystData = ClassRegistry::init('AnalystData'); try { @@ -1051,14 +1056,11 @@ public function pull(array $user, ServerSyncTool $serverSync) return 0; } - if ($serverSync->isSupported(ServerSyncTool::PERM_ANALYST_DATA)) { - return $this->pullInChunks($user, $remoteUUIDsToFetch, $serverSync); - } + return $this->pullInChunks($user, $remoteUUIDsToFetch, $serverSync); } - public function pullInChunks(array $user, array $analystDataUuids, ServerSyncTool $serverSync) + private function pullInChunks(array $user, array $analystDataUuids, ServerSyncTool $serverSync) { - $uuids = array_keys($analystDataUuids); $saved = 0; $serverOrgUUID = $this->Org->find('first', [ 'recursive' => -1,