Skip to content

Commit

Permalink
Merge pull request #11 from dachcom-digital/resource_candiate
Browse files Browse the repository at this point in the history
add missing resource proxy option resolver, deprecate proxy services
  • Loading branch information
solverat authored May 27, 2021
2 parents 64c3331 + 1baff47 commit 0cf79d4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,6 @@ Returns real full path of document

Return Type: `string|null`
Options: none

## Upgrade Info
Before updating, please [check our upgrade notes!](UPGRADE.md)
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Upgrade Notes
***

#### Update from Version 1.0.0 to Version 1.0.1
- **[BUGFIX]**: Fix missing Resource Proxy Option Resolver [#10](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-trinity/issues/10)
- **[BUGFIX]**: ObjectRelationGetterExtractor call_user_func call uses the wrong signature [@ThisIsJustARandomGuy](https://github.com/dachcom-digital/pimcore-dynamic-search-data-provider-trinity/issues/8)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
final class ProxyResolverPass implements CompilerPassInterface
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/DsTrinityDataBundle/Event/DataProxyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use DynamicSearchBundle\Resource\Proxy\ProxyResourceInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
class DataProxyEvent extends Event
{
/**
Expand Down
29 changes: 28 additions & 1 deletion src/DsTrinityDataBundle/Provider/TrinityDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use DynamicSearchBundle\Context\ContextDefinitionInterface;
use DynamicSearchBundle\Normalizer\Resource\ResourceMetaInterface;
use DynamicSearchBundle\Provider\DataProviderInterface;
use DynamicSearchBundle\Provider\DataProviderValidationAwareInterface;
use DynamicSearchBundle\Resource\ResourceCandidateInterface;
use Pimcore\Model\Asset;
use Pimcore\Model\DataObject;
use Pimcore\Model\Document;
use Pimcore\Model\Element\ElementInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TrinityDataProvider implements DataProviderInterface
class TrinityDataProvider implements DataProviderInterface, DataProviderValidationAwareInterface
{
/**
* @var DataProviderServiceInterface
Expand Down Expand Up @@ -158,6 +160,31 @@ public function validateUntrustedResource(ContextDefinitionInterface $contextDef
return $this->dataProvider->validate($resource);
}

/**
* {@inheritdoc}
*/
public function validateResource(ContextDefinitionInterface $contextDefinition, ResourceCandidateInterface $resourceCandidate)
{
// we're only able to validate elements here
$resource = $resourceCandidate->getResource();

if (!$resource instanceof ElementInterface) {
$resourceCandidate->setResource(null);

return $resourceCandidate;
}

$this->setupDataProvider($contextDefinition);

$isValidResource = $this->dataProvider->validate($resource);

if ($isValidResource === false) {
$resourceCandidate->setResource(null);
}

return $resourceCandidate;
}

/**
* {@inheritdoc}
*/
Expand Down
3 changes: 3 additions & 0 deletions src/DsTrinityDataBundle/Registry/ProxyResolverRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DsTrinityDataBundle\Resource\ProxyResolver\ProxyResolverInterface;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
class ProxyResolverRegistry implements ProxyResolverRegistryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DsTrinityDataBundle\Resource\ProxyResolver\ProxyResolverInterface;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
interface ProxyResolverRegistryInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
class ObjectProxyResolver implements ProxyResolverInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Pimcore\Model\Element\ElementInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @deprecated since 1.0.0 and will be removed in 2.0.0.
*/
interface ProxyResolverInterface
{
/**
Expand Down
16 changes: 9 additions & 7 deletions src/DsTrinityDataBundle/Service/DataProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public function checkResourceProxy(ElementInterface $resource)
return null;
}

$options = $this->getTypeOptions($type);
$proxyIdentifier = sprintf('%s_proxy_identifier', $type);
$proxyOptionsIdentifier = sprintf('%s_proxy_settings', $type);

if (!isset($this->indexOptions[$proxyIdentifier])) {
if (!isset($options[$proxyIdentifier])) {
return null;
}

$options = $this->getTypeOptions($type);
if (!isset($options[$proxyOptionsIdentifier])) {
return null;
}
Expand All @@ -137,7 +137,9 @@ public function checkResourceProxy(ElementInterface $resource)
$optionsResolver = new OptionsResolver();
$proxyResolver->configureOptions($optionsResolver);

return $proxyResolver->resolveProxy($resource, $options, ['contextDispatchType' => $this->contextDispatchType, 'contextName' => $this->contextName]);
$proxyOptions = $optionsResolver->resolve($options[$proxyOptionsIdentifier]);

return $proxyResolver->resolveProxy($resource, $proxyOptions, ['contextDispatchType' => $this->contextDispatchType, 'contextName' => $this->contextName]);
}

/**
Expand Down Expand Up @@ -229,10 +231,10 @@ protected function fetchByType(string $type, string $providerBehaviour)
}

/**
* @param string $type
* @param string $providerBehaviour
* @param int $id
* @param ResourceMetaInterface $resourceMeta
* @param string $type
* @param string $providerBehaviour
* @param int $id
* @param ResourceMetaInterface|null $resourceMeta
*/
protected function fetchByTypeAndId(string $type, string $providerBehaviour, $id, ?ResourceMetaInterface $resourceMeta)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ public function setContextDispatchType(string $dispatchType);
public function setIndexOptions(array $indexOptions);

/**
* This method only gets executed on untrusted events like insert, update or delete
*
* @param ElementInterface $resource
*
* @return ProxyResourceInterface|null
*
* @deprecated since 1.0.0 and will be removed in 2.0.0
*/
public function checkResourceProxy(ElementInterface $resource);

/**
* This method only gets executed on untrusted events like insert, update or delete
*
* @param ElementInterface $resource
*
* @return bool
Expand Down

0 comments on commit 0cf79d4

Please sign in to comment.