Skip to content

Commit c1a4b7f

Browse files
committed
B2B-2259: customAttributeMetadata GraphQl query has no cache identity
1 parent 602a036 commit c1a4b7f

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

app/code/Magento/EavGraphQl/Model/Resolver/Cache/CustomAttributeMetadataIdentity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function getIdentities(array $resolvedData): array
2424
$item['attribute_code']
2525
);
2626
}
27+
} else {
28+
return [];
2729
}
2830
return $identities;
2931
}

app/code/Magento/EavGraphQl/Plugin/Eav/AttributePlugin.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
namespace Magento\EavGraphQl\Plugin\Eav;
99

1010
use Magento\Eav\Model\Entity\Attribute;
11-
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
1211
use Magento\Framework\DataObject\IdentityInterface;
1312
use Magento\Framework\Event\ManagerInterface;
1413

1514
/**
16-
* EAV plugin runs page cache clean and provides peoper EAV identities.
15+
* EAV plugin runs page cache clean and provides proper EAV identities.
1716
*/
1817
class AttributePlugin implements IdentityInterface
1918
{
@@ -38,25 +37,54 @@ public function __construct(ManagerInterface $eventManager)
3837
}
3938

4039
/**
41-
* Clean cache by relevant tags.
40+
* Clean cache by relevant tags after entity save.
4241
*
4342
* @param Attribute $subject
4443
* @param Attribute $result
4544
* @return Attribute
46-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4745
*/
4846
public function afterSave(
4947
Attribute $subject,
5048
Attribute $result
5149
): Attribute
50+
{
51+
if (!$subject->isObjectNew()) {
52+
$this->triggerCacheClean($subject);
53+
}
54+
return $result;
55+
}
56+
57+
/**
58+
* Clean cache by relevant tags after entity is deleted and afterDelete
59+
* handler is executed.
60+
*
61+
* @param Attribute $subject
62+
* @param Attribute $result
63+
* @return Attribute
64+
*/
65+
public function afterAfterDelete(
66+
Attribute $subject,
67+
Attribute $result
68+
) : Attribute
69+
{
70+
$this->triggerCacheClean($subject);
71+
return $result;
72+
}
73+
74+
/**
75+
* Trigger cache clean event in event manager.
76+
*
77+
* @param Attribute $entity
78+
* @return void
79+
*/
80+
private function triggerCacheClean(Attribute $entity): void
5281
{
5382
$this->identities[] = sprintf(
5483
"%s_%s",
55-
EavAttribute::CACHE_TAG,
56-
$subject->getAttributeCode()
84+
Attribute::CACHE_TAG,
85+
$entity->getAttributeCode()
5786
);
5887
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
59-
return $result;
6088
}
6189

6290
/**

app/code/Magento/EavGraphQl/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<type name="Magento\Eav\Model\Entity\Attribute">
10-
<plugin name="afterSavePlugin" type="Magento\EavGraphQl\Plugin\Eav\AttributePlugin" />
10+
<plugin name="entityAttributeChangePlugin" type="Magento\EavGraphQl\Plugin\Eav\AttributePlugin" />
1111
</type>
1212
</config>

0 commit comments

Comments
 (0)