@@ -105,38 +105,31 @@ public function __construct(
105
105
}
106
106
107
107
/**
108
- * Get feed id
108
+ * Get FB Feed ID
109
109
*
110
- * @param int $feedId
111
- * @param array $catalogFeeds
112
- * @param string $feedName
113
- * @param int $catalogId
114
- * @return void
110
+ * @return mixed|null
115
111
* @throws GuzzleException
116
112
*/
117
-
118
- private function getFeedId ($ feedId , $ catalogFeeds , $ feedName , $ catalogId )
113
+ private function getFbFeedId ()
119
114
{
115
+ $ feedId = $ this ->systemConfig ->getFeedId ($ this ->storeId );
116
+ $ feedName = self ::FB_FEED_NAME ;
117
+ $ catalogId = $ this ->systemConfig ->getCatalogId ($ this ->storeId );
118
+ $ catalogFeeds = $ this ->graphApiAdapter ->getCatalogFeeds ($ catalogId );
119
+
120
+ // make sure feed exists on meta side, not deleted
120
121
if ($ feedId ) {
121
- $ magentoFeeds = array_filter ($ catalogFeeds , function ($ a ) use ( $ feedId ) {
122
- return $ a [ ' id ' ] === $ feedId ;
123
- });
122
+ $ magentoFeeds = array_filter ($ catalogFeeds , fn ($ a ) => $ a [ ' id ' ] === $ feedId );
123
+ // in case feed id is not found in meta catalog, feed id on
124
+ // magento will be flushed and new feed will be created in Meta Catalog
124
125
if (empty ($ magentoFeeds )) {
125
126
$ feedId = null ;
126
127
}
127
128
}
128
129
129
- if (!$ feedId ) {
130
- $ magentoFeeds = array_filter ($ catalogFeeds , function ($ a ) use ($ feedName ) {
131
- return $ a ['name ' ] === $ feedName ;
132
- });
133
- if (!empty ($ magentoFeeds )) {
134
- $ feedId = $ magentoFeeds [array_key_first ($ magentoFeeds )]['id ' ];
135
- }
136
- }
137
-
138
130
if (!$ feedId ) {
139
131
$ feedId = $ this ->graphApiAdapter ->createEmptyFeed ($ catalogId , $ feedName );
132
+
140
133
$ maxAttempts = 5 ;
141
134
$ attempts = 0 ;
142
135
do {
@@ -147,26 +140,14 @@ private function getFeedId($feedId, $catalogFeeds, $feedName, $catalogId)
147
140
$ attempts ++;
148
141
usleep (2000000 );
149
142
} while ($ attempts < $ maxAttempts );
150
- }
151
- }
152
143
153
- /**
154
- * Get FB Feed Id
155
- *
156
- * @return mixed|null
157
- * @throws GuzzleException
158
- */
159
- private function getFbFeedId ()
160
- {
161
- $ feedId = $ this ->systemConfig ->getFeedId ($ this ->storeId );
162
- $ feedName = self ::FB_FEED_NAME ;
163
- $ catalogId = $ this ->systemConfig ->getCatalogId ($ this ->storeId );
164
- $ catalogFeeds = $ this ->graphApiAdapter ->getCatalogFeeds ($ catalogId );
165
- $ this ->getFeedId ($ feedId , $ catalogFeeds , $ feedName , $ catalogId );
166
- if ($ feedId && $ this ->systemConfig ->getFeedId ($ this ->storeId ) != $ feedId ) {
167
- $ this ->systemConfig
168
- ->saveConfig (SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID , $ feedId , $ this ->storeId )
169
- ->cleanCache ();
144
+ if ($ feedId ) {
145
+ $ this ->systemConfig ->saveConfig (
146
+ SystemConfig::XML_PATH_FACEBOOK_BUSINESS_EXTENSION_FEED_ID ,
147
+ $ feedId ,
148
+ $ this ->storeId
149
+ )->cleanCache ();
150
+ }
170
151
}
171
152
return $ feedId ;
172
153
}
@@ -256,7 +237,6 @@ public function execute($storeId = null)
256
237
$ this ->builder ->setStoreId ($ this ->storeId );
257
238
$ this ->graphApiAdapter ->setDebugMode ($ this ->systemConfig ->isDebugMode ($ storeId ))
258
239
->setAccessToken ($ this ->systemConfig ->getAccessToken ($ storeId ));
259
-
260
240
try {
261
241
$ feedId = $ this ->getFbFeedId ();
262
242
if (!$ feedId ) {
0 commit comments