forked from EC-CUBE/TwoFactorAuthCustomerSms42
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginManager.php
More file actions
196 lines (171 loc) · 5.86 KB
/
Copy pathPluginManager.php
File metadata and controls
196 lines (171 loc) · 5.86 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\TwoFactorAuthCustomerSms42;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Entity\Layout;
use Eccube\Entity\Page;
use Eccube\Entity\PageLayout;
use Eccube\Plugin\AbstractPluginManager;
use Eccube\Repository\LayoutRepository;
use Eccube\Repository\PageLayoutRepository;
use Eccube\Repository\PageRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Plugin\TwoFactorAuthCustomer42\Entity\TwoFactorAuthConfig;
use Plugin\TwoFactorAuthCustomer42\Entity\TwoFactorAuthType;
/**
* Class PluginManager.
*/
class PluginManager extends AbstractPluginManager
{
// 設定対象ページ情報
private $pages = [
['plg_customer_2fa_sms_send_onetime', 'SMS認証送信先入力', 'TwoFactorAuthCustomer42/Resource/template/default/tfa/sms/send_onetime'],
['plg_customer_2fa_sms_input_onetime', 'SMS認証トークン入力', 'TwoFactorAuthCustomer42/Resource/template/default/tfa/sms/input_onetime'],
];
/**
* @param array $meta
* @param ContainerInterface $container
*/
public function enable(array $meta, ContainerInterface $container)
{
$em = $container->get('doctrine')->getManager();
$this->createConfig($em);
// twigファイルを追加
$this->copyTwigFiles($container);
// ページ登録
$this->createPages($em);
}
/**
* @param array $meta
* @param ContainerInterface $container
*/
public function disable(array $meta, ContainerInterface $container)
{
}
/**
* @param array $meta
* @param ContainerInterface $container
*/
public function uninstall(array $meta, ContainerInterface $container)
{
$em = $container->get('doctrine')->getManager();
// twigファイルを削除
$this->removeTwigFiles($container);
// ページ削除
$this->removePages($em);
}
/**
* Twigファイルの登録
*
* @param ContainerInterface $container
*/
protected function copyTwigFiles(ContainerInterface $container)
{
// テンプレートファイルコピー
$templatePath = $container->getParameter('eccube_theme_front_dir')
.'/TwoFactorAuthCustomerSms42/Resource/template/default';
$fs = new Filesystem();
if ($fs->exists($templatePath)) {
return;
}
$fs->mkdir($templatePath);
$fs->mirror(__DIR__.'/Resource/template/default', $templatePath);
}
/**
* ページ情報の登録
*
* @param EntityManagerInterface $em
*/
protected function createPages(EntityManagerInterface $em)
{
foreach ($this->pages as $p) {
$Page = $em->getRepository(Page::class)->findOneBy(['url' => $p[0]]);
if (!$Page) {
/** @var \Eccube\Entity\Page $Page */
$Page = $em->getRepository(Page::class)->newPage();
$Page->setEditType(Page::EDIT_TYPE_DEFAULT);
$Page->setUrl($p[0]);
$Page->setName($p[1]);
$Page->setFileName($p[2]);
$Page->setMetaRobots('noindex');
$em->persist($Page);
$em->flush();
$Layout = $em->getRepository(Layout::class)->find(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE);
$PageLayout = new PageLayout();
$PageLayout->setPage($Page)
->setPageId($Page->getId())
->setLayout($Layout)
->setLayoutId($Layout->getId())
->setSortNo(0);
$em->persist($PageLayout);
$em->flush();
}
}
}
/**
* Twigファイルの削除
*
* @param ContainerInterface $container
*/
protected function removeTwigFiles(ContainerInterface $container)
{
$templatePath = $container->getParameter('eccube_theme_front_dir')
.'/TwoFactorAuthCustomerSms42';
$fs = new Filesystem();
$fs->remove($templatePath);
}
/**
* ページ情報の削除
*
* @param EntityManagerInterface $em
*/
protected function removePages(EntityManagerInterface $em)
{
foreach ($this->pages as $p) {
$Page = $em->getRepository(Page::class)->findOneBy(['url' => $p[0]]);
if (!$Page) {
$Layout = $em->getRepository(Layout::class)->find(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE);
$PageLayout = $em->getRepository(PageLayout::class)->findOneBy(['Page' => $Page, 'Layout' => $Layout]);
$em->remove($PageLayout);
$em->remove($Page);
$em->flush();
}
}
}
/**
* 設定の登録.
*
* @param EntityManagerInterface $em
*/
protected function createConfig(EntityManagerInterface $em)
{
$TwoFactorAuthType = $em->getRepository(TwoFactorAuthType::class)->findBy([ 'name' => 'SMS' ]);
if (!$TwoFactorAuthType) {
// レコードを保存
$TwoFactorAuthType = new TwoFactorAuthType();
$TwoFactorAuthType
->setName('SMS')
->setRoute('plg_customer_2fa_sms_send_onetime')
;
$em->persist($TwoFactorAuthType);
}
// 除外ルートの登録
$TwoFactorAuthConfig = $em->find(TwoFactorAuthConfig::class, 1);
foreach ($this->pages as $p) {
$TwoFactorAuthConfig->addExcludeRoute($p[0]);
}
$em->persist($TwoFactorAuthConfig);
$em->flush();
return;
}
}