forked from EC-CUBE/ProductRank-plugin
/
PluginManager.php
90 lines (73 loc) · 2.28 KB
/
PluginManager.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\ProductRank;
use Eccube\Application;
use Eccube\Entity\Master\ProductListOrderBy;
use Eccube\Plugin\AbstractPluginManager;
class PluginManager extends AbstractPluginManager
{
public function __construct()
{
}
public function install($config, $app)
{
}
public function uninstall($config, $app)
{
$this->removeProductListOrderBy($app);
}
public function enable($config, $app)
{
$this->addProductListOrderBy($app);
}
public function disable($config, $app)
{
$this->removeProductListOrderBy($app);
}
public function update($config, $app)
{
}
/**
* @param Application $app
*/
private function addProductListOrderBy(Application $app) {
// this up() migration is auto-generated, please modify it to your needs
/** @var \Eccube\Entity\Master\ProductListOrderBy $plob */
$ProductListOrderBy = new ProductListOrderBy();
$ProductListOrderBy->setId(0);
$ProductListOrderBy->setName('未選択');
$ProductListOrderBy->setRank(-1);
/** @var \Doctrine\ORM\EntityManager $em */
$em = $app['orm.em'];
$em->persist($ProductListOrderBy);
$em->flush();
}
/**
* @param Application $app
*/
private function removeProductListOrderBy(Application $app) {
// this down() migration is auto-generated, please modify it to your needs
/** @var \Doctrine\ORM\EntityManager $em */
$em = $app['orm.em'];
$repos = $em->getRepository('Eccube\Entity\Master\ProductListOrderBy');
$ProductListOrderBy = $repos->createQueryBuilder('plob')
->where('plob.id = :id')
->getQuery()
->setParameters(array(
'id' => 0,
))
->getSingleResult();
if ($ProductListOrderBy) {
$em->remove($ProductListOrderBy);
$em->flush();
}
}
}