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

Revision 22857, 7.6 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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