[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.3 | 6 // +---------------------------------------------------------------------------+ 7 // | addindex.php | 8 // | Add index field to Geeklog tables. | 9 // | | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2002 by the following authors: | 12 // | | 13 // | Authors: Dirk Haun - dirk@haun-online.de | 14 // | with the help of Jeffrey Schoolcraft, Marc von Ahn, and Rob Griffiths | 15 // +---------------------------------------------------------------------------+ 16 // | | 17 // | This program is free software; you can redistribute it and/or | 18 // | modify it under the terms of the GNU General Public License | 19 // | as published by the Free Software Foundation; either version 2 | 20 // | of the License, or (at your option) any later version. | 21 // | | 22 // | This program is distributed in the hope that it will be useful, | 23 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 24 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 25 // | GNU General Public License for more details. | 26 // | | 27 // | You should have received a copy of the GNU General Public License | 28 // | along with this program; if not, write to the Free Software Foundation, | 29 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 30 // | | 31 // +---------------------------------------------------------------------------+ 32 // 33 // $Id: addindex.php,v 1.3 2005/06/26 08:38:32 mjervis Exp $ 34 35 36 // Add missing indexes to Geeklog tables 37 // 38 // Date Version Author 39 // ---- ------- ------ 40 // 2002-10-22 0.1 Dirk Haun <dirk@haun-online.de> 41 // Initial version 42 // 2002-11-24 0.2 Dirk Haun <dirk@haun-online.de> 43 // Added key names for the indexes, added authentication check 44 45 require_once ('../../lib-common.php'); 46 47 if (!SEC_inGroup ('Root')) { 48 COM_errorLog ("Access denied to {$PHP_SELF} for user {$_USER['username']}, IP=" . $_SERVER['REMOTE_ADDR']); 49 $display = COM_siteHeader('menu'); 50 $display .= COM_startBlock($LANG20[1]); 51 $display .= $LANG20[6]; 52 $display .= COM_endBlock(); 53 $display .= COM_siteFooter(); 54 echo $display; 55 exit; 56 } 57 58 // $_DEBUG = 1; 59 60 // list according to Jeff's post on geeklog-devel (2002-10-14) 61 // plus stories.hits (Rob Griffiths) plus group_assignments.ug_uid 62 // <http://www.geeklog.net/article.php?story=20021011151827972> 63 64 $index['comments'] = "cid,type,sid,date,uid"; 65 $index['stories'] = "sid,tid,date,uid,frontpage,featured,hits"; 66 $index['blocks'] = "bid,is_enabled,tid,type"; 67 $index['events'] = "eid,datestart,dateend,event_type"; 68 $index['links'] = "lid,category,date"; 69 $index['pollquestions'] = "qid,date,display,commentcode,statuscode"; 70 $index['staticpage'] = "sp_id,sp_uid,sp_date,sp_onmenu"; 71 $index['userindex'] = "uid,noboxes,maxstories"; 72 $index['group_assignments'] = "ug_main_grp_id,ug_uid"; 73 74 75 echo COM_siteHeader('menu'); 76 echo COM_startBlock("Updating indexes ..."); 77 78 foreach ($index as $table=>$fields) { 79 80 $idx = explode (",", $fields); 81 82 echo "<p>Table: {$_TABLES[$table]}</p>"; 83 84 if ($_DEBUG) { 85 echo "<p>Wanted: "; 86 foreach ($idx as $id) { 87 echo "$id, "; 88 } 89 echo "</p>"; 90 } 91 92 $result = DB_query ("show index from {$_TABLES[$table]}"); 93 $nrows = DB_numRows ($result); 94 $exidx = array (); 95 for ($i = 0; $i < $nrows; $i++) { 96 $A = DB_fetchArray ($result); 97 $exidx[] = $A['Column_name']; 98 } 99 $newidx = array_diff ($idx, $exidx); 100 101 if ($_DEBUG) { 102 echo "<p>Existing: "; 103 foreach ($exidx as $ex) { 104 echo "$ex, "; 105 } 106 echo "</p>"; 107 } 108 109 if ($_DEBUG) { 110 echo "<p>Need to add: "; 111 foreach ($newidx as $ne) { 112 echo "$ne, "; 113 } 114 echo "</p>"; 115 } 116 117 if (sizeof ($newidx) > 0) { 118 echo "<p>Adding indexes ...<br>"; 119 foreach ($newidx as $ne) { 120 $idxname = $table . '_' . $ne; 121 echo "Adding index \"$idxname\""; 122 flush (); 123 124 $idxtimer = new timerobject (); 125 $idxtimer->setPercision (4); 126 $idxtimer->startTimer (); 127 128 DB_query("ALTER TABLE {$_TABLES[$table]} ADD INDEX $idxname ($ne)"); 129 130 $idxtime = $idxtimer->stopTimer (); 131 $idxtimer->setPercision (4); 132 echo " in $idxtime seconds<br>"; 133 } 134 echo "Done!</p>"; 135 } else { 136 echo "<p>No index to add for table {$_TABLES[$table]}</p>"; 137 } 138 139 echo "<hr>"; 140 } 141 142 echo COM_endBlock(); 143 echo COM_siteFooter(); 144 145 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |