From 90cca98feb97aeee74f5c76894d8ca4eacb70559 Mon Sep 17 00:00:00 2001 From: Vladimir Malik Date: Fri, 27 Sep 2024 09:07:56 +0200 Subject: [PATCH] Use constant for 'datahub_context' instead hardcoded value (#880) * Use constant for 'datahub_context' instead hardcoded value * Removed unused variable $context in DocumentTreeType. * Removed unused imports. --- src/Controller/WebserviceController.php | 4 ++-- src/GraphQL/ClassTypeDefinitions.php | 3 ++- src/GraphQL/DataObjectType/ObjectTreeType.php | 3 ++- src/GraphQL/DocumentType/DocumentTreeType.php | 3 --- src/GraphQL/Service.php | 2 +- src/WorkspaceHelper.php | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Controller/WebserviceController.php b/src/Controller/WebserviceController.php index 5a26f818..865a8ced 100644 --- a/src/Controller/WebserviceController.php +++ b/src/Controller/WebserviceController.php @@ -121,8 +121,8 @@ public function webonyxAction( PimcoreDataHubBundle::setNotAllowedPolicy($config['graphql']['not_allowed_policy']); } - $longRunningHelper->addPimcoreRuntimeCacheProtectedItems(['datahub_context']); - RuntimeCache::set('datahub_context', $context); + $longRunningHelper->addPimcoreRuntimeCacheProtectedItems([PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY]); + RuntimeCache::set(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY, $context); ClassTypeDefinitions::build($service, $context); diff --git a/src/GraphQL/ClassTypeDefinitions.php b/src/GraphQL/ClassTypeDefinitions.php index 3cbc3776..7ff94c7b 100644 --- a/src/GraphQL/ClassTypeDefinitions.php +++ b/src/GraphQL/ClassTypeDefinitions.php @@ -18,6 +18,7 @@ use Pimcore\Bundle\DataHubBundle\Configuration; use Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType\PimcoreObjectType; use Pimcore\Bundle\DataHubBundle\GraphQL\Exception\ClientSafeException; +use Pimcore\Bundle\DataHubBundle\PimcoreDataHubBundle; use Pimcore\Cache\RuntimeCache; use Pimcore\Db; use Pimcore\Model\DataObject\ClassDefinition; @@ -81,7 +82,7 @@ public static function get($class) public static function getAll($onlyQueryTypes = false) { if ($onlyQueryTypes) { - $context = RuntimeCache::get('datahub_context'); + $context = RuntimeCache::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY); /** @var Configuration $configuration */ $configuration = $context['configuration']; $types = array_keys($configuration->getConfiguration()['schema']['queryEntities']); diff --git a/src/GraphQL/DataObjectType/ObjectTreeType.php b/src/GraphQL/DataObjectType/ObjectTreeType.php index 55607fd4..d8cb12eb 100644 --- a/src/GraphQL/DataObjectType/ObjectTreeType.php +++ b/src/GraphQL/DataObjectType/ObjectTreeType.php @@ -22,6 +22,7 @@ use Pimcore\Bundle\DataHubBundle\GraphQL\ClassTypeDefinitions; use Pimcore\Bundle\DataHubBundle\GraphQL\Service; use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait; +use Pimcore\Bundle\DataHubBundle\PimcoreDataHubBundle; use Pimcore\Cache\RuntimeCache; use Pimcore\Model\DataObject; use Symfony\Component\DependencyInjection\ContainerAwareInterface; @@ -47,7 +48,7 @@ public function __construct(Service $graphQlService, $config = ['name' => 'objec */ public function getTypes(): array { - $context = RuntimeCache::get('datahub_context'); + $context = RuntimeCache::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY); /** @var Configuration $configuration */ $configuration = $context['configuration']; diff --git a/src/GraphQL/DocumentType/DocumentTreeType.php b/src/GraphQL/DocumentType/DocumentTreeType.php index 53222dbe..0ad05cf9 100644 --- a/src/GraphQL/DocumentType/DocumentTreeType.php +++ b/src/GraphQL/DocumentType/DocumentTreeType.php @@ -20,7 +20,6 @@ use GraphQL\Type\Definition\UnionType; use Pimcore\Bundle\DataHubBundle\GraphQL\Service; use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait; -use Pimcore\Cache\RuntimeCache; use Pimcore\Model\Document; use Pimcore\Model\Element\ElementInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; @@ -50,8 +49,6 @@ public function __construct(Service $graphQlService, $config = ['name' => 'docum */ public function getTypes(): array { - $context = RuntimeCache::get('datahub_context'); - $types = []; $supportedTypes = [ diff --git a/src/GraphQL/Service.php b/src/GraphQL/Service.php index ae90ff98..d637beae 100644 --- a/src/GraphQL/Service.php +++ b/src/GraphQL/Service.php @@ -1145,7 +1145,7 @@ public function extractData($data, $target, $args = [], $context = [], ResolveIn */ public function querySchemaEnabled(string $type) { - $context = RuntimeCache::get('datahub_context'); + $context = RuntimeCache::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY); /** @var Configuration $configuration */ $configuration = $context['configuration']; if ($type === 'object') { diff --git a/src/WorkspaceHelper.php b/src/WorkspaceHelper.php index d6a04bb6..30ab3040 100644 --- a/src/WorkspaceHelper.php +++ b/src/WorkspaceHelper.php @@ -222,7 +222,7 @@ public static function deleteConfiguration(Configuration $config) */ public static function checkPermission($element, $type) { - $context = RuntimeCache::get('datahub_context'); + $context = RuntimeCache::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY); /** @var Configuration $configuration */ $configuration = $context['configuration'];