From a5cdf1293cb1c99d92c9dd7f558e05bbfceabae5 Mon Sep 17 00:00:00 2001 From: Yaraslau Kavaliou Date: Tue, 17 Oct 2023 01:22:11 +0300 Subject: [PATCH] feat: Add logging for graph db installation --- scripts/install/CleanGraphDatabase.php | 20 ++++++++++++++ scripts/install/EnableGraphDatabase.php | 36 ++++++++++++++++++++----- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/scripts/install/CleanGraphDatabase.php b/scripts/install/CleanGraphDatabase.php index 6a9c30cc26..eb7851746e 100644 --- a/scripts/install/CleanGraphDatabase.php +++ b/scripts/install/CleanGraphDatabase.php @@ -22,13 +22,21 @@ namespace oat\tao\scripts\install; +use common_persistence_GraphPersistence; use common_persistence_Manager; use oat\oatbox\extension\InstallAction; +use oat\oatbox\log\ColoredVerboseLogger; +use oat\oatbox\log\LoggerAwareTrait; +use Psr\Log\LogLevel; class CleanGraphDatabase extends InstallAction { + use LoggerAwareTrait; + public function __invoke($params) { + $this->setLogger(new ColoredVerboseLogger(LogLevel::INFO)); + $persistenceId = $params[0]; if (empty($persistenceId)) { throw new \common_Exception('Persistence id should be provided in script parameters'); @@ -38,7 +46,19 @@ public function __invoke($params) ->get(common_persistence_Manager::SERVICE_ID) ->getPersistenceById($persistenceId); + $this->removeNodes($persistence); + $this->removeConstraints($persistence); + + $this->logInfo(sprintf('Data from "%s" persistence has been cleared', $persistenceId)); + } + + private function removeNodes(common_persistence_GraphPersistence $persistence) + { $persistence->run('MATCH (n) DETACH DELETE n'); + } + + private function removeConstraints(common_persistence_GraphPersistence $persistence) + { $persistence->run('CALL apoc.schema.assert({}, {}, true) YIELD label, key RETURN *'); } } diff --git a/scripts/install/EnableGraphDatabase.php b/scripts/install/EnableGraphDatabase.php index 67872edd38..2e795b2e58 100644 --- a/scripts/install/EnableGraphDatabase.php +++ b/scripts/install/EnableGraphDatabase.php @@ -22,29 +22,46 @@ namespace oat\tao\scripts\install; -use core_kernel_persistence_smoothsql_SmoothModel; use core_kernel_persistence_starsql_StarModel; use oat\generis\model\data\Ontology; use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService; use oat\oatbox\extension\InstallAction; +use oat\oatbox\log\ColoredVerboseLogger; +use oat\oatbox\log\LoggerAwareTrait; +use Psr\Log\LogLevel; class EnableGraphDatabase extends InstallAction { + use LoggerAwareTrait; + public function __invoke($params) { + $this->setLogger(new ColoredVerboseLogger(LogLevel::INFO)); + $persistenceId = $params[0]; if (empty($persistenceId)) { throw new \common_Exception('Persistence id should be provided in script parameters'); } - $sm = $this->getServiceManager(); + $this->updateOntologyService($persistenceId); + $this->updateComplexSearchService(); + } - $ontologyService = $sm->get(Ontology::SERVICE_ID); + private function updateOntologyService($persistenceId) + { + $ontologyService = $this->getServiceManager()->get(Ontology::SERVICE_ID); $serviceOptions = $ontologyService->getOptions(); - $serviceOptions[core_kernel_persistence_smoothsql_SmoothModel::OPTION_PERSISTENCE] = $persistenceId; - $sm->register(Ontology::SERVICE_ID, new core_kernel_persistence_starsql_StarModel($serviceOptions)); + $serviceOptions[core_kernel_persistence_starsql_StarModel::OPTION_PERSISTENCE] = $persistenceId; + $this + ->getServiceManager() + ->register(Ontology::SERVICE_ID, new core_kernel_persistence_starsql_StarModel($serviceOptions)); - $complexSearchService = $sm->get(ComplexSearchService::SERVICE_ID); + $this->logInfo(sprintf('"%s" persistence has been set for ontology service', $persistenceId)); + } + + private function updateComplexSearchService() + { + $complexSearchService = $this->getServiceManager()->get(ComplexSearchService::SERVICE_ID); $serviceOptions = $complexSearchService->getOptions(); $serviceOptions['shared']['search.neo4j.serialyser'] = false; $serviceOptions['invokables']['search.driver.neo4j'] = @@ -53,6 +70,11 @@ public function __invoke($params) '\\oat\\generis\\model\\kernel\\persistence\\starsql\\search\\QuerySerializer'; $serviceOptions['invokables']['search.tao.gateway'] = '\\oat\\generis\\model\\kernel\\persistence\\starsql\\search\\GateWay'; - $sm->register(ComplexSearchService::SERVICE_ID, new ComplexSearchService($serviceOptions)); + $this + ->getServiceManager() + ->register(ComplexSearchService::SERVICE_ID, new ComplexSearchService($serviceOptions)); + + $this + ->logInfo('ComplexSearch service has been updated to compliant with graph database'); } }