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

Revision 19805, 5.4 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部実装

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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_REALDIR . "pages/LC_Page.php");
26
27/**
28 * システム情報 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id: LC_Page_Admin_System_Editdb.php 18701 2010-06-14 08:30:18Z nanasess $
33 */
34class LC_Page_Admin_System_Editdb extends LC_Page {
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_subnavi  = 'system/subnavi.tpl';
48        $this->tpl_subno    = 'editdb';
49        $this->tpl_mainno   = 'system';
50        $this->tpl_subtitle = '高度なデータベース管理';
51    }
52
53    /**
54     * フォームパラメータ初期化
55     *
56     * @return void
57     */
58    function initForm() {
59        $objForm = new SC_FormParam();
60        $objForm->addParam('mode', 'mode', INT_LEN, '', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
61        $objForm->addParam('table_name', 'テーブル名');
62        $objForm->addParam('column_name', 'カラム名');
63        $objForm->addParam('indexflag', 'インデックス');
64    $objForm->addParam('indexflag_new', 'インデックス(変更後)');
65   
66    $objForm->setParam($_POST);
67        $this->objForm = $objForm;
68    }
69
70    /**
71     * Page のプロセス.
72     *
73     * @return void
74     */
75    function process() {
76
77        SC_Utils_Ex::sfIsSuccess(new SC_Session);
78        $objView = new SC_AdminView();
79    $objSiteInfo = new SC_SiteInfo();
80        $objQuery = new SC_Query();
81        $objDb = new SC_Helper_DB_Ex();
82        $objProduct = new SC_Product();
83
84    //インデックスの値を取得
85    $this->arrForm = $this->lfGetIndexList();
86
87    //フォームの値を取得
88        $this->initForm();
89   
90        switch($this->objForm->getValue('mode')) {
91    //確認画面へ
92    case 'confirm' :
93        //POSTの値と配列の値を比較
94        // TODO: $_POSTを使わないように修正する。
95            $arrIndexFlag  = $_POST['indexflag'];
96            $arrIndexFlagNewIndex  = $_POST['indexflag_new'];
97
98            $arrIndexFlagNew = array();
99            for($i = 0; $i < count($arrIndexFlag); $i++) {
100                if(array_search($i, $arrIndexFlagNewIndex) !== false) {
101                    $arrIndexFlagNew[] = true;
102                } else {
103                    $arrIndexFlagNew[] = false;
104        }
105        }
106
107            $objQuery = new SC_Query();
108        foreach($arrIndexFlag as $key => $val){
109        if($val != $arrIndexFlagNew[$key]) {
110                    //値が異なっていた場合、インデックスのアップデートをかける
111                    $index_name = $_POST["table_name"][$key] . "_" . $_POST["column_name"][$key] . "_key";
112                    if($arrIndexFlagNew[$key] == false) {
113                        $objQuery->dropIndex($_POST["table_name"][$key], $index_name);
114                    } else {
115                        $objQuery->createIndex($_POST["table_name"][$key], $index_name, array('fields' => array($_POST["column_name"][$key] => array())));
116                    }
117
118                    // フォームに引継ぐ
119                    $this->arrForm[$key]["indexflag"] = true;
120        }
121        }
122       
123        $this->tpl_onload = "window.alert('インデックスの変更が完了しました。');";
124        default:
125        break;
126        }
127
128        $objView->assignobj($this);
129        $objView->display(MAIN_FRAME);
130    }
131
132    /**
133     * デストラクタ.
134     *
135     * @return void
136     */
137    function destroy() {
138        parent::destroy();
139    }
140   
141    /**
142     * インデックス設定を行う一覧を返す関数
143     *
144     * @return void
145     */
146    function lfGetIndexList()
147    {
148        // データベースからインデックス設定一覧を取得する
149        $objQuery = new SC_Query();
150        $objQuery->setOrder("table_name, column_name");
151        $arrIndexList = $objQuery->select("table_name , column_name , recommend_flg, recommend_comment", "dtb_index_list");
152
153        $table = "";
154        foreach($arrIndexList as $key => $arrIndex) {
155            // テーブルに対するインデックス一覧を取得
156            if($table !== $arrIndex["table_name"]) {
157                $table = $arrIndex["table_name"];
158                $arrIndexes = $objQuery->listTableIndexes($table);
159            }
160 
161            // インデックスが設定されているかを取得
162            if(array_search($table . "_" . $arrIndex["column_name"] . "_key", $arrIndexes) === false) {
163                $arrIndexList[$key]["indexflag"] = false;
164            } else {
165                $arrIndexList[$key]["indexflag"] = true;
166            }
167        }
168   
169        return $arrIndexList;
170    }
171   
172}
Note: See TracBrowser for help on using the repository browser.