Completed
Push — master ( 9d6b60...66885a )
by David
02:09
created

WbmTagManager::uninstall()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.9332
c 1
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Tag 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 WbmTagManager;
18
19
use Shopware\Components\Plugin\Context\ActivateContext;
20
use Shopware\Components\Plugin\Context\InstallContext;
21
use Shopware\Components\Plugin\Context\UninstallContext;
22
use Shopware\Components\Plugin\Context\UpdateContext;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
25
/**
26
 * Class WbmTagManager
27
 */
28
class WbmTagManager extends \Shopware\Components\Plugin
29
{
30
    /**
31
     * @param ContainerBuilder $container
32
     */
33
    public function build(ContainerBuilder $container)
34
    {
35
        $container->setParameter('wbm_tag_manager.plugin_dir', $this->getPath());
36
37
        parent::build($container);
38
    }
39
40
    /**
41
     * @param InstallContext $context
42
     *
43
     * @throws \Exception
44
     */
45
    public function install(InstallContext $context)
46
    {
47
        $sql = file_get_contents($this->getPath() . '/Resources/sql/install.sql');
48
49
        $this->container->get('shopware.db')->query($sql);
50
    }
51
52
    /**
53
     * @param UninstallContext $context
54
     *
55
     * @throws \Exception
56
     */
57
    public function uninstall(UninstallContext $context)
58
    {
59
        if (!$context->keepUserData()) {
60
            $sql = file_get_contents($this->getPath() . '/Resources/sql/uninstall.sql');
61
62
            $this->container->get('shopware.db')->query($sql);
63
        }
64
65
        $context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
66
    }
67
68
    /**
69
     * @param ActivateContext $context
70
     */
71
    public function activate(ActivateContext $context)
72
    {
73
        $context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
74
    }
75
76
    /**
77
     * @param UpdateContext $context
78
     *
79
     * @throws \Exception
80
     */
81
    public function update(UpdateContext $context)
82
    {
83
        $currentVersion = $context->getCurrentVersion();
84
        $sql = '';
85
86
        if (version_compare($currentVersion, '2.0.0', '<')) {
87
            $sql .= file_get_contents($this->getPath() . '/Resources/sql/install.sql');
88
        }
89
        if (version_compare($currentVersion, '2.0.3', '<')) {
90
            $sql .= file_get_contents($this->getPath() . '/Resources/sql/update.2.0.3.sql');
91
        }
92
        if (version_compare($currentVersion, '2.0.4', '<')) {
93
            $sql .= file_get_contents($this->getPath() . '/Resources/sql/update.2.0.4.sql');
94
        }
95
        if (version_compare($currentVersion, '2.1.2', '<')) {
96
            $sql .= file_get_contents($this->getPath() . '/Resources/sql/update.2.1.2.sql');
97
        }
98
        if (version_compare($currentVersion, '2.1.9', '<')) {
99
            $sql .= file_get_contents($this->getPath() . '/Resources/sql/update.2.1.9.sql');
100
            $this->container->get('shopware.db')->query($sql);
101
        }
102
103
        $context->scheduleClearCache(InstallContext::CACHE_LIST_ALL);
104
    }
105
}
106