-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPluginManager.php
153 lines (135 loc) · 3.86 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
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
<?php
/*
* This file is part of the Order Pdf plugin
*
* Copyright (C) EC-CUBE CO.,LTD. All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\OrderPdf;
use Eccube\Application;
use Eccube\Plugin\AbstractPluginManager;
use Symfony\Component\Filesystem\Filesystem;
/**
* Class PluginManager.
*/
class PluginManager extends AbstractPluginManager
{
/**
* PluginManager constructor.
*/
public function __construct()
{
}
/**
* Install.
*
* @param array $config
* @param Application $app
*/
public function install($config, $app)
{
$this->copyFile($app['config'], $config['code'], $config['const']['logo_file']);
$this->copyFile($app['config'], $config['code'], $config['const']['pdf_file']);
}
/**
* Uninstall.
*
* @param array $config
* @param Application $app
*/
public function uninstall($config, $app)
{
// Remove temp
$this->removeLogo($app['config'], $config['code'], $config['const']['logo_file']);
$this->removeLogo($app['config'], $config['code'], $config['const']['pdf_file']);
$this->migrationSchema($app, __DIR__.'/Resource/doctrine/migration', $config['code'], 0);
}
/**
* Enable.
*
* @param array $config
* @param Application $app
*/
public function enable($config, $app)
{
$this->migrationSchema($app, __DIR__.'/Resource/doctrine/migration', $config['code']);
}
/**
* Disable.
*
* @param array $config
* @param Application $app
*/
public function disable($config, $app)
{
}
/**
* Update.
*
* @param array $config
* @param Application $app
*/
public function update($config, $app)
{
$this->copyFile($app['config'], $config['code'], $config['const']['logo_file']);
$this->copyFile($app['config'], $config['code'], $config['const']['pdf_file']);
// Update
$this->migrationSchema($app, __DIR__.'/Resource/doctrine/migration', $config['code']);
}
/**
* ファイルをapp/templateにコピーする.
*
* @param array $config
* @param string $pluginCode
* @param string $fileName
*/
private function copyFile($config, $pluginCode, $fileName)
{
$src = $this->getPluginTemplateDir().'/'.$fileName;
$target = $this->getAppTemplateDir($config).'/'.$pluginCode.'/'.$fileName;
// コピー先にすでにファイルが存在する場合は、ユーザーが変更したロゴ画像を残すために上書きをしない
if (file_exists($target) || !file_exists($src)) {
return;
}
$file = new Filesystem();
$file->copy($src, $target, true);
}
/**
* インストール時app/templateにコピーしたファイルを削除する.
*
* @param array $config
* @param string $pluginCode
* @param string $fileName
*/
private function removeLogo($config, $pluginCode, $fileName)
{
$target = $this->getAppTemplateDir($config).'/'.$pluginCode.'/'.$fileName;
if (!file_exists($target)) {
return;
}
$file = new Filesystem();
$file->remove($target);
}
/**
* Plugin内のテンプレートディレクトリのパスを取得する.
*
* @return string
*/
private function getPluginTemplateDir()
{
return __DIR__.'/Resource/template';
}
/**
* app/template内のテンプレートディレクトリのパスを取得する.
*
* @param array $config
*
* @return string
*/
private function getAppTemplateDir($config)
{
return $config['template_realdir'].'/../admin';
}
}