1 Star 0 Fork 0

falcon / wp_alert_table_engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wp_alter_table_engine.php 4.94 KB
一键复制 编辑 原始数据 按行查看 历史
falcon 提交于 2015-12-28 16:24 . fix detail
<?php
/*
Plugin Name: WP_ALER_TABLE_ENGINE
Plugin URI: http://cellmean.com
Description: a tiny tool for Changing the mysql engines of wordpress tables in a click.
Version: 1.0
Author: Falcon
Author URI: http://cellmean.com
License: GPL v2
*/
class WATE
{
public function __construct()
{
add_action('admin_menu', array(&$this, 'admin_menu'), 10, 2);
}
public function admin_menu()
{
add_submenu_page('tools.php', __('WP ALTER TABLE ENGINE', 'wate'), __('WP ALTER TABLE ENGINE', 'wate'), 'manage_options', __('WP ALTER TABLE ENGINE', 'wate'), array(&$this, 'admin_settings'));
}
public function admin_settings()
{
global $wpdb;
$results = array();
if (isset($_POST['wate_submit']) && !empty($_POST['wate_submit'])) {
check_admin_referer('wate_settings');
$tables = $wpdb->get_results("show table status like '%'", ARRAY_A);
if (isset($_POST['engines']) && !empty($_POST['engines'])) {
$tables = $wpdb->get_results("show table status like '%'", ARRAY_A);
$toChangeEngines = array();
foreach ($tables as $table) {
$tableName = $table['Name'];
$tableEngine = $table['Engine'];
if (isset($_POST['engines'][$tableName]) && $_POST['engines'][$tableName] != $tableEngine) {
$toChangeEngines[$tableName] = $_POST['engines'][$tableName];
}
}
foreach ($toChangeEngines as $tableName => $engineName) {
$results[$tableName] = $wpdb->query(sprintf('ALTER TABLE %s engine=%s', $tableName, $engineName));
}
}
}
$tables = $wpdb->get_results("show table status like '%'", ARRAY_A);
$enginesAvailable = $wpdb->get_results("show engines", ARRAY_A);
$showCols = array('Name', 'Engine', 'Rows', 'Create_time', 'Update_time', 'Collation', 'Comment');
?>
<div class="wrap">
<form action="" method="post">
<h1><?php _e('WP ALTER TABLE ENGINE', 'wate'); ?></h1>
<?php if (!empty($results)): ?>
<h1 style="font-size:16px;margin: 0;padding: 0;"><?php _e('status', 'wate') ?>:</h1>
<ul style="margin:0;padding:0">
<?php foreach ($results as $table => $result) : ?>
<li><?php echo $table ?> : <?php echo ($result) ? _( 'Success','wate' ) : _( 'Failed','wate' ) ?></li>
<?php endforeach; ?>
</ul>
<?php endif ?>
<strong>
<?php _e('Before alert table engine,Please backup your database firstly !', 'wate'); ?>
</strong>
<table class="widefat striped">
<tbody>
<?php foreach ($tables as $key => $tableObj) : ?>
<?php if ($key == 0) : ?>
<tr>
<?php foreach ($showCols as $key) : ?>
<td class="row-title"><?php echo $key; ?></td>
<?php endforeach; ?>
</tr>
<?php endif ?>
<tr>
<?php foreach ($showCols as $key): ?>
<td class="desc">
<?php if ($key == 'Engine'): ?>
<select name="engines[<?php echo $tableObj['Name'] ?>]">
<?php foreach ($enginesAvailable as $engine): ?>
<option
<?php selected($engine['Engine'], $tableObj[$key]); ?>
value="<?php echo $engine['Engine']; ?>">
<?php echo $engine['Engine']; ?>
</option>
<?php endforeach; ?>
</select>
<?php else: ?>
<?php echo $tableObj[$key]; ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p class="submit">
<input type="submit" name="wate_submit" id="wate_submit" class="button-primary"
value="<?php _e('Submit', 'wate') ?>"/>
</p>
<?php wp_nonce_field("wate_settings"); ?>
</form>
</div>
<?php
}
}
if (is_admin()) {
new WATE();
}
PHP
1
https://gitee.com/falcon/wp_alert_table_engine.git
git@gitee.com:falcon/wp_alert_table_engine.git
falcon
wp_alert_table_engine
wp_alert_table_engine
master

搜索帮助