Config   F
last analyzed

Complexity

Total Complexity 98

Size/Duplication

Total Lines 707
Duplicated Lines 5.94 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 42
loc 707
rs 1.893
c 0
b 0
f 0
wmc 98
lcom 2
cbo 4

35 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getConfig() 0 48 10
A hasSsl() 0 10 1
A isCronActive() 0 8 3
A isCronPluginActive() 0 12 1
A isDynamicStreamCronActive() 0 10 1
A getPluginConfig() 0 6 2
A getMainConfig() 0 16 3
A getConfigs() 0 6 1
A setConfig() 0 22 3
A deleteConfig() 0 16 3
A getGeneralConfig() 0 10 1
A setGeneralConfigs() 0 33 4
A getImportConfig() 0 9 1
B setImportConfigs() 6 37 7
A getExportConfig() 0 16 3
B setExportConfigs() 6 41 9
A processTriggerChange() 0 9 2
A getTriggerService() 0 8 2
A setUnitsMapping() 0 20 3
A getUnitsMappings() 0 7 1
A compareExportConfiguration() 0 17 6
A hasTriggerConfigChanged() 0 9 3
C collectExportPrice() 0 34 9
A getConfigByValue() 0 6 1
A setMarketplaceSettings() 0 7 2
A getMarketplaceUrl() 0 8 2
A getDefaultShopId() 10 10 1
A getDefaultShopCategory() 12 12 1
A getConfigRepository() 0 8 2
A getShopRepository() 0 8 2
A getPriceGateway() 0 10 2
A getCustomerGroupRepository() 0 8 2
A getConnectPDOGateway() 8 8 2
A activateConnectCronJob() 0 7 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Config often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Config, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Components;
9
10
use Shopware\Components\Plugin\CachedConfigReader;
11
use ShopwarePlugins\Connect\Components\Marketplace\MarketplaceSettings;
12
use Shopware\Components\Model\ModelManager;
13
use Shopware\CustomModels\Connect\Config as ConfigModel;
14
use Shopware\Connect\Gateway\PDO;
15
16
/**
17
 * @category  Shopware
18
 * @package   Shopware\Plugins\SwagConnect
19
 */
20
class Config
21
{
22
    const UPDATE_MANUAL = 0;
23
    const UPDATE_AUTO = 1;
24
    const UPDATE_CRON_JOB = 2;
25
    const MARKETPLACE_URL = 'sn.connect.shopware.com';
26
27
    /**
28
     * @var ModelManager
29
     */
30
    private $manager;
31
32
    /**
33
     * @var \Shopware\CustomModels\Connect\ConfigRepository
34
     */
35
    private $repository;
36
37
    /** @var \Shopware\Models\Shop\Shop */
38
    private $shopRepository;
39
40
    private $customerGroupRepository;
41
42
    private $priceGateway;
43
44
    private $connectGateway;
45
46
    /** @var CachedConfigReader */
47
    private $configReader;
48
49
    /**
50
     * @var TriggerService
51
     */
52
    private $triggerService;
53
54
    /**
55
     * @param ModelManager $manager
56
     * @param CachedConfigReader $configReader
57
     */
58
    public function __construct(ModelManager $manager, CachedConfigReader $configReader)
59
    {
60
        $this->manager = $manager;
61
        $this->configReader = $configReader;
62
    }
63
64
    /**
65
     * @param $name
66
     * @param null $default
67
     * @param null $shopId
68
     * @return null
69
     */
70
    public function getConfig($name, $default = null, $shopId = null)
71
    {
72
        $result = $this->getPluginConfig($name);
73
        if (!empty($result)) {
74
            return $result;
75
        }
76
77
        if (is_null($shopId)) {
78
            return $this->getMainConfig($name, $default);
79
        }
80
        $query = $this->getConfigRepository()->getConfigsQuery($name, $shopId);
81
        $query->setMaxResults(1);
82
        $result = $query->getResult();
83
84
        if (count($result) > 0 && $model = reset($result)) {
85
            $decodedString = json_decode($model->getValue(), true);
86
            if ($decodedString !== null) {
87
                return $decodedString;
88
            }
89
90
            return $model->getValue();
91
        }
92
93
        $shop = $this->getShopRepository()->find($shopId);
94
        if (!$shop) {
95
            return $this->getMainConfig($name, $default);
96
        }
97
98
        $mainShop = $shop->getMain();
99
        if ($mainShop) {
100
            $mainShopId = $mainShop->getId();
101
            $query = $this->getConfigRepository()->getConfigsQuery($name, $mainShopId);
102
            $query->setMaxResults(1);
103
            $result = $query->getResult();
104
            $model = $result[0];
105
106
            if ($model) {
107
                $decodedString = json_decode($model->getValue(), true);
108
                if ($decodedString !== null) {
109
                    return $decodedString;
110
                }
111
112
                return $model->getValue();
113
            }
114
        }
115
116
        return $this->getMainConfig($name, $default);
117
    }
118
119
    /**
120
     * @return bool
121
     */
122
    public function hasSsl()
123
    {
124
        $builder = $this->manager->getConnection()->createQueryBuilder();
125
        $builder->select('cs.secure')
126
            ->from('s_core_shops', 'cs')
127
            ->where('cs.default = :default')
128
            ->setParameter('default', true);
129
130
        return (bool) $builder->execute()->fetchColumn();
131
    }
132
133
    /**
134
     * @return bool
135
     */
136
    public function isCronActive()
137
    {
138
        if ($this->isCronPluginActive() && $this->isDynamicStreamCronActive()) {
139
            return true;
140
        }
141
142
        return false;
143
    }
144
145
    /**
146
     * @return bool
147
     */
148
    public function isCronPluginActive()
149
    {
150
        $builder = $this->manager->getConnection()->createQueryBuilder();
151
        $builder->select('cp.active')
152
            ->from('s_core_plugins', 'cp')
153
            ->where('cp.namespace = :namespace')
154
            ->andWhere('cp.name = :name')
155
            ->setParameter('namespace', 'Core')
156
            ->setParameter('name', 'Cron');
157
158
        return (bool) $builder->execute()->fetchColumn();
159
    }
160
161
    /**
162
     * @return bool
163
     */
164
    public function isDynamicStreamCronActive()
165
    {
166
        $builder = $this->manager->getConnection()->createQueryBuilder();
167
        $builder->select('cron.active')
168
            ->from('s_crontab', 'cron')
169
            ->where('cron.action LIKE :action')
170
            ->setParameter('action', '%ConnectExportDynamicStreams');
171
172
        return (bool) $builder->execute()->fetchColumn();
173
    }
174
175
    /**
176
     * @param $name
177
     * @param null $default
178
     * @return mixed
179
     */
180
    private function getPluginConfig($name, $default = null)
181
    {
182
        $config = $this->configReader->getByPluginName('SwagConnect');
183
184
        return array_key_exists($name, $config) ? $config[$name] : $default;
185
    }
186
187
    /**
188
     * @param $name
189
     * @param null $default
190
     * @return null
191
     */
192
    private function getMainConfig($name, $default = null)
193
    {
194
        $query = $this->getConfigRepository()->getConfigsQuery($name);
195
        $query->setMaxResults(1);
196
        $result = $query->getResult();
197
        if (count($result) === 0) {
198
            return $default;
199
        }
200
201
        $decodedString = json_decode($result[0]->getValue(), true);
202
        if ($decodedString !== null) {
203
            return $decodedString;
204
        }
205
206
        return $result[0]->getValue();
207
    }
208
209
    /**
210
     * @param null $name
211
     * @param null $shopId
212
     * @param null $groupName
213
     * @return array
214
     */
215
    public function getConfigs($name = null, $shopId = null, $groupName = null)
216
    {
217
        $query = $this->getConfigRepository()->getConfigsQuery($name, $shopId, $groupName);
218
219
        return $query->getResult();
220
    }
221
222
    /**
223
     * @param $name
224
     * @param $value
225
     * @param null $shopId
226
     * @param null $groupName
227
     */
228
    public function setConfig($name, $value, $shopId = null, $groupName = null)
229
    {
230
        $model = $this->getConfigRepository()->findOneBy(['name' => $name]);
231
232
        if (!$model) {
233
            $model = new ConfigModel();
234
            $this->manager->persist($model);
235
        }
236
237
        $model->setName($name);
238
239
        if (is_array($value)) {
240
            $model->setValue(json_encode($value));
241
        } else {
242
            $model->setValue($value);
243
        }
244
245
        $model->setShopId($shopId);
246
        $model->setGroupName($groupName);
247
248
        $this->manager->flush();
249
    }
250
251
    public function deleteConfig($name, $shopId = null)
252
    {
253
        $whereClause = ['name' => $name];
254
        if ($shopId > 0) {
255
            $whereClause['shopId'] = $shopId;
256
        }
257
        $model = $this->getConfigRepository()->findOneBy($whereClause);
258
        if (!$model) {
259
            throw new \Exception(sprintf(
260
                'Config entity %s not found!',
261
                $name
262
            ));
263
        }
264
265
        $this->getConfigRepository()->remove($model);
266
    }
267
268
    /**
269
     * Helper function which returns general configuration
270
     * for each shop.
271
     *
272
     * @return array
273
     */
274
    public function getGeneralConfig()
275
    {
276
        $query = "SELECT `name`, `value` FROM s_plugin_connect_config
277
        WHERE `shopId` IS NULL AND `groupName` = 'general'";
278
279
        $result = Shopware()->Db()->fetchPairs($query);
280
        $result['shopId'] = $this->getConnectPDOGateway()->getShopId();
281
282
        return [$result];
283
    }
284
285
    /**
286
     * Stores data general config
287
     * data into database.
288
     *
289
     * @param array $data
290
     */
291
    public function setGeneralConfigs($data)
292
    {
293
        // shopware must not be overwritten in config table
294
        // it can be set only during login/register
295
        unset($data['shopwareId']);
296
        // do not store shopId in plugin config table
297
        unset($data['shopId']);
298
299
        foreach ($data as $key => $configItem) {
300
301
            /** @var \Shopware\CustomModels\Connect\Config $model */
302
            $model = $this->getConfigRepository()->findOneBy([
303
                'name' => $key,
304
                'groupName' => 'general'
305
            ]);
306
307
            if (is_null($model)) {
308
                $model = new ConfigModel();
309
                $model->setName($key);
310
                $model->setGroupName('general');
311
            }
312
313
            if (is_array($configItem)) {
314
                $model->setValue(json_encode($configItem));
315
            } else {
316
                $model->setValue($configItem);
317
            }
318
319
            $this->manager->persist($model);
320
        }
321
322
        $this->manager->flush();
323
    }
324
325
    /**
326
     * Helper function which returns import configuration.
327
     *
328
     * @return array
329
     */
330
    public function getImportConfig()
331
    {
332
        $query = "SELECT `name`, `value` FROM s_plugin_connect_config
333
        WHERE `shopId` IS NULL AND `groupName` = 'import'";
334
335
        $result = Shopware()->Db()->fetchPairs($query);
336
337
        return $result;
338
    }
339
340
    /**
341
     * Stores data import config
342
     * data into database.
343
     *
344
     * @param array $data
345
     */
346
    public function setImportConfigs($data)
347
    {
348
        foreach ($data as $config) {
349
            unset($config['id']);
350
            foreach ($config as $key => $configValue) {
351
                /** @var \Shopware\CustomModels\Connect\Config $model */
352
                $model = $this->getConfigRepository()->findOneBy([
353
                    'name' => $key,
354
                    'shopId' => null,
355
                    'groupName' => 'import'
356
                ]);
357 View Code Duplication
                if (is_null($model)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
358
                    $model = new ConfigModel();
359
                    $model->setName($key);
360
                    $model->setGroupName('import');
361
                    $model->setShopId(null);
362
                }
363
364
                if (is_array($configValue)) {
365
                    $model->setValue(json_encode($configValue));
366
                } else {
367
                    $model->setValue($configValue);
368
                }
369
                $this->manager->persist($model);
370
371
                if ($key === 'importImagesOnFirstImport') {
372
                    if ($configValue == 0) {
373
                        $this->activateConnectCronJob('ShopwareConnectImportImages', 1);
374
                    } else {
375
                        $this->activateConnectCronJob('ShopwareConnectImportImages', 0);
376
                    }
377
                }
378
            }
379
        }
380
381
        $this->manager->flush();
382
    }
383
384
    /**
385
     * Helper function which returns export configuration.
386
     *
387
     * @return array
388
     */
389
    public function getExportConfig()
390
    {
391
        $query = "SELECT `name`, `value` FROM s_plugin_connect_config
392
        WHERE `shopId` IS NULL AND `groupName` = 'export'";
393
394
        $result = Shopware()->Db()->fetchPairs($query);
395
396
        foreach ($result as $key => $value) {
397
            $decodedString = json_decode($value, true);
398
            if ($decodedString !== null) {
399
                $result[$key] = $decodedString;
400
            }
401
        }
402
403
        return $result;
404
    }
405
406
    public function setExportConfigs($data)
407
    {
408
        foreach ($data as $config) {
409
            unset($config['id']);
410
            foreach ($config as $key => $configValue) {
411
                /** @var \Shopware\CustomModels\Connect\Config $model */
412
                $model = $this->getConfigRepository()->findOneBy([
413
                    'name' => $key,
414
                    'shopId' => null,
415
                    'groupName' => 'export'
416
                ]);
417 View Code Duplication
                if (is_null($model)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
418
                    $model = new ConfigModel();
419
                    $model->setName($key);
420
                    $model->setGroupName('export');
421
                    $model->setShopId(null);
422
                }
423
424
                if (is_array($configValue)) {
425
                    $model->setValue(json_encode($configValue));
426
                } else {
427
                    $model->setValue($configValue);
428
                }
429
430
                $this->manager->persist($model);
431
432
                if ($key === 'autoUpdateProducts') {
433
                    if ($configValue == self::UPDATE_CRON_JOB) {
434
                        $this->activateConnectCronJob('ShopwareConnectUpdateProducts', 1);
435
                    } else {
436
                        $this->activateConnectCronJob('ShopwareConnectUpdateProducts', 0);
437
                    }
438
                }
439
                if ($key === 'useTriggers' && $this->hasTriggerConfigChanged($configValue)) {
440
                    $this->processTriggerChange($configValue);
441
                }
442
            }
443
        }
444
445
        $this->manager->flush();
446
    }
447
448
    /**
449
     * @param string $configValue
450
     */
451
    private function processTriggerChange($configValue)
452
    {
453
        $triggerService = $this->getTriggerService();
454
        if ($configValue == '1') {
455
            $triggerService->activateTriggers();
456
        } else {
457
            $triggerService->deactivateTriggers();
458
        }
459
    }
460
461
    /**
462
     * @return \ShopwarePlugins\Connect\Components\TriggerService
463
     */
464
    private function getTriggerService()
465
    {
466
        if (!$this->triggerService) {
467
            $this->triggerService = new \ShopwarePlugins\Connect\Components\TriggerService(Shopware()->Models()->getConnection());
468
        }
469
470
        return $this->triggerService;
471
    }
472
473
    /**
474
     * Stores units mapping
475
     * data into database.
476
     * @param $units
477
     */
478
    public function setUnitsMapping($units)
479
    {
480
        foreach ($units as $unit) {
481
            /** @var \Shopware\CustomModels\Connect\Config $model */
482
            $model = $this->getConfigRepository()->findOneBy([
483
                'name' => $unit['connectUnit'],
484
                'shopId' => null,
485
                'groupName' => 'units'
486
            ]);
487
488
            if (!$model) {
489
                continue;
490
            }
491
492
            $model->setValue($unit['shopwareUnitKey']);
493
            $this->manager->persist($model);
494
        }
495
496
        $this->manager->flush();
497
    }
498
499
    /**
500
     * Returns units mapping from Connect config table
501
     *
502
     * @return array
503
     */
504
    public function getUnitsMappings()
505
    {
506
        $query = "SELECT `name`, `value` FROM s_plugin_connect_config
507
        WHERE `shopId` IS NULL AND `groupName` = 'units'";
508
509
        return Shopware()->Db()->fetchPairs($query);
510
    }
511
512
    /**
513
     * Compare given export price configuration
514
     * and current export price configuration
515
     * @param array $config
516
     * @return bool
517
     */
518
    public function compareExportConfiguration($config)
519
    {
520
        $currentConfig = $this->getExportConfig();
521
        if ($currentConfig['priceGroupForPriceExport'] != $config['priceGroupForPriceExport']) {
522
            return true;
523
        } elseif ($currentConfig['priceFieldForPriceExport'] != $config['priceFieldForPriceExport']) {
524
            return true;
525
        } elseif ($currentConfig['priceGroupForPurchasePriceExport'] != $config['priceGroupForPurchasePriceExport']) {
526
            return true;
527
        } elseif ($currentConfig['priceFieldForPurchasePriceExport'] != $config['priceFieldForPurchasePriceExport']) {
528
            return true;
529
        } elseif ($currentConfig['exportPriceMode'] != $config['exportPriceMode']) {
530
            return true;
531
        }
532
533
        return false;
534
    }
535
536
    /**
537
     * Compare given Trigger configuration
538
     * and current Trigger configuration
539
     * @param string $configValue
540
     * @return bool
541
     */
542
    private function hasTriggerConfigChanged($configValue)
543
    {
544
        $currentConfig = $this->getExportConfig();
545
        if (isset($currentConfig['useTriggers']) && $currentConfig['useTriggers'] != $configValue) {
546
            return true;
547
        }
548
549
        return false;
550
    }
551
552
    /**
553
     * @param $priceExportMode
554
     * @param $customerGroupKey
555
     * @return array
556
     */
557
    public function collectExportPrice($priceExportMode, $customerGroupKey)
558
    {
559
        $exportConfigArray = $this->getExportConfig();
560
        $postfix = 'ForPriceExport';
561
562
        if ($priceExportMode == 'purchasePrice') {
563
            $postfix = 'ForPurchasePriceExport';
564
        }
565
566
        $group = 'priceGroup' . $postfix;
567
        $price = 'priceField' . $postfix;
568
569
        $allowGroup = isset($exportConfigArray[$group]) && $exportConfigArray[$group] == $customerGroupKey;
570
571
        $customerGroup = $this->getCustomerGroupRepository()->findOneBy(['key' => $customerGroupKey]);
572
573
        $productCount = $this->getPriceGateway()->countProducts($customerGroup);
574
        $priceConfiguredProducts = $this->getPriceGateway()->countProductsWithConfiguredPrice($customerGroup, 'price');
575
        $basePriceConfiguredProducts = $this->getPriceGateway()->countProductsWithConfiguredPrice($customerGroup, 'baseprice');
576
        $pseudoPriceConfiguredProducts = $this->getPriceGateway()->countProductsWithConfiguredPrice($customerGroup, 'pseudoprice');
577
578
        return [
579
            'price' => $allowGroup && $exportConfigArray[$price] == 'price' ? true : false,
580
            'priceAvailable' => false,
581
            'priceConfiguredProducts' => $priceConfiguredProducts,
582
            'basePrice' =>$allowGroup && $exportConfigArray[$price] == 'basePrice' ? true : false,
583
            'basePriceAvailable' => false,
584
            'basePriceConfiguredProducts' => $basePriceConfiguredProducts,
585
            'pseudoPrice' =>$allowGroup && $exportConfigArray[$price] == 'pseudoPrice' ? true : false,
586
            'pseudoPriceAvailable' => false,
587
            'pseudoPriceConfiguredProducts' => $pseudoPriceConfiguredProducts,
588
            'productCount' => $productCount
589
        ];
590
    }
591
592
    /**
593
     * Returns config entity by value
594
     * @param $value
595
     * @return \Shopware\CustomModels\Connect\Config
596
     */
597
    public function getConfigByValue($value)
598
    {
599
        $model = $this->getConfigRepository()->findOneBy(['value' => $value, 'groupName' => 'units']);
600
601
        return $model;
602
    }
603
604
    /**
605
     * Saves array with marketplace settings to config table
606
     *
607
     * @param MarketplaceSettings $settings
608
     */
609
    public function setMarketplaceSettings(MarketplaceSettings $settings)
610
    {
611
        $settings = (array) $settings;
612
        foreach ($settings as $settingName => $settingValue) {
613
            $this->setConfig($settingName, $settingValue, null, 'marketplace');
614
        }
615
    }
616
617
    public function getMarketplaceUrl()
618
    {
619
        if ($this->getConfig('marketplaceNetworkUrl')) {
620
            return $this->getConfig('marketplaceNetworkUrl');
621
        }
622
623
        return self::MARKETPLACE_URL;
624
    }
625
626
    /**
627
     * @return int
628
     */
629 View Code Duplication
    public function getDefaultShopId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
630
    {
631
        $builder = $this->manager->getConnection()->createQueryBuilder();
632
        $builder->select('cs.id')
633
            ->from('s_core_shops', 'cs')
634
            ->where('cs.default = :default')
635
            ->setParameter('default', true);
636
637
        return (int) $builder->execute()->fetchColumn();
638
    }
639
640
    /**
641
     * @return \Shopware\Models\Category\Category
642
     */
643 View Code Duplication
    public function getDefaultShopCategory()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
644
    {
645
        $builder = $this->manager->getConnection()->createQueryBuilder();
646
        $builder->select('cs.category_id')
647
            ->from('s_core_shops', 'cs')
648
            ->where('cs.default = :default')
649
            ->setParameter('default', true);
650
651
        $categoryId = (int) $builder->execute()->fetchColumn();
652
653
        return $this->manager->find('Shopware\Models\Category\Category', $categoryId);
654
    }
655
656
    /**
657
     * @return \Shopware\Components\Model\ModelRepository|\Shopware\CustomModels\Connect\ConfigRepository
658
     */
659
    private function getConfigRepository()
660
    {
661
        if (!$this->repository) {
662
            $this->repository = $this->manager->getRepository('Shopware\CustomModels\Connect\Config');
663
        }
664
665
        return $this->repository;
666
    }
667
668
    /**
669
     * @return \Shopware\Components\Model\ModelRepository|\Shopware\Models\Shop\Shop
670
     */
671
    private function getShopRepository()
672
    {
673
        if (!$this->shopRepository) {
674
            $this->shopRepository = $this->manager->getRepository('Shopware\Models\Shop\Shop');
675
        }
676
677
        return $this->shopRepository;
678
    }
679
680
    private function getPriceGateway()
681
    {
682
        if (!$this->priceGateway) {
683
            $this->priceGateway = new \ShopwarePlugins\Connect\Components\PriceGateway(
684
                Shopware()->Db()
685
            );
686
        }
687
688
        return $this->priceGateway;
689
    }
690
691
    /**
692
     * @return \Shopware\Components\Model\ModelRepository
693
     */
694
    private function getCustomerGroupRepository()
695
    {
696
        if (!$this->customerGroupRepository) {
697
            $this->customerGroupRepository = $this->manager->getRepository('Shopware\Models\Customer\Group');
698
        }
699
700
        return $this->customerGroupRepository;
701
    }
702
703
    /**
704
     * @return \Shopware\Connect\Gateway\PDO
705
     */
706 View Code Duplication
    private function getConnectPDOGateway()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
707
    {
708
        if (!$this->connectGateway) {
709
            $this->connectGateway = new PDO(Shopware()->Db()->getConnection());
710
        }
711
712
        return $this->connectGateway;
713
    }
714
715
    /**
716
     * @param string $action
717
     * @param int $active
718
     */
719
    private function activateConnectCronJob($action, $active)
720
    {
721
        $this->manager->getConnection()->executeUpdate(
722
            'UPDATE `s_crontab` SET `active` = ? WHERE `action` = ? OR `action` = ?',
723
            [$active, $action, "Shopware_CronJob_$action"]
724
        );
725
    }
726
}
727