source: branches/camp/camp-2_13-plugin/data/class/plugin/SC_Plugin_Installer.php @ 22673

Revision 22673, 5.9 KB checked in by adachi, 11 years ago (diff)

#2181 ログ出力

Line 
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 */
23class SC_Plugin_Installer {
24   
25    protected $exec_func;
26   
27    protected $plugin_code;
28   
29    protected $arrPlugin;
30   
31    protected $arrInstallData;
32   
33    public function __construct($exec_func, $arrPlugin) {
34        define('PLUGIN_LOG_REALFILE', DATA_REALDIR . "logs/plugin.log");
35        $this->exec_func   = $exec_func;
36        $this->plugin_code = $arrPlugin['plugin_code'];
37        $this->arrPlugin   = $arrPlugin;
38        $this->arrInstallData = array();
39        $this->arrInstallData['sql'] = array();
40        $this->arrInstallData['copy_file'] = array();
41        $this->arrInstallData['copy_direcrtory'] = array();
42        $this->arrInstallData['remove_file'] = array();
43        $this->arrInstallData['remove_directory'] = array();
44    }
45   
46    public function execInstall() {
47        GC_Utils_Ex::gfPrintLog("start install: " . $this->arrPlugin['plugin_code']);
48       
49        $plugin_code = $this->arrPlugin['plugin_code'];
50
51        $objQuery =& SC_Query::getSingletonInstance();
52       
53        // テーブル作成SQLなどを実行
54        $arrSql = $this->arrInstallData['sql'];
55       
56        foreach ($arrSql as $sql) {
57            GC_Utils_Ex::gfPrintLog("exec sql:" . $sql['sql']);
58            $objQuery->query($sql['sql'], $sql['params']);
59        }
60       
61        // プラグインのディレクトリコピー
62        $arrCopyDirectories = $this->arrInstallData['copy_directory'];
63
64        foreach ($arrCopyDirectories as $directory) {
65            GC_Utils_Ex::gfPrintLog("exec dir copy:" . $directory['src']);
66            // ディレクトリコピー -> HTML配下とDATA配下を別関数にする
67            SC_Utils::copyDirectory(
68                    PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $directory['src'],
69                    PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $directory['dist']);
70        }
71
72        // プラグインのファイルコピー
73        $arrCopyFiles = $this->arrInstallData['copy_file'];
74
75        foreach ($arrCopyFiles as $file) {
76            GC_Utils_Ex::gfPrintLog("exec file copy:" . $file['src']);
77            // ファイルコピー
78            copy(PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $file['src'],
79                 PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $file['dist']);
80        }
81
82        GC_Utils_Ex::gfPrintLog("end install: " . $this->arrPlugin['plugin_code']);
83    }
84   
85    public function execPlugin($exec_func) {
86        $this->log("start");
87       
88        $plugin_code = $this->arrPlugin['plugin_code'];
89
90        $objQuery =& SC_Query::getSingletonInstance();
91       
92        // テーブル作成SQLなどを実行
93        $arrSql = $this->arrInstallData['sql'];
94       
95        foreach ($arrSql as $sql) {
96            $this->log("exec sql: " . $sql['sql']);
97            $objQuery->query($sql['sql'], $sql['params']);
98        }
99       
100        // プラグインのディレクトリコピー
101        $arrCopyDirectories = $this->arrInstallData['copy_directory'];
102
103        foreach ($arrCopyDirectories as $directory) {
104            $this->log("exec dir copy: " . $directory['src'] . ' -> ' . $directory['dist']);
105            // ディレクトリコピー -> HTML配下とDATA配下を別関数にする
106            SC_Utils::copyDirectory(
107                    PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $directory['src'],
108                    PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $directory['dist']);
109        }
110
111        // プラグインのファイルコピー
112        $arrCopyFiles = $this->arrInstallData['copy_file'];
113
114        foreach ($arrCopyFiles as $file) {
115            $this->log("exec file copy: " . $file['src'] . ' -> ' . $file['dist']);
116            // ファイルコピー
117            copy(PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $file['src'],
118                 PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $file['dist']);
119        }
120       
121        $this->log("end");         
122    }
123
124    public function copyFile($src, $dist) {
125        $this->arrInstallData['copy_file'][] = array(
126            'src'  => $src,
127            'dist' => $dist
128        );
129    }
130 
131    public function copyDirectory($src, $dist) {
132        $this->arrInstallData['copy_directory'][] = array(
133            'src'  => $src,
134            'dist' => $dist
135        );       
136    }
137   
138    public function removeFile($dist) {
139        $this->arrInstallData['remove_file'][] = array(
140            'dist' => $dist
141        );
142    }
143   
144    public function removeDirectory($dist) {
145       $this->arrInstallData['remove_file'][] = array(
146            'dist' => $dist
147        );     
148    }
149
150    public function sql($sql, array $params = array()) {
151        $this->arrInstallData['sql'][] = array(
152            'sql'    => $sql,
153            'params' => $params
154        );
155    }
156   
157    public function query($sql, array $params = array()) {
158        $this->sql($sql, $params);
159    }
160   
161    protected function log($msg) {
162        $msg = sprintf("%s %s: %s", $this->exec_func, $this->plugin_code, $msg);
163        GC_Utils::gfPrintLog($msg, PLUGIN_LOG_REALFILE);
164    }
165}
Note: See TracBrowser for help on using the repository browser.