Changeset 4931
- Timestamp:
- 02/04/06 18:19:20 (2 years ago)
- Files:
-
- wp-dbmanager/trunk/database-manager.php (modified) (20 diffs)
- wp-dbmanager/trunk/readme-upgrade.txt (modified) (1 diff)
- wp-dbmanager/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wp-dbmanager/trunk/database-manager.php
r4876 r4931 49 49 ### Format Bytes Into KB/MB 50 50 function format_size($rawSize) { 51 if ($rawSize / 1048576 > 1) 51 if($rawSize / 1073741824 > 1) 52 return round($rawSize/1048576, 1) . ' GB'; 53 else if ($rawSize / 1048576 > 1) 52 54 return round($rawSize/1048576, 1) . ' MB'; 53 55 else if ($rawSize / 1024 > 1) … … 55 57 else 56 58 return round($rawSize, 1) . ' bytes'; 59 } 60 61 62 ### Get File Extension 63 function file_ext($file_name) { 64 return substr(strrchr($file_name, '.'), 1); 57 65 } 58 66 … … 84 92 $database_file = trim($_POST['database_file']); 85 93 $optimize = $_POST['optimize']; 94 $emptydrop = $_POST['emptydrop']; 86 95 $delete = $_POST['delete']; 87 96 $nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10)); … … 152 161 if(!empty($database_file)) { 153 162 $file_path = $backup['path'].'/'.$database_file; 154 $nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13);163 //$nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13); 155 164 header("Pragma: public"); 156 165 header("Expires: 0"); … … 159 168 header("Content-Type: application/octet-stream"); 160 169 header("Content-Type: application/download"); 161 header("Content-Disposition: attachment; filename=".basename($ nice_file_name).";");170 header("Content-Disposition: attachment; filename=".basename($database_file).";"); 162 171 header("Content-Transfer-Encoding: binary"); 163 172 header("Content-Length: ".filesize($file_path)); … … 168 177 break; 169 178 case 'Optimize': 170 foreach($optimize as $key => $value) { 171 if($value == 'yes') { 172 $tables_string .= ', '.$key; 173 } 179 if(!empty($optimize)) { 180 foreach($optimize as $key => $value) { 181 if($value == 'yes') { 182 $tables_string .= ', '.$key; 183 } 184 } 185 } else { 186 $text = '<font color="red">No Tables Selected</font>'; 174 187 } 175 188 $selected_tables = substr($tables_string, 2); … … 177 190 $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables"); 178 191 if(!$optimize2) { 179 $text = "<font color=\"red\">Table(s) '$selected_tables' Failed To BeOptimized</font>";192 $text = "<font color=\"red\">Table(s) '$selected_tables' NOT Optimized</font>"; 180 193 } else { 181 $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized Successfully</font>"; 182 } 183 } else { 184 $text = '<font color="red">No Tables Selected</font>'; 194 $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized</font>"; 195 } 185 196 } 186 197 break; … … 201 212 if($sql_queries) { 202 213 foreach($sql_queries as $sql_query) { 203 if (preg_match("/^\\s*(insert|update|replace|delete|create ) /i",$sql_query)) {214 if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) { 204 215 $run_query = $wpdb->query($sql_query); 205 216 if(!$run_query) { … … 223 234 } 224 235 break; 236 case 'Empty/Drop': 237 $empty_tables = array(); 238 if(!empty($emptydrop)) { 239 foreach($emptydrop as $key => $value) { 240 if($value == 'empty') { 241 $empty_tables[] = $key; 242 } elseif($value == 'drop') { 243 $drop_tables .= ', '.$key; 244 } 245 } 246 } else { 247 $text = '<font color="red">No Tables Selected</font>'; 248 } 249 $drop_tables = substr($drop_tables, 2); 250 if(!empty($empty_tables)) { 251 foreach($empty_tables as $empty_table) { 252 $empty_query = $wpdb->query("TRUNCATE $empty_table"); 253 $text .= "<font color=\"green\">Table '$empty_table' Emptied</font><br />"; 254 } 255 } 256 if(!empty($drop_tables)) { 257 $drop_query = $wpdb->query("DROP TABLE $drop_tables"); 258 $text = "<font color=\"green\">Table(s) '$drop_tables' Dropped</font>"; 259 } 260 break; 225 261 } 226 262 } … … 241 277 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 242 278 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 243 <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 279 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 280 <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 244 281 </ul> 282 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 245 283 <!-- Backup Database --> 246 284 <div class="wrap"> 247 285 <h2>Backup Database</h2> 248 <form action="<? =$_SERVER['PHP_SELF']?>" method="post">286 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=backup" method="post"> 249 287 <table width="100%" cellspacing="3" cellpadding="3" border="0"> 250 288 <tr style='background-color: #eee'> 251 289 <th align="left" scope="row">Database Name:</th> 252 <td><? =DB_NAME?></td>290 <td><?php echo DB_NAME; ?></td> 253 291 </tr> 254 292 <tr style='background-color: none'> 255 293 <th align="left" scope="row">Database Backup To:</th> 256 <td><? =$backup['path']?></td>294 <td><?php echo $backup['path']; ?></td> 257 295 </tr> 258 296 <tr style='background-color: #eee'> 259 297 <th align="left" scope="row">Database Backup Date:</th> 260 <td><? =date('jS F Y', $backup['date'])?></td>298 <td><?php echo date('jS F Y', $backup['date']); ?></td> 261 299 </tr> 262 300 <tr style='background-color: none'> 263 301 <th align="left" scope="row">Database Backup File Name:</th> 264 <td><? =$backup['filename']?> / <?=date('jS_F_Y', substr($backup['filename'], 0, 10)).'-'.substr($backup['filename'], 13);?></td>302 <td><?php echo $backup['filename']; ?></td> 265 303 </tr> 266 304 <tr style='background-color: #eee'> … … 270 308 <tr style='background-color: none'> 271 309 <th align="left" scope="row">MYSQL Dump Location</th> 272 <td><? =$backup['mysqldumppath']?></td>310 <td><?php echo $backup['mysqldumppath']; ?></td> 273 311 </tr> 274 312 <tr style='background-color: #eee'> … … 296 334 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 297 335 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 298 <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 336 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 337 <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 299 338 </ul> 339 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 300 340 <!-- Optimize Database --> 301 341 <div class="wrap"> 302 342 <h2>Optimize Database</h2> 303 <form action="<? =$_SERVER['PHP_SELF']?>" method="post">343 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=optimize" method="post"> 304 344 <table width="100%" cellspacing="3" cellpadding="3" border="0"> 305 345 <tr> … … 343 383 <li><a href="database-manager.php?mode=restore" class="current"><?php _e('Restore/Download DB'); ?></a></li> 344 384 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 345 <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 385 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 386 <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 346 387 </ul> 388 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 347 389 <!-- Restore/Download Database --> 348 390 <div class="wrap"> 349 391 <h2>Restore/Download Database</h2> 350 <form action="<? =$_SERVER['PHP_SELF']?>" method="post">392 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=restore" method="post"> 351 393 <table width="100%" cellspacing="3" cellpadding="3" border="0"> 352 394 <tr> … … 365 407 $database_files = array(); 366 408 while (false !== ($file = readdir($handle))) { 367 if ($file != '.' && $file != '..' ) {409 if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) { 368 410 $database_files[] = $file; 369 411 } … … 396 438 </tr> 397 439 <tr> 398 <th align="left" colspan="3"><? =$no?> Backup File(s)</th>399 <th align="left"><? =format_size($totalsize)?></th>440 <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th> 441 <th align="left"><?php echo format_size($totalsize); ?></th> 400 442 <td> </td> 401 443 </tr> … … 419 461 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 420 462 <li><a href="database-manager.php?mode=delete" class="current"><?php _e('Delete Backup DB'); ?></a></li> 421 <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 463 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 464 <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 422 465 </ul> 466 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 423 467 <!-- Delete Database Backup Files --> 424 468 <div class="wrap"> 425 469 <h2>Delete Database Backup Files</h2> 426 <form action="<? =$_SERVER['PHP_SELF']?>" method="post">470 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=delete" method="post"> 427 471 <table width="100%" cellspacing="3" cellpadding="3" border="0"> 428 472 <tr> … … 441 485 $database_files = array(); 442 486 while (false !== ($file = readdir($handle))) { 443 if ($file != '.' && $file != '..' ) {487 if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) { 444 488 $database_files[] = $file; 445 489 } … … 472 516 </tr> 473 517 <tr> 474 <th align="left" colspan="3"><? =$no?> Backup File(s)</th>475 <th align="left"><? =format_size($totalsize)?></th>518 <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th> 519 <th align="left"><?php echo format_size($totalsize); ?></th> 476 520 <td> </td> 477 521 </tr> … … 495 539 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 496 540 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 497 <li class="last"><a href="database-manager.php?mode=run" class="current"><?php _e('Run SQL Query'); ?></a></li> 541 <li><a href="database-manager.php?mode=run" class="current"><?php _e('Run SQL Query'); ?></a></li> 542 <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 498 543 </ul> 544 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 499 545 <!-- Run SQL Query --> 500 546 <div class="wrap"> 501 547 <h2>Run SQL Query</h2> 502 <form action="<? =$_SERVER['PHP_SELF']?>" method="post">503 <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE and CREATEstatements.</font></p>548 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=run" method="post"> 549 <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.</font></p> 504 550 <p align="center"><textarea cols="150" rows="30" name="sql_query"></textarea></p> 505 551 <p align="center"><input type="submit" name="do" Value="Run" class="button"> <input type="submit" name="cancel" Value="Cancel" class="button"></p> 506 <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.</font></p> 552 <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.<br />3. ALTER statement will return an error because there is no value returned.</font></p> 553 </form> 554 </div> 555 <?php 556 break; 557 // Empty/Drop Tables 558 case 'empty': 559 $title = __('Empty/Drop Tables'); 560 require("./admin-header.php"); 561 $tables = $wpdb->get_results("SHOW TABLES"); 562 ?> <!-- Drop/Empty Tables --> 563 <ul id="submenu"> 564 <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li> 565 <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li> 566 <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li> 567 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 568 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 569 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 570 <li class="last"><a href="database-manager.php?mode=empty" class="current"><?php _e('Empty/Drop Tables'); ?></a></li> 571 </ul> 572 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 573 <!-- Empty/Drop Tables --> 574 <div class="wrap"> 575 <h2>Empty/Drop Tables</h2> 576 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=empty" method="post"> 577 <table width="100%" cellspacing="3" cellpadding="3" border="0"> 578 <tr> 579 <th align="left" scope="col">Tables</th> 580 <th align="left" scope="col">Empty</th> 581 <th align="left" scope="col">Drop</th> 582 </tr> 583 <?php 584 foreach($tables as $dbtable) { 585 if($no%2 == 0) { 586 $style = 'style=\'background-color: #eee\''; 587 } else { 588 $style = 'style=\'background-color: none\''; 589 } 590 $no++; 591 $table_name = '$dbtable->Tables_in_'.DB_NAME; 592 eval("\$table_name = \"$table_name\";"); 593 echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n"; 594 echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"empty\"> Empty</td>"; 595 echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"drop\"> Drop</td></tr>"; 596 } 597 ?> 598 <tr> 599 <td colspan="3">1. DROPPING a table means deleting the table. This action is not REVERSIBLE.<br />2. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.</td> 600 </tr> 601 <tr> 602 <td colspan="3" align="center"><input type="submit" name="do" value="Empty/Drop" class="button" onclick="return confirm('You Are About To Empty Or Drop The Selected Databases.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')"> <input type="submit" name="cancel" Value="Cancel" class="button"></td> 603 </tr> 604 </table> 507 605 </form> 508 606 </div> … … 522 620 <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li> 523 621 <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 524 <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 622 <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 623 <li class="last"><a href="database-manager.php?mode=empty" class="current"><?php _e('Empty/Drop Tables'); ?></a></li> 525 624 </ul> 526 625 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> wp-dbmanager/trunk/readme-upgrade.txt
r4819 r4931 1 -> Upgrade Instructions For Version 2.0 0 To Version 2.011 -> Upgrade Instructions For Version 2.0x To Version 2.02 2 2 ------------------------------------------------------------------ 3 3 // Open wp-admin folder wp-dbmanager/trunk/readme.txt
r4876 r4931 13 13 // Version 2.02 (01-03-2006) 14 14 - NEW: Improved On 'manage_database' Capabilities 15 - NEW: Added GigaBytes To File Size 16 - NEW: Added ALTER Statement To Allowed Queries 17 - NEW: Able To Empty/Drop Tables 15 18 - FIXED: PHP Short Tags 19 - FIXED: Redirect Back To The Same Page Instead Of Manage Database Page After Submitting Form 16 20 17 21 // Version 2.01 (01-02-2006)
