source: branches/version-2_13_0/data/class/pages/admin/system/LC_Page_Admin_System_Editdb.php @ 23126

Revision 23126, 7.5 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

  • 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    public 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    public function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    public 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     * @param  object $objFormParam
92     * @param  array  $arrParams    $_POST値
93     * @return void
94     */
95    public function initForm(&$objFormParam, &$arrParams)
96    {
97        $objFormParam->addParam('モード', 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
98        $objFormParam->addParam('テーブル名', 'table_name');
99        $objFormParam->addParam('カラム名', 'column_name');
100        $objFormParam->addParam('インデックス', 'indexflag');
101        $objFormParam->addParam('インデックス(変更後)', 'indexflag_new');
102        $objFormParam->setParam($arrParams);
103    }
104
105    public function lfDoChange(&$objFormParam)
106    {
107        $objQuery =& SC_Query_Ex::getSingletonInstance();
108        $arrTarget = $this->lfGetTargetData($objFormParam);
109        $message = '';
110        if (is_array($arrTarget) && count($arrTarget) == 0) {
111            $message = "window.alert('変更対象となるデータはありませんでした。');";
112
113            return $message;
114        } elseif (!is_array($arrTarget) && $arrTarget != '') {
115            return $arrTarget; // window.alert が返ってきているはず。
116        }
117
118        // 変更対象の設定変更
119        foreach ($arrTarget as $item) {
120            $index_name = $item['table_name'] . '_' . $item['column_name'] . '_key';
121            $arrField = array('fields' => array($item['column_name'] => array()));
122            if ($item['indexflag_new'] == '1') {
123                $objQuery->createIndex($item['table_name'], $index_name, $arrField);
124            } else {
125                $objQuery->dropIndex($item['table_name'], $index_name);
126            }
127        }
128        $message = "window.alert('インデックスの変更が完了しました。');";
129
130        return $message;
131    }
132
133    public function lfGetTargetData(&$objFormParam)
134    {
135        $objQuery =& SC_Query_Ex::getSingletonInstance();
136        $arrIndexFlag    = $objFormParam->getValue('indexflag');
137        $arrIndexFlagNew = $objFormParam->getValue('indexflag_new');
138        $arrTableName    = $objFormParam->getValue('table_name');
139        $arrColumnName   = $objFormParam->getValue('column_name');
140        $arrTarget = array();
141        $message = '';
142
143        // 変更されている対象を走査
144        for ($i = 1; $i <= count($arrIndexFlag); $i++) {
145            //入力値チェック
146            $param = array('indexflag' => $arrIndexFlag[$i],
147                            'indexflag_new' => $arrIndexFlagNew[$i],
148                            'table_name' => $arrTableName[$i],
149                            'column_name' => $arrColumnName[$i]);
150            $objErr = new SC_CheckError_Ex($param);
151            $objErr->doFunc(array('インデックス(' . $i . ')', 'indexflag', INT_LEN), array('NUM_CHECK'));
152            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
153            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
154            $objErr->doFunc(array('テーブル名(' . $i . ')', 'table_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
155            $objErr->doFunc(array('カラム名(' . $i . ')', 'column_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
156            $arrErr = $objErr->arrErr;
157            if (count($arrErr) != 0) {
158                // 通常の送信ではエラーにならないはずです。
159                $message = "window.alert('不正なデータがあったため処理を中断しました。');";
160
161                return $message;
162            }
163            if ($param['indexflag'] != $param['indexflag_new']) {
164                // 入力値がデータにある対象テーブルかのチェック
165                if ($objQuery->exists('dtb_index_list', 'table_name = ? and column_name = ?', array($param['table_name'], $param['column_name']))) {
166                    $arrTarget[] = $param;
167                }
168            }
169        }
170
171        return $arrTarget;
172    }
173
174    /**
175     * インデックス設定を行う一覧を返す関数
176     *
177     * @return void
178     */
179    public function lfGetIndexList()
180    {
181        // データベースからインデックス設定一覧を取得する
182        $objQuery =& SC_Query_Ex::getSingletonInstance();
183        $objQuery->setOrder('table_name, column_name');
184        $arrIndexList = $objQuery->select('table_name , column_name , recommend_flg, recommend_comment', 'dtb_index_list');
185
186        $table = '';
187        foreach ($arrIndexList as $key => $arrIndex) {
188            // テーブルに対するインデックス一覧を取得
189            if ($table !== $arrIndex['table_name']) {
190                $table = $arrIndex['table_name'];
191                $arrIndexes = $objQuery->listTableIndexes($table);
192            }
193            // インデックスが設定されているかを取得
194            $idx_name = $table . '_' . $arrIndex['column_name'] . '_key';
195            if (array_search($idx_name, $arrIndexes) === false) {
196                $arrIndexList[$key]['indexflag'] = '';
197            } else {
198                $arrIndexList[$key]['indexflag'] = '1';
199            }
200        }
201
202        return $arrIndexList;
203    }
204}
Note: See TracBrowser for help on using the repository browser.