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

Revision 23607, 7.7 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/e168461a-0ee4-40cd-8b59-bbf58965f139/patches

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