Loading src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php +2 −2 Changes for src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ class SqlHelperService if ($source !== null) $columns[] = 'source_id'; $values = []; foreach ($correspondance as $s => $d) { $values[] = $this->echapValue($item[$s]); $values[] = $this->echapValue($item[$s]??null); } $values[] = "now()"; if ($source !== null) $values[] = "'" . $source . "'"; Loading @@ -106,7 +106,7 @@ class SqlHelperService { $values = []; foreach ($correspondance as $s => $d) { $values[] = $d . "=" . $this->echapValue($item[$s]); $values[] = $d . "=" . $this->echapValue($item[$s]??null); } if ($source !== null) $values[] = "source_id='" . $source . "'"; $values[] = "updated_on=now()"; Loading src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php +41 −15 Changes for src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php: 41 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class SynchronisationService private function checkDifferences(array $itemSource, array $itemDestination, array $correspondance, ?string $source = null): bool { foreach ($correspondance as $idSource => $idCorrespondance) { if ($itemSource[$idSource] != $itemDestination[$idCorrespondance]) { if (($itemSource[$idSource]??null) != $itemDestination[$idCorrespondance]) { // var_dump($itemSource[$idSource]); // var_dump($itemDestination[$idCorrespondance]); // var_dump("Diff: " . $idSource . " >>> " . $itemSource[$idSource] . "!=" . $itemDestination[$idCorrespondance]); Loading Loading @@ -103,21 +103,9 @@ class SynchronisationService exit(404); } /** Si WebService ****************************************************************************************/ if ($ws_source !== null) { $entity = $this->getFromConfig($name, 'entity'); $table_destination = $this->getFromConfig($name, 'table_destination'); $id_source = $this->getFromConfig($name, 'id'); $source = $this->getFromConfig($name, 'source'); $id_destination = $correspondance[$id_source]; try { $data_source = $this->getWebServiceReaderService()->fetch($ws_source, $entity); } catch (GuzzleException $e) { throw new RuntimeException("Une erreur est survenue lors de la lecteur des données depuis le WebService",$e->getCode(), $e); } $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, null, null, $source); echo count($data_source) . " entrées dans les données sources.\n"; $this->doSynchronisation($name, $data_source, $data_destination); $this->doSynchronisationForWebService($name); } if ($orm_source) { Loading Loading @@ -173,6 +161,44 @@ class SynchronisationService } public function doSynchronisationForWebService(string $name): void { $correspondance = $this->getFromConfig($name, 'correspondance'); $format = $this->getFromConfig($name, 'format'); $ws_source = $this->webServices[$this->getFromConfig($name, 'web_service')]; $orm_destination = $this->entityManagers[$this->getFromConfig($name, 'orm_destination')]; $entity = $this->getFromConfig($name, 'entity'); $table_destination = $this->getFromConfig($name, 'table_destination'); $id_source = $this->getFromConfig($name, 'id'); $source = $this->getFromConfig($name, 'source'); $id_destination = $correspondance[$id_source]; try { if (strtolower($format) === 'ldjson') { $data_fetched = $this->getWebServiceReaderService()->fetchLdJson($ws_source, $entity); $data_source = []; foreach ($data_fetched as $row) { $data_source[$row[$id_source]] = $row; } } elseif ($format === 'json') { $data_fetched = $this->getWebServiceReaderService()->fetchJson($ws_source, $entity); $data_source = []; foreach ($data_fetched as $row) { $data_source[$row[$id_source]] = $row; } }else { throw new RuntimeException("Format non transmis ou inconnu"); } } catch (GuzzleException $e) { throw new RuntimeException("Une erreur est survenue lors de la lecteur des données depuis le WebService",$e->getCode(), $e); } $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, null, null, $source); echo count($data_source) . " entrées dans les données sources.\n"; $this->doSynchronisation($name, $data_source, $data_destination); } private function doSynchronisation(string $name, array $data_source, array $data_destination): void { Loading src/UnicaenSynchro/Service/WebServiceReader/WebServiceReaderService.php +24 −19 Changes for src/UnicaenSynchro/Service/WebServiceReader/WebServiceReaderService.php: 24 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -15,24 +15,8 @@ class WebServiceReaderService { /** * @throws GuzzleException */ public function fetch(array $webserviceConfig, string $entities): array public function fetchLdJson(array $webserviceConfig, string $entities): array { $data = []; $data['U01'] = [ 'COD_CMP' => 'U01', 'LIB_CMP' => 'UFR Sciences', 'LIB_LONG_CMP' => 'UFR des Sciences Numériques', 'LIC_CMP' => 'SN', ]; $data['U02'] = [ 'COD_CMP' => 'U02', 'LIB_CMP' => 'UFR LVE', 'LIB_LONG_CMP' => 'UFR Langues vivantes et étrangères', 'LIC_CMP' => 'LVE', ]; return $data; $client = new Client([ 'verify' => false ]); Loading @@ -40,7 +24,7 @@ class WebServiceReaderService { $url = $entities; do { $response = $client->request('GET', $this->buildUrl($webserviceConfig['host'], $url), [ 'auth' => [$webserviceConfig['user'], $webserviceConfig['password']], 'auth' => [$webserviceConfig['user']??null, $webserviceConfig['password']??null], 'headers' => [ 'Accept' => 'application/ld+json' ] Loading @@ -56,10 +40,31 @@ class WebServiceReaderService { } while ($url !== null); // Continue if there is a next page return $allData; } /** * @throws GuzzleException */ public function fetchJson(array $webserviceConfig, string $entities): array { $client = new Client([ 'verify' => false ]); $url = $entities; return $allData; $response = $client->request('GET', $this->buildUrl($webserviceConfig['host'], $url), [ 'auth' => [$webserviceConfig['user']??null, $webserviceConfig['password']??null], 'headers' => [ 'Accept' => 'application/json' ] ]); $data = json_decode($response->getBody(), true); return $data; } Loading Loading
src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php +2 −2 Changes for src/UnicaenSynchro/Service/SqlHelper/SqlHelperService.php: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ class SqlHelperService if ($source !== null) $columns[] = 'source_id'; $values = []; foreach ($correspondance as $s => $d) { $values[] = $this->echapValue($item[$s]); $values[] = $this->echapValue($item[$s]??null); } $values[] = "now()"; if ($source !== null) $values[] = "'" . $source . "'"; Loading @@ -106,7 +106,7 @@ class SqlHelperService { $values = []; foreach ($correspondance as $s => $d) { $values[] = $d . "=" . $this->echapValue($item[$s]); $values[] = $d . "=" . $this->echapValue($item[$s]??null); } if ($source !== null) $values[] = "source_id='" . $source . "'"; $values[] = "updated_on=now()"; Loading
src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php +41 −15 Changes for src/UnicaenSynchro/Service/Synchronisation/SynchronisationService.php: 41 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ class SynchronisationService private function checkDifferences(array $itemSource, array $itemDestination, array $correspondance, ?string $source = null): bool { foreach ($correspondance as $idSource => $idCorrespondance) { if ($itemSource[$idSource] != $itemDestination[$idCorrespondance]) { if (($itemSource[$idSource]??null) != $itemDestination[$idCorrespondance]) { // var_dump($itemSource[$idSource]); // var_dump($itemDestination[$idCorrespondance]); // var_dump("Diff: " . $idSource . " >>> " . $itemSource[$idSource] . "!=" . $itemDestination[$idCorrespondance]); Loading Loading @@ -103,21 +103,9 @@ class SynchronisationService exit(404); } /** Si WebService ****************************************************************************************/ if ($ws_source !== null) { $entity = $this->getFromConfig($name, 'entity'); $table_destination = $this->getFromConfig($name, 'table_destination'); $id_source = $this->getFromConfig($name, 'id'); $source = $this->getFromConfig($name, 'source'); $id_destination = $correspondance[$id_source]; try { $data_source = $this->getWebServiceReaderService()->fetch($ws_source, $entity); } catch (GuzzleException $e) { throw new RuntimeException("Une erreur est survenue lors de la lecteur des données depuis le WebService",$e->getCode(), $e); } $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, null, null, $source); echo count($data_source) . " entrées dans les données sources.\n"; $this->doSynchronisation($name, $data_source, $data_destination); $this->doSynchronisationForWebService($name); } if ($orm_source) { Loading Loading @@ -173,6 +161,44 @@ class SynchronisationService } public function doSynchronisationForWebService(string $name): void { $correspondance = $this->getFromConfig($name, 'correspondance'); $format = $this->getFromConfig($name, 'format'); $ws_source = $this->webServices[$this->getFromConfig($name, 'web_service')]; $orm_destination = $this->entityManagers[$this->getFromConfig($name, 'orm_destination')]; $entity = $this->getFromConfig($name, 'entity'); $table_destination = $this->getFromConfig($name, 'table_destination'); $id_source = $this->getFromConfig($name, 'id'); $source = $this->getFromConfig($name, 'source'); $id_destination = $correspondance[$id_source]; try { if (strtolower($format) === 'ldjson') { $data_fetched = $this->getWebServiceReaderService()->fetchLdJson($ws_source, $entity); $data_source = []; foreach ($data_fetched as $row) { $data_source[$row[$id_source]] = $row; } } elseif ($format === 'json') { $data_fetched = $this->getWebServiceReaderService()->fetchJson($ws_source, $entity); $data_source = []; foreach ($data_fetched as $row) { $data_source[$row[$id_source]] = $row; } }else { throw new RuntimeException("Format non transmis ou inconnu"); } } catch (GuzzleException $e) { throw new RuntimeException("Une erreur est survenue lors de la lecteur des données depuis le WebService",$e->getCode(), $e); } $data_destination = $this->getSqlHelperService()->fetch($orm_destination, $table_destination, $correspondance, 'destination', $id_destination, null, null, $source); echo count($data_source) . " entrées dans les données sources.\n"; $this->doSynchronisation($name, $data_source, $data_destination); } private function doSynchronisation(string $name, array $data_source, array $data_destination): void { Loading
src/UnicaenSynchro/Service/WebServiceReader/WebServiceReaderService.php +24 −19 Changes for src/UnicaenSynchro/Service/WebServiceReader/WebServiceReaderService.php: 24 added lines, 19 removed lines. Original line number Diff line number Diff line Loading @@ -15,24 +15,8 @@ class WebServiceReaderService { /** * @throws GuzzleException */ public function fetch(array $webserviceConfig, string $entities): array public function fetchLdJson(array $webserviceConfig, string $entities): array { $data = []; $data['U01'] = [ 'COD_CMP' => 'U01', 'LIB_CMP' => 'UFR Sciences', 'LIB_LONG_CMP' => 'UFR des Sciences Numériques', 'LIC_CMP' => 'SN', ]; $data['U02'] = [ 'COD_CMP' => 'U02', 'LIB_CMP' => 'UFR LVE', 'LIB_LONG_CMP' => 'UFR Langues vivantes et étrangères', 'LIC_CMP' => 'LVE', ]; return $data; $client = new Client([ 'verify' => false ]); Loading @@ -40,7 +24,7 @@ class WebServiceReaderService { $url = $entities; do { $response = $client->request('GET', $this->buildUrl($webserviceConfig['host'], $url), [ 'auth' => [$webserviceConfig['user'], $webserviceConfig['password']], 'auth' => [$webserviceConfig['user']??null, $webserviceConfig['password']??null], 'headers' => [ 'Accept' => 'application/ld+json' ] Loading @@ -56,10 +40,31 @@ class WebServiceReaderService { } while ($url !== null); // Continue if there is a next page return $allData; } /** * @throws GuzzleException */ public function fetchJson(array $webserviceConfig, string $entities): array { $client = new Client([ 'verify' => false ]); $url = $entities; return $allData; $response = $client->request('GET', $this->buildUrl($webserviceConfig['host'], $url), [ 'auth' => [$webserviceConfig['user']??null, $webserviceConfig['password']??null], 'headers' => [ 'Accept' => 'application/json' ] ]); $data = json_decode($response->getBody(), true); return $data; } Loading