1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | class SC_Plugin_Installer { |
---|
24 | |
---|
25 | protected $plugin_code; |
---|
26 | |
---|
27 | protected $arrPlugin; |
---|
28 | |
---|
29 | protected $arrInstallData; |
---|
30 | |
---|
31 | function __construct($arrPlugin) { |
---|
32 | $this->arrPlugin = $arrPlugin; |
---|
33 | $this->arrInstallData = array(); |
---|
34 | $this->arrInstallData['sql'] = array(); |
---|
35 | $this->arrInstallData['copy_file'] = array(); |
---|
36 | $this->arrInstallData['copy_direcrtory'] = array(); |
---|
37 | $this->arrInstallData['remove_file'] = array(); |
---|
38 | $this->arrInstallData['remove_directory'] = array(); |
---|
39 | } |
---|
40 | |
---|
41 | function execInstall() { |
---|
42 | GC_Utils_Ex::gfPrintLog("start install"); |
---|
43 | |
---|
44 | $plugin_code = $this->arrPlugin['plugin_code']; |
---|
45 | |
---|
46 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
47 | $objQuery->begin(); |
---|
48 | |
---|
49 | // テーブル作成SQLなどを実行 |
---|
50 | $arrSql = $this->arrInstallData['sql']; |
---|
51 | |
---|
52 | foreach ($arrSql as $sql) { |
---|
53 | GC_Utils_Ex::gfPrintLog("exec sql:" . $sql['sql']); |
---|
54 | $objQuery->query($sql['sql'], $sql['params']); |
---|
55 | } |
---|
56 | |
---|
57 | // プラグインのディレクトリコピー |
---|
58 | $arrCopyDirectories = $this->arrInstallData['copy_directory']; |
---|
59 | |
---|
60 | foreach ($arrCopyDirectories as $directory) { |
---|
61 | GC_Utils_Ex::gfPrintLog("exec dir copy:" . $directory['src']); |
---|
62 | // ディレクトリコピー -> HTML配下とDATA配下を別関数にする |
---|
63 | SC_Utils::copyDirectory( |
---|
64 | PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $directory['src'], |
---|
65 | PLUGIN_HTML_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $directory['dist']); |
---|
66 | } |
---|
67 | |
---|
68 | // プラグインのファイルコピー |
---|
69 | $arrCopyFiles = $this->arrInstallData['copy_file']; |
---|
70 | |
---|
71 | foreach ($arrCopyFiles as $file) { |
---|
72 | GC_Utils_Ex::gfPrintLog("exec file copy:" . $file['src']); |
---|
73 | // ファイルコピー |
---|
74 | copy(PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $file['src'], |
---|
75 | PLUGIN_HTML_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $file['dist']); |
---|
76 | } |
---|
77 | |
---|
78 | $objQuery->commit(); |
---|
79 | GC_Utils_Ex::gfPrintLog("end install"); |
---|
80 | |
---|
81 | } |
---|
82 | |
---|
83 | function copyFile($src, $dist) { |
---|
84 | $this->arrInstallData['copy_file'][] = array( |
---|
85 | 'src' => $src, |
---|
86 | 'dist' => $dist |
---|
87 | ); |
---|
88 | } |
---|
89 | |
---|
90 | function copyDirectory($src, $dist) { |
---|
91 | $this->arrInstallData['copy_directory'][] = array( |
---|
92 | 'src' => $src, |
---|
93 | 'dist' => $dist |
---|
94 | ); |
---|
95 | } |
---|
96 | |
---|
97 | function removeFile($dist) { |
---|
98 | $this->arrInstallData['remove_file'][] = array( |
---|
99 | 'dist' => $dist |
---|
100 | ); |
---|
101 | } |
---|
102 | |
---|
103 | function removeDirectory($dist) { |
---|
104 | $this->arrInstallData['remove_file'][] = array( |
---|
105 | 'dist' => $dist |
---|
106 | ); |
---|
107 | } |
---|
108 | |
---|
109 | public function sql($sql, array $params = array()) { |
---|
110 | $this->arrInstallData['sql'][] = array( |
---|
111 | 'sql' => $sql, |
---|
112 | 'params' => $params |
---|
113 | ); |
---|
114 | } |
---|
115 | } |
---|