|
20 | 20 | use DynamicSearchBundle\Processor\Harmonizer\ResourceHarmonizerInterface; |
21 | 21 | use DynamicSearchBundle\Queue\Message\ProcessResourceMessage; |
22 | 22 | use DynamicSearchBundle\Queue\Message\QueueResourceMessage; |
| 23 | +use DynamicSearchBundle\Resource\ResourceInfoInterface; |
23 | 24 | use Pimcore\Model\Asset; |
24 | 25 | use Pimcore\Model\DataObject; |
25 | 26 | use Pimcore\Model\Document; |
@@ -55,23 +56,39 @@ private function process(array $jobs): void |
55 | 56 | foreach ($jobs as [$message, $ack]) { |
56 | 57 | try { |
57 | 58 | $resource = $message->resource; |
58 | | - // @todo: use introduced "resource info" dto to determinate resource / type |
59 | | - if (str_contains($message->resourceType, '-')) { |
60 | | - [$type, $id] = explode('-', $message->resourceType); |
61 | | - if (is_numeric($id)) { |
62 | | - $id = (int) $id; |
| 59 | + |
| 60 | + if ($message->resourceType === ResourceInfoInterface::TYPE_PIMCORE_ELEMENT) { |
| 61 | + $resourceInfo = $resource; |
| 62 | + if (!$resourceInfo instanceof ResourceInfoInterface) { |
| 63 | + $this->logger->error( |
| 64 | + 'Unable to get resource info for pimcore resource.', |
| 65 | + 'queue', |
| 66 | + $message->contextName |
| 67 | + ); |
| 68 | + |
| 69 | + $ack->ack($message); |
| 70 | + |
| 71 | + continue; |
63 | 72 | } |
64 | | - $resource = Element\Service::getElementById($type, $id); |
| 73 | + |
| 74 | + $resource = Element\Service::getElementById($resourceInfo->getResourceType(), $resourceInfo->getResourceId()); |
65 | 75 | if ($resource === null && $message->dispatchType === ContextDefinitionInterface::CONTEXT_DISPATCH_TYPE_DELETE) { |
66 | 76 | // at this time, the resource is already deleted by pimcore |
67 | 77 | // since we do not serialize the resource into the message, |
68 | | - // we need to create a dummy resource to retrieve a valid resource meta for deletion |
69 | | - $resource = match ($type) { |
| 78 | + // we need to create a fake resource in order for the resource normalizer |
| 79 | + // to generate a valid resource meta for deletion |
| 80 | + $resource = match ($resourceInfo->getResourceType()) { |
70 | 81 | 'document' => new Document(), |
71 | 82 | 'asset' => new Asset(), |
72 | 83 | 'object' => new DataObject\Concrete(), |
| 84 | + default => null, |
73 | 85 | }; |
74 | | - $resource->setId($id); |
| 86 | + |
| 87 | + $resource?->setId($resourceInfo->getResourceId()); |
| 88 | + |
| 89 | + if ($resource instanceof Document && null !== $locale = $resourceInfo->getResourceLocale()) { |
| 90 | + $resource->setProperty('language', 'text', $locale, false, true); |
| 91 | + } |
75 | 92 | } |
76 | 93 | } |
77 | 94 |
|
|
0 commit comments