-
Notifications
You must be signed in to change notification settings - Fork 0
/
K10rProject.php
67 lines (56 loc) · 1.64 KB
/
K10rProject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace K10rProject;
use K10rProject\Components\Snippets;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
class K10rProject extends Plugin
{
/**
* {@inheritdoc}
*/
public function install(InstallContext $context)
{
$this->applyUpdates(null, $context->getCurrentVersion());
parent::install($context);
}
/**
* {@inheritdoc}
*/
public function uninstall(UninstallContext $context)
{
parent::uninstall($context);
}
/**
* {@inheritdoc}
*/
public function update(UpdateContext $updateContext)
{
$this->applyUpdates($updateContext->getCurrentVersion(), $updateContext->getUpdateVersion());
$this->container->get('k10r_project.helpers.project')->updateSnippets(Snippets::$snippets);
parent::update($updateContext);
}
/**
* @param null|string $oldVersion
* @param null|string $newVersion
*
* @return bool
*/
private function applyUpdates($oldVersion = null, $newVersion = null)
{
$versionClosures = [
'2.0.0' => function () {
return true;
},
];
foreach ($versionClosures as $version => $versionClosure) {
if ($oldVersion === null || (version_compare($oldVersion, $version, '<') && version_compare($version, $newVersion, '<='))) {
if (!$versionClosure($this)) {
return false;
}
}
}
return true;
}
}