source: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Editdb.php @ 21689

Revision 21689, 8.1 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * 高度なデータベース管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_System_Editdb extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'system/editdb.tpl';
47        $this->tpl_subno    = 'editdb';
48        $this->tpl_mainno   = 'system';
49        $this->tpl_maintitle = 'システム設定';
50        $this->tpl_subtitle = '高度なデータベース管理';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
69        // フックポイント.
70        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
71        $objPlugin->doAction('lc_page_admin_system_editdb_action_start', array($this));
72
73        $objFormParam = new SC_FormParam_Ex();
74
75        // パラメーターの初期化
76        $this->initForm($objFormParam, $_POST);
77
78        switch ($this->getMode()) {
79            case 'confirm' :
80                $message = $this->lfDoChange($objFormParam);
81                if (!is_array($message) && $message != '') {
82                    $this->tpl_onload = $message;
83                }
84                break;
85            default:
86                break;
87        }
88
89        //インデックスの現在値を取得
90        $this->arrForm = $this->lfGetIndexList();
91
92        // フックポイント.
93        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
94        $objPlugin->doAction('lc_page_admin_system_editdb_action_end', array($this));
95    }
96
97    /**
98     * デストラクタ.
99     *
100     * @return void
101     */
102    function destroy() {
103        parent::destroy();
104    }
105
106    /**
107     * フォームパラメーター初期化
108     *
109     * @param object $objFormParam
110     * @param array $arrParams $_POST値
111     * @return void
112     */
113    function initForm(&$objFormParam, &$arrParams) {
114
115        $objFormParam->addParam('モード', 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
116        $objFormParam->addParam('テーブル名', 'table_name');
117        $objFormParam->addParam('カラム名', 'column_name');
118        $objFormParam->addParam('インデックス', 'indexflag');
119        $objFormParam->addParam('インデックス(変更後)', 'indexflag_new');
120        $objFormParam->setParam($arrParams);
121
122    }
123
124    function lfDoChange(&$objFormParam) {
125        $objQuery =& SC_Query_Ex::getSingletonInstance();
126        $arrTarget = $this->lfGetTargetData($objFormParam);
127        $message = '';
128        if (is_array($arrTarget) && count($arrTarget) == 0) {
129            $message = "window.alert('変更対象となるデータはありませんでした。');";
130            return $message;
131        } elseif (!is_array($arrTarget) && $arrTarget != '') {
132            return $arrTarget; // window.alert が返ってきているはず。
133        }
134
135        // 変更対象の設定変更
136        foreach ($arrTarget as $item) {
137            $index_name = $item['table_name'] . '_' . $item['column_name'] . '_key';
138            $arrField = array('fields' => array($item['column_name'] => array()));
139            if ($item['indexflag_new'] == '1') {
140                $objQuery->createIndex($item['table_name'], $index_name, $arrField);
141            } else {
142                $objQuery->dropIndex($item['table_name'], $index_name);
143            }
144        }
145        $message = "window.alert('インデックスの変更が完了しました。');";
146        return $message;
147    }
148
149    function lfGetTargetData(&$objFormParam) {
150        $objQuery =& SC_Query_Ex::getSingletonInstance();
151        $arrIndexFlag    = $objFormParam->getValue('indexflag');
152        $arrIndexFlagNew = $objFormParam->getValue('indexflag_new');
153        $arrTableName    = $objFormParam->getValue('table_name');
154        $arrColumnName   = $objFormParam->getValue('column_name');
155        $arrTarget = array();
156        $message = '';
157
158        // 変更されている対象を走査
159        for ($i = 1; $i <= count($arrIndexFlag); $i++) {
160            //入力値チェック
161            $param = array('indexflag' => $arrIndexFlag[$i],
162                            'indexflag_new' => $arrIndexFlagNew[$i],
163                            'table_name' => $arrTableName[$i],
164                            'column_name' => $arrColumnName[$i]);
165            $objErr = new SC_CheckError_Ex($param);
166            $objErr->doFunc(array('インデックス(' . $i . ')', 'indexflag', INT_LEN), array('NUM_CHECK'));
167            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
168            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
169            $objErr->doFunc(array('テーブル名(' . $i . ')', 'table_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
170            $objErr->doFunc(array('カラム名(' . $i . ')', 'column_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
171            $arrErr = $objErr->arrErr;
172            if (count($arrErr) != 0) {
173                // 通常の送信ではエラーにならないはずです。
174                $message = "window.alert('不正なデータがあったため処理を中断しました。');";
175                return $message;
176            }
177            if ($param['indexflag'] != $param['indexflag_new']) {
178                // 入力値がデータにある対象テーブルかのチェック
179                if ($objQuery->exists('dtb_index_list', 'table_name = ? and column_name = ?', array($param['table_name'], $param['column_name']))) {
180                    $arrTarget[] = $param;
181                }
182            }
183        }
184        return $arrTarget;
185    }
186
187    /**
188     * インデックス設定を行う一覧を返す関数
189     *
190     * @return void
191     */
192    function lfGetIndexList() {
193        // データベースからインデックス設定一覧を取得する
194        $objQuery =& SC_Query_Ex::getSingletonInstance();
195        $objQuery->setOrder('table_name, column_name');
196        $arrIndexList = $objQuery->select('table_name , column_name , recommend_flg, recommend_comment', 'dtb_index_list');
197
198        $table = '';
199        foreach ($arrIndexList as $key => $arrIndex) {
200            // テーブルに対するインデックス一覧を取得
201            if ($table !== $arrIndex['table_name']) {
202                $table = $arrIndex['table_name'];
203                $arrIndexes = $objQuery->listTableIndexes($table);
204            }
205            // インデックスが設定されているかを取得
206            $idx_name = $table . '_' . $arrIndex['column_name'] . '_key';
207            if (array_search($idx_name, $arrIndexes) === false) {
208                $arrIndexList[$key]['indexflag'] = '';
209            } else {
210                $arrIndexList[$key]['indexflag'] = '1';
211            }
212        }
213        return $arrIndexList;
214    }
215
216}
Note: See TracBrowser for help on using the repository browser.