6
6
7
7
use Shopsys \FrameworkBundle \Component \Domain \Domain ;
8
8
use Shopsys \FrameworkBundle \Component \Setting \Setting ;
9
+ use Shopsys \FrameworkBundle \Model \Feed \Exception \FeedNotFoundException ;
9
10
use Shopsys \Plugin \Cron \IteratedCronModuleInterface ;
10
11
use Symfony \Bridge \Monolog \Logger ;
11
12
@@ -24,12 +25,14 @@ class FeedCronModule implements IteratedCronModuleInterface
24
25
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
25
26
* @param \Shopsys\FrameworkBundle\Component\Setting\Setting $setting
26
27
* @param \Shopsys\FrameworkBundle\Model\Feed\FeedModuleRepository $feedModuleRepository
28
+ * @param \Shopsys\FrameworkBundle\Model\Feed\FeedModuleFacade $feedModuleFacade
27
29
*/
28
30
public function __construct (
29
31
protected readonly FeedFacade $ feedFacade ,
30
32
protected readonly Domain $ domain ,
31
33
protected readonly Setting $ setting ,
32
34
protected readonly FeedModuleRepository $ feedModuleRepository ,
35
+ protected readonly FeedModuleFacade $ feedModuleFacade ,
33
36
) {
34
37
}
35
38
@@ -60,6 +63,10 @@ public function iterate(): bool
60
63
if ($ this ->currentFeedExport === null ) {
61
64
$ this ->currentFeedExport = $ this ->createCurrentFeedExport ();
62
65
66
+ if ($ this ->currentFeedExport === null ) {
67
+ return false ;
68
+ }
69
+
63
70
$ this ->logger ->info (sprintf (
64
71
'Started generation of feed "%s" generated on domain "%s" into "%s". ' ,
65
72
$ this ->currentFeedExport ->getFeedInfo ()->getName (),
@@ -94,6 +101,10 @@ public function iterate(): bool
94
101
if ($ existsNext === true ) {
95
102
$ this ->currentFeedExport = $ this ->createCurrentFeedExport ();
96
103
104
+ if ($ this ->currentFeedExport === null ) {
105
+ return false ;
106
+ }
107
+
97
108
$ this ->logger ->info (sprintf (
98
109
'Started generation of feed "%s" generated on domain "%s" into "%s". ' ,
99
110
$ this ->currentFeedExport ->getFeedInfo ()->getName (),
@@ -166,6 +177,11 @@ public function wakeUp(): void
166
177
167
178
$ lastSeekId = $ this ->setting ->get (Setting::FEED_ITEM_ID_TO_CONTINUE );
168
179
$ this ->currentFeedExport = $ this ->createCurrentFeedExport ($ lastSeekId );
180
+
181
+ if ($ this ->currentFeedExport === null ) {
182
+ return ;
183
+ }
184
+
169
185
$ this ->currentFeedExport ->wakeUp ();
170
186
171
187
$ this ->logger ->info (sprintf (
@@ -178,15 +194,31 @@ public function wakeUp(): void
178
194
179
195
/**
180
196
* @param int|null $lastSeekId
181
- * @return \Shopsys\FrameworkBundle\Model\Feed\FeedExport
197
+ * @return \Shopsys\FrameworkBundle\Model\Feed\FeedExport|null
182
198
*/
183
- protected function createCurrentFeedExport (?int $ lastSeekId = null ): FeedExport
199
+ protected function createCurrentFeedExport (?int $ lastSeekId = null ): ? FeedExport
184
200
{
185
- return $ this ->feedFacade ->createFeedExport (
186
- $ this ->getFeedExportCreationDataQueue ()->getCurrentFeedName (),
187
- $ this ->getFeedExportCreationDataQueue ()->getCurrentDomain (),
188
- $ lastSeekId ,
189
- );
201
+ try {
202
+ $ feedExport = $ this ->feedFacade ->createFeedExport (
203
+ $ this ->getFeedExportCreationDataQueue ()->getCurrentFeedName (),
204
+ $ this ->getFeedExportCreationDataQueue ()->getCurrentDomain (),
205
+ $ lastSeekId ,
206
+ );
207
+ } catch (FeedNotFoundException $ e ) {
208
+ $ this ->logger ->error ($ e ->getMessage ());
209
+
210
+ $ this ->feedModuleFacade ->deleteFeedCronModulesByName ($ this ->getFeedExportCreationDataQueue ()->getCurrentFeedName ());
211
+
212
+ $ isNextFeedInQueue = $ this ->getFeedExportCreationDataQueue ()->next ();
213
+
214
+ if ($ isNextFeedInQueue === false ) {
215
+ return null ;
216
+ }
217
+
218
+ return $ this ->createCurrentFeedExport ();
219
+ }
220
+
221
+ return $ feedExport ;
190
222
}
191
223
192
224
/**
0 commit comments