66
77use Shopsys \FrameworkBundle \Component \Domain \Domain ;
88use Shopsys \FrameworkBundle \Component \Setting \Setting ;
9+ use Shopsys \FrameworkBundle \Model \Feed \Exception \FeedNotFoundException ;
910use Shopsys \Plugin \Cron \IteratedCronModuleInterface ;
1011use Symfony \Bridge \Monolog \Logger ;
1112
@@ -24,12 +25,14 @@ class FeedCronModule implements IteratedCronModuleInterface
2425 * @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
2526 * @param \Shopsys\FrameworkBundle\Component\Setting\Setting $setting
2627 * @param \Shopsys\FrameworkBundle\Model\Feed\FeedModuleRepository $feedModuleRepository
28+ * @param \Shopsys\FrameworkBundle\Model\Feed\FeedModuleFacade $feedModuleFacade
2729 */
2830 public function __construct (
2931 protected readonly FeedFacade $ feedFacade ,
3032 protected readonly Domain $ domain ,
3133 protected readonly Setting $ setting ,
3234 protected readonly FeedModuleRepository $ feedModuleRepository ,
35+ protected readonly FeedModuleFacade $ feedModuleFacade ,
3336 ) {
3437 }
3538
@@ -60,6 +63,10 @@ public function iterate(): bool
6063 if ($ this ->currentFeedExport === null ) {
6164 $ this ->currentFeedExport = $ this ->createCurrentFeedExport ();
6265
66+ if ($ this ->currentFeedExport === null ) {
67+ return false ;
68+ }
69+
6370 $ this ->logger ->info (sprintf (
6471 'Started generation of feed "%s" generated on domain "%s" into "%s". ' ,
6572 $ this ->currentFeedExport ->getFeedInfo ()->getName (),
@@ -94,6 +101,10 @@ public function iterate(): bool
94101 if ($ existsNext === true ) {
95102 $ this ->currentFeedExport = $ this ->createCurrentFeedExport ();
96103
104+ if ($ this ->currentFeedExport === null ) {
105+ return false ;
106+ }
107+
97108 $ this ->logger ->info (sprintf (
98109 'Started generation of feed "%s" generated on domain "%s" into "%s". ' ,
99110 $ this ->currentFeedExport ->getFeedInfo ()->getName (),
@@ -166,6 +177,11 @@ public function wakeUp(): void
166177
167178 $ lastSeekId = $ this ->setting ->get (Setting::FEED_ITEM_ID_TO_CONTINUE );
168179 $ this ->currentFeedExport = $ this ->createCurrentFeedExport ($ lastSeekId );
180+
181+ if ($ this ->currentFeedExport === null ) {
182+ return ;
183+ }
184+
169185 $ this ->currentFeedExport ->wakeUp ();
170186
171187 $ this ->logger ->info (sprintf (
@@ -178,15 +194,31 @@ public function wakeUp(): void
178194
179195 /**
180196 * @param int|null $lastSeekId
181- * @return \Shopsys\FrameworkBundle\Model\Feed\FeedExport
197+ * @return \Shopsys\FrameworkBundle\Model\Feed\FeedExport|null
182198 */
183- protected function createCurrentFeedExport (?int $ lastSeekId = null ): FeedExport
199+ protected function createCurrentFeedExport (?int $ lastSeekId = null ): ? FeedExport
184200 {
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 ;
190222 }
191223
192224 /**
0 commit comments