8
8
9
9
namespace Ess \M2ePro \Model \Cron \Task \Ebay \Template ;
10
10
11
+ use Ess \M2ePro \Helper \Component \Ebay \Category as EbayCategory ;
12
+
11
13
/**
12
14
* Class \Ess\M2ePro\Model\Cron\Task\Ebay\Template\RemoveUnused
13
15
*/
@@ -42,8 +44,8 @@ protected function performActions()
42
44
protected function removeUnusedTemplates ($ templateNick )
43
45
{
44
46
$ this ->getOperationHistory ()->addTimePoint (
45
- __METHOD__ . $ templateNick ,
46
- 'Remove Unused " ' . $ templateNick. '" Policies '
47
+ __METHOD__ . $ templateNick ,
48
+ 'Remove Unused " ' . $ templateNick . '" Policies '
47
49
);
48
50
49
51
/** @var \Ess\M2ePro\Model\Ebay\Template\Manager $templateManager */
@@ -57,13 +59,13 @@ protected function removeUnusedTemplates($templateNick)
57
59
58
60
$ unionSelectListingTemplate = $ connection ->select ()
59
61
->from ($ listingTable , ['result_field ' =>$ templateManager ->getTemplateIdColumnName ()])
60
- ->where ($ templateManager ->getTemplateIdColumnName (). ' IS NOT NULL ' );
62
+ ->where ($ templateManager ->getTemplateIdColumnName () . ' IS NOT NULL ' );
61
63
$ unionSelectListingCustom = $ connection ->select ()
62
64
->from ($ listingTable , ['result_field ' =>$ templateManager ->getCustomIdColumnName ()])
63
65
->where ($ templateManager ->getCustomIdColumnName ().' IS NOT NULL ' );
64
66
$ unionSelectListingProductTemplate = $ connection ->select ()
65
67
->from ($ listingProductTable , ['result_field ' =>$ templateManager ->getTemplateIdColumnName ()])
66
- ->where ($ templateManager ->getTemplateIdColumnName (). ' IS NOT NULL ' );
68
+ ->where ($ templateManager ->getTemplateIdColumnName () . ' IS NOT NULL ' );
67
69
$ unionSelectListingProductCustom = $ connection ->select ()
68
70
->from ($ listingProductTable , ['result_field ' =>$ templateManager ->getCustomIdColumnName ()])
69
71
->where ($ templateManager ->getCustomIdColumnName ().' IS NOT NULL ' );
@@ -81,7 +83,7 @@ protected function removeUnusedTemplates($templateNick)
81
83
$ minCreateDate = $ this ->getHelper ('Data ' )->getDate ($ minCreateDate );
82
84
83
85
$ collection = $ templateManager ->getTemplateCollection ();
84
- $ collection ->getSelect ()->where ('`id` NOT IN ( ' . $ unionSelect ->__toString (). ') ' );
86
+ $ collection ->getSelect ()->where ('`id` NOT IN ( ' . $ unionSelect ->__toString () . ') ' );
85
87
$ collection ->getSelect ()->where ('`is_custom_template` = 1 ' );
86
88
$ collection ->getSelect ()->where ('`create_date` < ? ' , $ minCreateDate );
87
89
@@ -90,7 +92,7 @@ protected function removeUnusedTemplates($templateNick)
90
92
$ unusedTemplate ->delete ();
91
93
}
92
94
93
- $ this ->getOperationHistory ()->saveTimePoint (__METHOD__ . $ templateNick );
95
+ $ this ->getOperationHistory ()->saveTimePoint (__METHOD__ . $ templateNick );
94
96
}
95
97
96
98
// ---------------------------------------
@@ -184,10 +186,34 @@ protected function removeCategoriesTemplates()
184
186
$ minCreateDate = $ this ->getHelper ('Data ' )->getDate ($ minCreateDate );
185
187
186
188
$ collection = $ this ->activeRecordFactory ->getObject ('Ebay_Template_Category ' )->getCollection ();
187
- $ collection ->getSelect ()->where ('id NOT IN ( ' . $ unionSelect ->__toString (). ') ' );
189
+ $ collection ->getSelect ()->where ('id NOT IN ( ' . $ unionSelect ->__toString () . ') ' );
188
190
$ collection ->getSelect ()->where ('is_custom_template = 1 ' );
189
191
$ collection ->getSelect ()->where ('create_date < ? ' , $ minCreateDate );
190
192
193
+ $ rememberTemplateIds = [];
194
+
195
+ $ listingCollection = $ this ->activeRecordFactory ->getObject ('Ebay_Listing ' )->getCollection ();
196
+ foreach ($ listingCollection ->getItems () as $ eBayListing ) {
197
+ $ additionalData = $ eBayListing ->getParentObject ()->getSettings ('additional_data ' );
198
+ if (!isset ($ additionalData ['mode_same_category_data ' ])) {
199
+ continue ;
200
+ }
201
+
202
+ $ sameCategoryData = $ additionalData ['mode_same_category_data ' ];
203
+
204
+ if (!empty ($ sameCategoryData [EbayCategory::TYPE_EBAY_MAIN ])) {
205
+ $ rememberTemplateIds [] = $ sameCategoryData [EbayCategory::TYPE_EBAY_MAIN ]['template_id ' ];
206
+ }
207
+
208
+ if (!empty ($ sameCategoryData [EbayCategory::TYPE_EBAY_SECONDARY ])) {
209
+ $ rememberTemplateIds [] = $ sameCategoryData [EbayCategory::TYPE_EBAY_SECONDARY ]['template_id ' ];
210
+ }
211
+ }
212
+
213
+ if (!empty ($ rememberTemplateIds )) {
214
+ $ collection ->getSelect ()->where ('id NOT IN ( ' . implode (', ' , $ rememberTemplateIds ) . ') ' );
215
+ }
216
+
191
217
$ unusedTemplates = $ collection ->getItems ();
192
218
foreach ($ unusedTemplates as $ unusedTemplate ) {
193
219
/**@var \Ess\M2ePro\Model\Ebay\Template\Category $unusedTemplate */
@@ -286,9 +312,33 @@ protected function removeStoreCategoriesTemplates()
286
312
$ minCreateDate = $ this ->getHelper ('Data ' )->getDate ($ minCreateDate );
287
313
288
314
$ collection = $ this ->activeRecordFactory ->getObject ('Ebay_Template_StoreCategory ' )->getCollection ();
289
- $ collection ->getSelect ()->where ('`id` NOT IN ( ' . $ unionSelect ->__toString (). ') ' );
315
+ $ collection ->getSelect ()->where ('`id` NOT IN ( ' . $ unionSelect ->__toString () . ') ' );
290
316
$ collection ->getSelect ()->where ('`create_date` < ? ' , $ minCreateDate );
291
317
318
+ $ rememberTemplateIds = [];
319
+
320
+ $ listingCollection = $ this ->activeRecordFactory ->getObject ('Ebay_Listing ' )->getCollection ();
321
+ foreach ($ listingCollection ->getItems () as $ eBayListing ) {
322
+ $ additionalData = $ eBayListing ->getParentObject ()->getSettings ('additional_data ' );
323
+ if (!isset ($ additionalData ['mode_same_category_data ' ])) {
324
+ continue ;
325
+ }
326
+
327
+ $ sameCategoryData = $ additionalData ['mode_same_category_data ' ];
328
+
329
+ if (!empty ($ sameCategoryData [EbayCategory::TYPE_STORE_MAIN ])) {
330
+ $ rememberTemplateIds [] = $ sameCategoryData [EbayCategory::TYPE_STORE_MAIN ]['template_id ' ];
331
+ }
332
+
333
+ if (!empty ($ sameCategoryData [EbayCategory::TYPE_STORE_SECONDARY ])) {
334
+ $ rememberTemplateIds [] = $ sameCategoryData [EbayCategory::TYPE_STORE_SECONDARY ]['template_id ' ];
335
+ }
336
+ }
337
+
338
+ if (!empty ($ rememberTemplateIds )) {
339
+ $ collection ->getSelect ()->where ('id NOT IN ( ' . implode (', ' , $ rememberTemplateIds ) . ') ' );
340
+ }
341
+
292
342
$ unusedTemplates = $ collection ->getItems ();
293
343
foreach ($ unusedTemplates as $ unusedTemplate ) {
294
344
/**@var \Ess\M2ePro\Model\Ebay\Template\StoreCategory $unusedTemplate */
0 commit comments