|
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\Bootstrap; |
|
9
|
|
|
|
|
10
|
|
|
use Shopware\Bundle\AttributeBundle\Service\CrudService; |
|
11
|
|
|
use Shopware\Components\Model\ModelManager; |
|
12
|
|
|
use Enlight_Components_Db_Adapter_Pdo_Mysql as Pdo; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Uninstaller of the plugin. |
|
16
|
|
|
* Currently attribute columns will never be removed, as well as the plugin tables. This can be changed once |
|
17
|
|
|
* shopware supports asking the user, if he wants to remove the plugin permanently or temporarily |
|
18
|
|
|
* |
|
19
|
|
|
* Class Uninstall |
|
20
|
|
|
* @package ShopwarePlugins\Connect\Bootstrap |
|
21
|
|
|
*/ |
|
22
|
|
|
class Uninstall |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Shopware_Plugins_Backend_SwagConnect_Bootstrap |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $bootstrap; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Pdo |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $db; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ModelManager |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $modelManager; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var Menu |
|
41
|
|
|
*/ |
|
42
|
|
|
private $menu; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Setup constructor. |
|
46
|
|
|
* @param \Shopware_Plugins_Backend_SwagConnect_Bootstrap $bootstrap |
|
47
|
|
|
* @param ModelManager $modelManager |
|
48
|
|
|
* @param Pdo $db |
|
49
|
|
|
* @param Menu $menu |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
52
|
|
|
\Shopware_Plugins_Backend_SwagConnect_Bootstrap $bootstrap, |
|
53
|
|
|
ModelManager $modelManager, |
|
54
|
|
|
Pdo $db, |
|
55
|
|
|
Menu $menu |
|
56
|
|
|
) { |
|
57
|
|
|
$this->bootstrap = $bootstrap; |
|
58
|
|
|
$this->modelManager = $modelManager; |
|
59
|
|
|
$this->db = $db; |
|
60
|
|
|
$this->menu = $menu; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function run() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->menu->remove(); |
|
69
|
|
|
$this->deactivateConnectProducts(); |
|
70
|
|
|
$this->removeEngineElement(); |
|
71
|
|
|
|
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return CrudService |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getCrudService() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->bootstrap->Application()->Container()->get('shopware_attribute.crud_service'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Disabled all products imported from shopware Connect |
|
85
|
|
|
*/ |
|
86
|
|
|
public function deactivateConnectProducts() |
|
87
|
|
|
{ |
|
88
|
|
|
$sql = ' |
|
89
|
|
|
UPDATE s_articles |
|
90
|
|
|
INNER JOIN s_plugin_connect_items |
|
91
|
|
|
ON s_plugin_connect_items.article_id = s_articles.id |
|
92
|
|
|
AND shop_id IS NOT NULL |
|
93
|
|
|
SET s_articles.active = false |
|
94
|
|
|
'; |
|
95
|
|
|
$this->db->exec($sql); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Remove an engine element so that the connectProductDescription is not displayed in the article anymore |
|
100
|
|
|
*/ |
|
101
|
|
|
public function removeEngineElement() |
|
102
|
|
|
{ |
|
103
|
|
|
$repo = $this->modelManager->getRepository('Shopware\Models\Article\Element'); |
|
104
|
|
|
$element = $repo->findOneBy(['name' => 'connectProductDescription']); |
|
105
|
|
|
|
|
106
|
|
|
if ($element) { |
|
107
|
|
|
$this->modelManager->remove($element); |
|
108
|
|
|
$this->modelManager->flush(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
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.