Changeset 20037
- Timestamp:
- 2011/01/25 04:00:29 (12 years ago)
- Location:
- branches/version-2_5-dev/data
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/Smarty/templates/admin/system/editdb.tpl
r19965 r20037 29 29 </div> 30 30 <table class="list"> 31 <colgroup width="8%"> 31 <colgroup width="5%"> 32 <colgroup width="5%"> 32 33 <colgroup width="28%"> 33 34 <colgroup width="25%"> 34 <colgroup width="4 5%">35 <colgroup width="43%"> 35 36 <tr> 36 <th>インデックス</th> 37 <th>テーブル名</th> 38 <th>カラム名</th> 39 <th>説明</th> 37 <th colspan="2">インデックス</th> 38 <th rowspan="2">テーブル名</th> 39 <th rowspan="2">カラム名</th> 40 <th rowspan="2">説明</th> 41 </tr> 42 <tr> 43 <th>ON</th> 44 <th>OFF</th> 40 45 </tr> 41 46 … … 44 49 45 50 <tr> 46 <td class="center"><input type="checkbox" name="indexflag_new[]" value="<!--{$smarty.section.cnt.index}-->" <!--{if $arrForm[cnt].indexflag == "1"}-->checked<!--{/if}--> /></td> 51 <td class="center"><input type="radio" name="indexflag_new[<!--{$smarty.section.cnt.iteration}-->]" value="1" <!--{if $arrForm[cnt].indexflag == "1"}-->checked<!--{/if}--> /></td> 52 <td class="center"><input type="radio" name="indexflag_new[<!--{$smarty.section.cnt.iteration}-->]" value="" <!--{if $arrForm[cnt].indexflag != "1"}-->checked<!--{/if}--> /></td> 47 53 <th class="column"><!--{$arrForm[cnt].table_name}--></th> 48 54 <th class="column"><!--{$arrForm[cnt].column_name}--></th> 49 55 <td><!--{$arrForm[cnt].recommend_comment}--></td> 50 56 </tr> 51 <input type="hidden" name="table_name[ ]" value="<!--{$arrForm[cnt].table_name}-->" />52 <input type="hidden" name="column_name[ ]" value="<!--{$arrForm[cnt].column_name}-->" />53 <input type="hidden" name="indexflag[ ]" value="<!--{$arrForm[cnt].indexflag}-->" />57 <input type="hidden" name="table_name[<!--{$smarty.section.cnt.iteration}-->]" value="<!--{$arrForm[cnt].table_name}-->" /> 58 <input type="hidden" name="column_name[<!--{$smarty.section.cnt.iteration}-->]" value="<!--{$arrForm[cnt].column_name}-->" /> 59 <input type="hidden" name="indexflag[<!--{$smarty.section.cnt.iteration}-->]" value="<!--{$arrForm[cnt].indexflag}-->" /> 54 60 55 61 <!--{/section}--> -
branches/version-2_5-dev/data/class/SC_Query.php
r19805 r20037 791 791 * @param string $name インデックス名 792 792 * @param array $definition フィールド名など 通常のフィールド指定時は、$definition=array('fields' => array('フィールド名' => array())); 793 * MySQLのtext型フィールドを指定する場合は $definition['length'] = 'text_field(NNN)' が必要 793 794 */ 794 795 function createIndex($table, $name, $definition) { 796 $definition = $this->dbFactory->sfGetCreateIndexDefinition($table, $name, $definition); 795 797 $objManager =& $this->conn->loadModule('Manager'); 796 798 return $objManager->createIndex($table, $name, $definition); … … 807 809 return $objManager->dropIndex($table, $name); 808 810 } 809 811 812 /** 813 * テーブルの詳細情報を取得する。 814 * 815 * @param string $table テーブル名 816 * @return array テーブル情報の配列 817 */ 818 function getTableInfo($table) { 819 $objManager =& $this->conn->loadModule('Reverse'); 820 return $objManager->tableInfo($table, NULL); 821 } 822 810 823 /** 811 824 * 値を適切にクォートする. -
branches/version-2_5-dev/data/class/db/SC_DB_DBFactory.php
r19805 r20037 156 156 */ 157 157 function findTableNames($expression = "") { return array(); } 158 159 /** 160 * インデックス作成の追加定義を取得する 161 * 162 * 引数に部分一致するテーブル名を配列で返す. 163 * 164 * @param string $table 対象テーブル名 165 * @param string $name 対象カラム名 166 * @return array インデックス設定情報配列 167 */ 168 function sfGetCreateIndexDefinition($table, $name, $definition) { return $definition; } 169 158 170 } 159 171 ?> -
branches/version-2_5-dev/data/class/db/dbfactory/SC_DB_DBFactory_MYSQL.php
r20024 r20037 434 434 435 435 } 436 437 /** 438 * インデックス作成の追加定義を取得する 439 * 440 * 引数に部分一致するテーブル名を配列で返す. 441 * 442 * @param string $table 対象テーブル名 443 * @param string $name 対象カラム名 444 * @return array インデックス設定情報配列 445 */ 446 function sfGetCreateIndexDefinition($table, $name, $definition) { 447 $objQuery =& SC_Query::getSingletonInstance(); 448 $arrTblInfo = $objQuery->getTableInfo($table); 449 foreach($arrTblInfo as $fieldInfo) { 450 if(array_key_exists($fieldInfo['name'], $definition['fields'])) { 451 if($fieldInfo['nativetype'] == 'text') { 452 // TODO: text型フィールドの場合に255文字以内決めうちでインデックス列のサイズとして 453 // 指定して良いか確認は必要。 454 $definition['fields'][$fieldInfo['name']]['length'] = '255'; 455 } 456 } 457 } 458 return $definition; 459 } 436 460 } 437 461 ?> -
branches/version-2_5-dev/data/class/pages/admin/system/LC_Page_Admin_System_Editdb.php
r19805 r20037 23 23 24 24 // {{{ requires 25 require_once (CLASS_REALDIR . "pages/LC_Page.php");25 require_once CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"; 26 26 27 27 /** 28 * システム情報のページクラス.28 * 高度なデータベース管理 のページクラス. 29 29 * 30 30 * @package Page … … 32 32 * @version $Id: LC_Page_Admin_System_Editdb.php 18701 2010-06-14 08:30:18Z nanasess $ 33 33 */ 34 class LC_Page_Admin_System_Editdb extends LC_Page {34 class LC_Page_Admin_System_Editdb extends LC_Page_Admin { 35 35 36 36 // }}} … … 44 44 function init() { 45 45 parent::init(); 46 46 47 $this->tpl_mainpage = 'system/editdb.tpl'; 47 48 $this->tpl_subnavi = 'system/subnavi.tpl'; … … 58 59 function initForm() { 59 60 $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); 61 $objForm->addParam('モード', 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK')); 62 $objForm->addParam('テーブル名', 'table_name'); 63 $objForm->addParam('カラム名', 'column_name'); 64 $objForm->addParam('インデックス', 'indexflag'); 65 $objForm->addParam('インデックス(変更後)', 'indexflag_new'); 66 $objForm->setParam($_POST); 67 67 $this->objForm = $objForm; 68 68 } … … 74 74 */ 75 75 function process() { 76 $this->action(); 77 $this->sendResponse(); 78 } 76 79 80 /** 81 * Page のアクション. 82 * 83 * @return void 84 */ 85 function action() { 77 86 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 87 84 //インデックスの値を取得85 $this->arrForm = $this->lfGetIndexList();88 //フォームの値を取得 89 $this->initForm(); 86 90 87 //フォームの値を取得88 $this->initForm();89 90 91 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 } 92 case 'confirm' : 93 $this->lfDoChange(); 94 break; 95 default: 96 break; 105 97 } 106 98 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); 99 //インデックスの現在値を取得 100 $this->arrForm = $this->lfGetIndexList(); 130 101 } 131 102 … … 139 110 } 140 111 112 function lfGetTargetData() { 113 $objQuery = new SC_Query(); 114 $arrIndexFlag = $this->objForm->getValue('indexflag'); 115 $arrIndexFlagNew = $this->objForm->getValue('indexflag_new'); 116 $arrTableName = $this->objForm->getValue('table_name'); 117 $arrColumnName =$this->objForm->getValue('column_name'); 118 $arrTarget = array(); 119 // 変更されている対象を走査 120 for($i = 1; $i <= count($arrIndexFlag); $i++) { 121 //入力値チェック 122 $param = array('indexflag' => $arrIndexFlag[$i], 123 'indexflag_new' => $arrIndexFlagNew[$i], 124 'table_name' => $arrTableName[$i], 125 'column_name' => $arrColumnName[$i]); 126 $objErr = new SC_CheckError($param); 127 $objErr->doFunc(array("インデックス(" . $i . ")", 'indexflag', INT_LEN), array("NUM_CHECK")); 128 $objErr->doFunc(array("インデックス変更後(" . $i . ")", 'indexflag_new', INT_LEN), array("NUM_CHECK")); 129 $objErr->doFunc(array("インデックス変更後(" . $i . ")", 'indexflag_new', INT_LEN), array("NUM_CHECK")); 130 $objErr->doFunc(array("テーブル名(" . $i . ")", 'table_name', STEXT_LEN), array("GRAPH_CHECK", "EXIST_CHECK", "MAX_LENGTH_CHECK")); 131 $objErr->doFunc(array("カラム名(" . $i . ")", 'column_name', STEXT_LEN), array("GRAPH_CHECK", "EXIST_CHECK", "MAX_LENGTH_CHECK")); 132 $arrErr = $objErr->arrErr; 133 if(count($arrErr) != 0) { 134 // 通常の送信ではエラーにならないはずです。 135 $this->tpl_onload = "window.alert('不正なデータがあったため処理を中断しました。');"; 136 return; 137 } 138 if($param['indexflag'] != $param['indexflag_new']) { 139 // 入力値がデータにある対象テーブルかのチェック 140 if($objQuery->count('dtb_index_list', 'table_name = ? and column_name = ?', array($param['table_name'], $param['column_name']))) { 141 $arrTarget[] = $param; 142 } 143 } 144 } 145 return $arrTarget; 146 } 147 148 function lfDoChange() { 149 $objQuery = new SC_Query(); 150 $arrTarget = $this->lfGetTargetData(); 151 if(count($arrTarget) == 0) { 152 $this->tpl_onload = "window.alert('変更対象となるデータはありませんでした。');"; 153 return; 154 } 155 156 // 変更対象の設定変更 157 foreach($arrTarget as $item) { 158 $index_name = $item['table_name'] . '_' . $item['column_name'] . "_key"; 159 $arrField = array( 'fields' => array($item['column_name'] => array())); 160 if($item['indexflag_new'] == '1') { 161 $objQuery->createIndex($item['table_name'], $index_name, $arrField); 162 }else{ 163 $objQuery->dropIndex($item['table_name'], $index_name); 164 } 165 } 166 $this->tpl_onload = "window.alert('インデックスの変更が完了しました。');"; 167 } 168 141 169 /** 142 170 * インデックス設定を行う一覧を返す関数 … … 158 186 $arrIndexes = $objQuery->listTableIndexes($table); 159 187 } 160 161 188 // インデックスが設定されているかを取得 162 if(array_search($table . "_" . $arrIndex["column_name"] . "_key", $arrIndexes) === false) { 163 $arrIndexList[$key]["indexflag"] = false; 189 $idx_name = $table . "_" . $arrIndex["column_name"] . "_key"; 190 if(array_search($idx_name, $arrIndexes) === false) { 191 $arrIndexList[$key]["indexflag"] = ''; 164 192 } else { 165 $arrIndexList[$key]["indexflag"] = true;193 $arrIndexList[$key]["indexflag"] = '1'; 166 194 } 167 195 } 168 169 196 return $arrIndexList; 170 197 }
Note: See TracChangeset
for help on using the changeset viewer.