Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_System_Editdb.php

Documentation is available at LC_Page_Admin_System_Editdb.php

  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
  25. require_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: LC_Page_Admin_System_Editdb.php 20970 2011-06-10 10:27:24Z Seasoft $
  33.  */
  34. class 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.         $objFormParam new SC_FormParam_Ex();
  71.  
  72.         // パラメーターの初期化
  73.         $this->initForm($objFormParam$_POST);
  74.  
  75.         switch($this->getMode()) {
  76.         case 'confirm' :
  77.             $message $this->lfDoChange($objFormParam);
  78.             if (!is_array($message&& $message != ""{
  79.                 $this->tpl_onload $message;
  80.             }
  81.             break;
  82.         default:
  83.             break;
  84.     }
  85.  
  86.         //インデックスの現在値を取得
  87.         $this->arrForm $this->lfGetIndexList();
  88.     }
  89.  
  90.     /**
  91.      * デストラクタ.
  92.      *
  93.      * @return void 
  94.      */
  95.     function destroy({
  96.         parent::destroy();
  97.     }
  98.  
  99.     /**
  100.      * フォームパラメーター初期化
  101.      *
  102.      * @param object $objFormParam 
  103.      * @param array $arrParams $_POST値
  104.      * @return void 
  105.      */
  106.     function initForm(&$objFormParam&$arrParams{
  107.  
  108.         $objFormParam->addParam('モード''mode'INT_LEN'n'array('ALPHA_CHECK''MAX_LENGTH_CHECK'));
  109.         $objFormParam->addParam('テーブル名''table_name');
  110.         $objFormParam->addParam('カラム名''column_name');
  111.         $objFormParam->addParam('インデックス''indexflag');
  112.         $objFormParam->addParam('インデックス(変更後)''indexflag_new');
  113.         $objFormParam->setParam($arrParams);
  114.  
  115.     }
  116.  
  117.     function lfDoChange(&$objFormParam{
  118.         $objQuery =SC_Query_Ex::getSingletonInstance();
  119.         $arrTarget $this->lfGetTargetData($objFormParam);
  120.         $message "";
  121.         if(is_array($arrTarget&& count($arrTarget== 0{
  122.             $message "window.alert('変更対象となるデータはありませんでした。');";
  123.             return $message;
  124.         elseif(!is_array($arrTarget&& $arrTarget != ""{
  125.             return $arrTarget// window.alert が返ってきているはず。
  126.         }
  127.  
  128.         // 変更対象の設定変更
  129.         foreach($arrTarget as $item{
  130.             $index_name $item['table_name''_' $item['column_name'"_key";
  131.             $arrField array'fields' => array($item['column_name'=> array()));
  132.             if($item['indexflag_new'== '1'{
  133.                 $objQuery->createIndex($item['table_name']$index_name$arrField);
  134.             }else{
  135.                 $objQuery->dropIndex($item['table_name']$index_name);
  136.             }
  137.         }
  138.         $message "window.alert('インデックスの変更が完了しました。');";
  139.         return $message;
  140.     }
  141.  
  142.     function lfGetTargetData(&$objFormParam{
  143.         $objQuery =SC_Query_Ex::getSingletonInstance();
  144.         $arrIndexFlag    $objFormParam->getValue('indexflag');
  145.         $arrIndexFlagNew $objFormParam->getValue('indexflag_new');
  146.         $arrTableName    $objFormParam->getValue('table_name');
  147.         $arrColumnName   $objFormParam->getValue('column_name');
  148.         $arrTarget array();
  149.         $message "";
  150.  
  151.         // 変更されている対象を走査
  152.         for($i 1$i <= count($arrIndexFlag)$i++{
  153.             //入力値チェック
  154.             $param array('indexflag' => $arrIndexFlag[$i],
  155.                             'indexflag_new' => $arrIndexFlagNew[$i],
  156.                             'table_name' => $arrTableName[$i],
  157.                             'column_name' => $arrColumnName[$i]);
  158.             $objErr new SC_CheckError_Ex($param);
  159.             $objErr->doFunc(array("インデックス(" $i ")"'indexflag'INT_LEN)array("NUM_CHECK"));
  160.             $objErr->doFunc(array("インデックス変更後(" $i ")"'indexflag_new'INT_LEN)array("NUM_CHECK"));
  161.             $objErr->doFunc(array("インデックス変更後(" $i ")"'indexflag_new'INT_LEN)array("NUM_CHECK"));
  162.             $objErr->doFunc(array("テーブル名(" $i ")"'table_name'STEXT_LEN)array("GRAPH_CHECK""EXIST_CHECK""MAX_LENGTH_CHECK"));
  163.             $objErr->doFunc(array("カラム名(" $i ")"'column_name'STEXT_LEN)array("GRAPH_CHECK""EXIST_CHECK""MAX_LENGTH_CHECK"));
  164.             $arrErr $objErr->arrErr;
  165.             if(count($arrErr!= 0{
  166.                 // 通常の送信ではエラーにならないはずです。
  167.                 $message "window.alert('不正なデータがあったため処理を中断しました。');";
  168.                 return $message;
  169.             }
  170.             if($param['indexflag'!= $param['indexflag_new']{
  171.                 // 入力値がデータにある対象テーブルかのチェック
  172.                 if($objQuery->count('dtb_index_list''table_name = ? and column_name = ?'array($param['table_name']$param['column_name']))) {
  173.                     $arrTarget[$param;
  174.                 }
  175.             }
  176.         }
  177.         return $arrTarget;
  178.     }
  179.  
  180.     /**
  181.      * インデックス設定を行う一覧を返す関数
  182.      *
  183.      * @return void 
  184.      */
  185.     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.         return $arrIndexList;
  208.     }
  209.  
  210. }

Documentation generated on Fri, 24 Feb 2012 14:01:48 +0900 by Seasoft