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

Revision 22665, 4.0 KB checked in by adachi, 11 years ago (diff)

#2181 query追加

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