@@ -20,7 +20,7 @@ class Observer
20
20
/**
21
21
* Cronjob expression configuration
22
22
*/
23
- const XML_PATH_CRON_EXPR = 'crontab/default/jobs/generate_sitemaps /schedule/cron_expr ' ;
23
+ const XML_PATH_CRON_EXPR = 'crontab/default/jobs/sitemap_generate /schedule/cron_expr ' ;
24
24
25
25
/**
26
26
* Error email template configuration
@@ -64,25 +64,33 @@ class Observer
64
64
*/
65
65
protected $ inlineTranslation ;
66
66
67
+ /**
68
+ * @var \Magento\Cron\Model\ScheduleFactory
69
+ */
70
+ private $ scheduleFactory ;
71
+
67
72
/**
68
73
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
69
74
* @param \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory
70
75
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
71
76
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
72
77
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
78
+ * @param \Magento\Cron\Model\ScheduleFactory $scheduleFactory
73
79
*/
74
80
public function __construct (
75
81
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
76
82
\Magento \Sitemap \Model \ResourceModel \Sitemap \CollectionFactory $ collectionFactory ,
77
83
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
78
84
\Magento \Framework \Mail \Template \TransportBuilder $ transportBuilder ,
79
- \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation
85
+ \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
86
+ \Magento \Cron \Model \ScheduleFactory $ scheduleFactory
80
87
) {
81
88
$ this ->_scopeConfig = $ scopeConfig ;
82
89
$ this ->_collectionFactory = $ collectionFactory ;
83
90
$ this ->_storeManager = $ storeManager ;
84
91
$ this ->_transportBuilder = $ transportBuilder ;
85
92
$ this ->inlineTranslation = $ inlineTranslation ;
93
+ $ this ->scheduleFactory = $ scheduleFactory ;
86
94
}
87
95
88
96
/**
@@ -105,6 +113,14 @@ public function scheduledGenerateSitemaps()
105
113
return ;
106
114
}
107
115
116
+ $ schedule = $ this ->scheduleFactory ->create ();
117
+ $ schedule ->setScheduledAt (date ('Y-m-d H:i:s ' ));
118
+ $ schedule ->setCronExpr ($ this ->_scopeConfig ->getValue (self ::XML_PATH_CRON_EXPR ));
119
+
120
+ if (!$ schedule ->trySchedule ()) {
121
+ return ;
122
+ }
123
+
108
124
$ collection = $ this ->_collectionFactory ->create ();
109
125
/* @var $collection \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection */
110
126
foreach ($ collection as $ sitemap ) {
0 commit comments