8
8
namespace Magento \EavGraphQl \Plugin \Eav ;
9
9
10
10
use Magento \Eav \Model \Entity \Attribute ;
11
- use Magento \Eav \Model \Entity \Attribute as EavAttribute ;
12
11
use Magento \Framework \DataObject \IdentityInterface ;
13
12
use Magento \Framework \Event \ManagerInterface ;
14
13
15
14
/**
16
- * EAV plugin runs page cache clean and provides peoper EAV identities.
15
+ * EAV plugin runs page cache clean and provides proper EAV identities.
17
16
*/
18
17
class AttributePlugin implements IdentityInterface
19
18
{
@@ -38,25 +37,54 @@ public function __construct(ManagerInterface $eventManager)
38
37
}
39
38
40
39
/**
41
- * Clean cache by relevant tags.
40
+ * Clean cache by relevant tags after entity save .
42
41
*
43
42
* @param Attribute $subject
44
43
* @param Attribute $result
45
44
* @return Attribute
46
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
47
45
*/
48
46
public function afterSave (
49
47
Attribute $ subject ,
50
48
Attribute $ result
51
49
): 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
52
81
{
53
82
$ this ->identities [] = sprintf (
54
83
"%s_%s " ,
55
- EavAttribute ::CACHE_TAG ,
56
- $ subject ->getAttributeCode ()
84
+ Attribute ::CACHE_TAG ,
85
+ $ entity ->getAttributeCode ()
57
86
);
58
87
$ this ->eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ]);
59
- return $ result ;
60
88
}
61
89
62
90
/**
0 commit comments