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

Revision 22655, 3.5 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 $arrPlugin;
26   
27    protected $arrInstallData;
28   
29    function __construct($arrPlugin) {
30        $this->arrPlugin = $arrPlugin;
31    }
32   
33    function execInstall() {
34        GC_Utils_Ex::gfPrintLog("start install");
35       
36        $plugin_code = $this->arrPlugin['plugin_code'];
37
38        $objQuery =& SC_Query::getSingletonInstance();
39        $objQuery->begin();
40       
41        // テーブル作成SQLなどを実行
42        $arrSql = $this->arrInstallData[$plugin_code]['sql'];
43       
44        foreach ($arrSql as $sql) {
45            GC_Utils_Ex::gfPrintLog("exec sql:" . $sql['sql']);
46            $objQuery->query($sql['sql'], $sql['params']);
47        }
48
49        // プラグインのディレクトリコピー
50        $arrCopyDirectories = $this->arrInstallData[$plugin_code]['copy_directory'];
51
52        foreach ($arrCopyDirectories as $directory) {
53            GC_Utils_Ex::gfPrintLog("exec dir copy:" . $directory['src']);
54            // ディレクトリコピー -> HTML配下とDATA配下を別関数にする
55            SC_Utils::copyDirectory(
56                    PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $directory['src'],
57                    PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $directory['dist']);
58        }
59
60        // プラグインのファイルコピー
61        $arrCopyFiles = $this->arrInstallData[$plugin_code]['copy_file'];
62
63        foreach ($arrCopyFiles as $file) {
64            GC_Utils_Ex::gfPrintLog("exec file copy:" . $file['src']);
65            // ファイルコピー
66            copy(PLUGIN_UPLOAD_REALDIR . $plugin_code . DIRECTORY_SEPARATOR . $file['src'],
67                 PLUGIN_HTML_REALDIR   . $plugin_code . DIRECTORY_SEPARATOR . $file['dist']);
68        }
69
70        $objQuery->commit();
71        GC_Utils_Ex::gfPrintLog("end install");
72       
73    }
74   
75    function copyFile($src, $dist) {
76        $plugin_code = $this->arrPlugin['plugin_code'];
77        $this->arrInstallData[$plugin_code]['copy_file'][] = array(
78            'src'    => $src,
79            'dist' => $dist
80        );
81    }
82
83    function copyDirectory($src, $dist) {
84        $plugin_code = $this->arrPlugin['plugin_code'];
85        $this->arrInstallData[$plugin_code]['copy_directory'][] = array(
86            'src'    => $src,
87            'dist' => $dist
88        );       
89    }
90
91    function removeFile($dist) {
92       
93    }
94   
95    public function sql($sql, array $params = array()) {
96        $plugin_code = $this->arrPlugin['plugin_code'];
97        $this->arrInstallData[$plugin_code]['sql'][] = array(
98            'sql'    => $sql,
99            'params' => $params
100        );
101    }
102}
Note: See TracBrowser for help on using the repository browser.