1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Query Manager |
4
|
|
|
* Copyright (c) Webmatch GmbH |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace WbmQueryManager; |
18
|
|
|
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Shopware\Components\Plugin\Context\ActivateContext; |
21
|
|
|
use Shopware\Components\Plugin\Context\InstallContext; |
22
|
|
|
use Shopware\Components\Plugin\Context\UpdateContext; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class WbmQueryManager |
26
|
|
|
* @package WbmQueryManager |
27
|
|
|
*/ |
28
|
|
|
class WbmQueryManager extends \Shopware\Components\Plugin |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @param ContainerBuilder $container |
32
|
|
|
*/ |
33
|
|
|
public function build(ContainerBuilder $container) |
34
|
|
|
{ |
35
|
|
|
$container->setParameter('wbm_query_manager.plugin_dir', $this->getPath()); |
36
|
|
|
|
37
|
|
|
parent::build($container); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param InstallContext $context |
42
|
|
|
*/ |
43
|
|
|
public function install(InstallContext $context) |
44
|
|
|
{ |
45
|
|
|
$sql = file_get_contents($this->getPath() . '/Resources/sql/install.sql'); |
46
|
|
|
|
47
|
|
|
$this->container->get('shopware.db')->query($sql, array($context->getPlugin()->getId())); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param ActivateContext $context |
52
|
|
|
*/ |
53
|
|
|
public function activate(ActivateContext $context) |
54
|
|
|
{ |
55
|
|
|
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param UpdateContext $context |
60
|
|
|
*/ |
61
|
|
|
public function update(UpdateContext $context) |
62
|
|
|
{ |
63
|
|
View Code Duplication |
if(version_compare($context->getCurrentVersion(), '2.0.0', '<')) { |
|
|
|
|
64
|
|
|
$sql = "ALTER TABLE `wbm_query_manager` CHANGE `interval` `interval_int` INT(11) NULL DEFAULT '0'; |
65
|
|
|
ALTER TABLE `wbm_query_manager` CHANGE `sql` `sql_string` LONGTEXT NOT NULL;"; |
66
|
|
|
|
67
|
|
|
$this->container->get('shopware.db')->query($sql); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
if(version_compare($context->getCurrentVersion(), '2.0.3', '<')) { |
|
|
|
|
71
|
|
|
$sql = "ALTER TABLE `wbm_query_manager` ADD `mail_recipient` VARCHAR (255) NULL DEFAULT NULL AFTER `last_run`;"; |
72
|
|
|
|
73
|
|
|
$this->container->get('shopware.db')->query($sql); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$context->scheduleClearCache(InstallContext::CACHE_LIST_ALL); |
77
|
|
|
} |
78
|
|
|
} |
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.