| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
if( ! current_user_can( 'administrator' ) ) exit; |
| 5 |
|
| 6 |
function wpforo_debug_page_ajax_actions() { ?> |
| 7 |
<script type="text/javascript"> |
| 8 |
jQuery(document).ready(function ($) { |
| 9 |
$('#wpf-debug-tables-solve-button').on('click', function () { |
| 10 |
$(this).prepend('<i class="fas fa-spinner fa-spin"></i>') |
| 11 |
$.ajax({ |
| 12 |
type: 'POST', |
| 13 |
url: ajaxurl, |
| 14 |
data: { |
| 15 |
action: 'wpforo_update_database', |
| 16 |
_wpnonce: '<?php echo wp_create_nonce( 'wpforo_update_database' ) ?>' |
| 17 |
} |
| 18 |
}).done(function () { |
| 19 |
window.location.reload() |
| 20 |
}) |
| 21 |
}) |
| 22 |
}) |
| 23 |
</script> |
| 24 |
<?php |
| 25 |
} |
| 26 |
|
| 27 |
add_action( 'admin_footer', 'wpforo_debug_page_ajax_actions' ); |
| 28 |
?> |
| 29 |
<div class="wpf-tool-box" style="width:98%; margin-left: 1%; border: none;"> |
| 30 |
<table style="width:100%;"> |
| 31 |
<tbody style="padding:10px;"> |
| 32 |
<?php $problems = wpforo_database_check(); ?> |
| 33 |
<?php if( $problems ): ?> |
| 34 |
<tr> |
| 35 |
<td><h3 style="color: #aa0000; margin: 0; border-bottom: none; padding: 15px 0 0 0"><span class="dashicons dashicons-warning" style="vertical-align: sub;"></span> <?php _e( 'Problems Found in Database', 'wpforo' ) ?></h3></td> |
| 36 |
</tr> |
| 37 |
<tr style="background-color: transparent;"> |
| 38 |
<td style="padding-bottom: 50px;"> |
| 39 |
<div style="font-size: 14px;"> |
| 40 |
<div style="font-weight: 600; display: flex; flex-direction: row; justify-content: space-between; padding: 5px 10px; border-bottom: 1px solid #cc0000; margin-bottom: 5px; color: #333333; background-color: #f9f9f9;"> |
| 41 |
<div style="width: 30%"><?php _e( 'Table name', 'wpforo' ); ?></div> |
| 42 |
<div style="text-align: left; flex-grow: 1;"><?php _e( 'Problem description', 'wpforo' ); ?></div> |
| 43 |
</div> |
| 44 |
<?php foreach( $problems as $table_name => $problem ): ?> |
| 45 |
<?php if( wpfval( $problem, 'fields' ) ): ?> |
| 46 |
<?php foreach( $problem['fields'] as $problem_fields ): ?> |
| 47 |
<div style="display: flex; flex-direction: row; justify-content: space-between; padding: 5px 10px; background-color: #ffeffa; color: #aa0000; margin-bottom: 3px;"> |
| 48 |
<div style="width: 30%; font-weight: 600;"><?php _e( 'Table:', 'wpforo' ); ?><?php echo $table_name; ?></div> |
| 49 |
<div style="text-align: left; flex-grow: 1;"><?php _e( 'Missing fields: ', 'wpforo' ); ?> <code><?php echo implode( ', ', $problem_fields ); ?></code></div> |
| 50 |
</div> |
| 51 |
<?php endforeach; ?> |
| 52 |
<?php endif; ?> |
| 53 |
<?php if( wpfval( $problem, 'keys' ) ): ?> |
| 54 |
<?php foreach( $problem['keys'] as $problem_keys ): ?> |
| 55 |
<div style="display: flex; flex-direction: row; justify-content: space-between; padding: 5px 10px; background-color: #ffeffa; color: #aa0000; margin-bottom: 3px;"> |
| 56 |
<div style="width: 30%; font-weight: 600;"><?php _e( 'Table:', 'wpforo' ); ?><?php echo $table_name; ?></div> |
| 57 |
<div style="text-align: left; flex-grow: 1;"><?php _e( 'Missing keys: ', 'wpforo' ); ?> <code><?php echo implode( ', ', $problem_keys ); ?></code></div> |
| 58 |
</div> |
| 59 |
<?php endforeach; ?> |
| 60 |
<?php endif; ?> |
| 61 |
<?php if( wpfkey( $problem, 'exists' ) ): ?> |
| 62 |
<?php if( $problem['exists'] ): ?> |
| 63 |
<div style="display: flex; flex-direction: row; justify-content: space-between; padding: 5px 10px; background-color: #ffeffa;; color: #aa0000; margin-bottom: 3px;"> |
| 64 |
<div style="width: 30%; font-weight: 600;"><?php _e( 'Table:', 'wpforo' ); ?><?php echo $table_name; ?></div> |
| 65 |
<div style="text-align: left; flex-grow: 1;"><?php _e( 'Doesn\'t exists', 'wpforo' ); ?></div> |
| 66 |
</div> |
| 67 |
<?php endif; ?> |
| 68 |
<?php endif; ?> |
| 69 |
<?php endforeach; ?> |
| 70 |
<div style="display:flex; flex-direction: row; justify-content: space-between; border-top: 1px dashed #cccccc; padding-top: 10px; text-align: right; margin-top: 10px; font-weight: normal; font-size: 13px;"> |
| 71 |
<?php $update_db_url = wp_nonce_url( admin_url( 'admin.php?page=' . wpforo_prefix_slug( 'tools' ) . '&tab=tables&wpfaction=database_update' ), 'wpforo_update_database' ); ?> |
| 72 |
<div> |
| 73 |
<a href="<?php echo esc_url( (string) $update_db_url ); ?>" class="button button-large" style="font-size:12px;"> |
| 74 |
<?php _e( 'Recheck DB', 'wpforo' ); ?> |
| 75 |
</a> |
| 76 |
</div> |
| 77 |
<div style="padding: 0 30px;"> |
| 78 |
<span id="wpf-debug-tables-solve-button" class="button button-primary button-large" style="font-size:14px;"> |
| 79 |
<?php _e( 'Solve database problems', 'wpforo' ); ?> |
| 80 |
</span> |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
<div style=" margin-top: 0px; font-weight: normal; font-size: 13px;"> |
| 84 |
<p style="font-weight: 600; font-size: 16px; margin-bottom: 2px;"><?php _e( 'IMPORTANT!', 'wpforo' ) ?></p> |
| 85 |
<p style="font-size: 14px; line-height: 1.5; margin-top: 2px;"><?php printf( |
| 86 |
__( 'If the %s button doesn\'t solve the issues. Please use the SQl commands below in your hosting service cPanel > phpMyAdmin Database Manager > WordPress Database > SQL Tab. In case you\'re not familiar with hosting service tools, please contact to your hosting service support team and forward them this message with the SQL command.', 'wpforo' ), |
| 87 |
'<b style="color: #0085ba; font-size:13px;font-family: Courier">[' . __( 'Solve database problems', 'wpforo' ) . ']</b>' |
| 88 |
) ?></p> |
| 89 |
<p style="font-size: 14px; font-weight: 600;"><?php _e( 'Problem fixer SQL commands:', 'wpforo' ) ?></p> |
| 90 |
<pre style=" width: 100%; max-width: 1200px; display: block; padding: 10px; line-height: 1.4; border: 1px dashed #dd0000; background-color: #fffdea; color: #000000; overflow-x:auto;"><?php |
| 91 |
if( ! empty( $problems ) ) { |
| 92 |
echo 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";<br />SET AUTOCOMMIT = 0;<br />'; |
| 93 |
$SQL = wpforo_database_fixer( $problems ); |
| 94 |
if( wpfval( $SQL, 'fields' ) ) { |
| 95 |
foreach( $SQL['fields'] as $query ) echo $query . '<br>'; |
| 96 |
} |
| 97 |
if( wpfval( $SQL, 'keys' ) ) { |
| 98 |
foreach( $SQL['keys'] as $query ) echo $query . '<br>'; |
| 99 |
} |
| 100 |
if( wpfval( $SQL, 'tables' ) ) { |
| 101 |
foreach( $SQL['tables'] as $query ) echo $query . '<br><br>'; |
| 102 |
} |
| 103 |
if( wpfval( $SQL, 'data' ) ) { |
| 104 |
foreach( $SQL['data'] as $query ) echo $query . '<br><br>'; |
| 105 |
} |
| 106 |
echo ';SET AUTOCOMMIT = 1;'; |
| 107 |
} |
| 108 |
?></pre> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
</td> |
| 112 |
</tr> |
| 113 |
<?php else: ?> |
| 114 |
<tr> |
| 115 |
<td><h3 style="color: #00aa00; margin: 0; border-bottom: none; padding: 15px 0 30px 0"><span class="dashicons dashicons-shield" style="vertical-align: sub;"></span> <?php _e( 'No Problems Found in Database', 'wpforo' ) ?></h3></td> |
| 116 |
</tr> |
| 117 |
<?php endif; ?> |
| 118 |
<tr style="background-color: transparent;"> |
| 119 |
<td> |
| 120 |
<div style="display: flex; align-items: center; justify-content: space-between;"> |
| 121 |
<h3 style=" border-bottom: none;"><?php _e( 'Database Tables', 'wpforo' ) ?></h3> |
| 122 |
<?php |
| 123 |
$boardid = WPF()->board->get_current( 'boardid' ); |
| 124 |
printf( |
| 125 |
'<a href="%1$s"><button type="button" style="background-color: #ec6262; color: white; padding: 5px 20px">%2$s</button></a>', |
| 126 |
wp_nonce_url( |
| 127 |
admin_url( |
| 128 |
sprintf( |
| 129 |
'admin.php?page=%1$s&wpfaction=%2$s&boardid=%3$s', |
| 130 |
'wpforo-boards', |
| 131 |
'board_repair', |
| 132 |
$boardid |
| 133 |
) |
| 134 |
), |
| 135 |
'wpforo-board-repair-' . $boardid |
| 136 |
), |
| 137 |
__( 'Repair', 'wpforo' ) |
| 138 |
); ?> |
| 139 |
</div> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<tr> |
| 143 |
<td><?php foreach( WPF()->tables as $table ) { |
| 144 |
wpforo_table_info( $table ); |
| 145 |
} ?></td> |
| 146 |
</tr> |
| 147 |
</tbody> |
| 148 |
</table> |
| 149 |
</div> |
| 150 |
|
| 151 |
|
| 152 |
<?php |
| 153 |
function wpforo_table_info( $table ) { |
| 154 |
$_table_exists = WPF()->db->get_var( "SHOW TABLES LIKE '" . esc_sql( $table ) . "'" ); |
| 155 |
if( $_table_exists ) { |
| 156 |
$result = WPF()->db->get_results( "SHOW FULL COLUMNS FROM " . esc_sql( $table ), ARRAY_A ); |
| 157 |
$count = WPF()->db->get_var( "SELECT COUNT(*) FROM " . esc_sql( $table ) ); |
| 158 |
$status = WPF()->db->get_row( "CHECK TABLE " . esc_sql( $table ), ARRAY_A ); |
| 159 |
echo '<table class="wpf-main-table-data"><tr><td>'; |
| 160 |
echo '<table class="wpf-table-data wpf-tbl">'; |
| 161 |
echo '<tr><td colspan="6" style="background:#999999; color: #ffffff;font-size:14px; line-height:26px"><b>' . $table . '</b> | Rows: ' . $count . ' | Status: ' . $status['Msg_text'] . '</td></tr>'; |
| 162 |
foreach( $result as $info ) { |
| 163 |
echo '<tr>'; |
| 164 |
echo '<td>' . $info['Field'] . '</td>'; |
| 165 |
echo '<td>' . $info['Type'] . '</td>'; |
| 166 |
echo '<td>' . $info['Collation'] . '</td>'; |
| 167 |
echo '<td>' . ( $info['Null'] == 'NO' ? '-' : 'NULL' ) . '</td>'; |
| 168 |
echo '<td>' . $info['Key'] . '</td>'; |
| 169 |
echo '<td>' . $info['Default'] . '</td>'; |
| 170 |
echo '</tr>'; |
| 171 |
} |
| 172 |
echo '</table>'; |
| 173 |
echo '</td>'; |
| 174 |
echo '<td>'; |
| 175 |
$result = WPF()->db->get_results( "SHOW INDEXES FROM " . esc_sql( $table ), ARRAY_A ); |
| 176 |
|
| 177 |
echo '<table class="wpf-table-data">'; |
| 178 |
echo '<tr><td colspan="6" style="background:#BBBBBB; color: #ffffff;font-size:14px; line-height:26px"><b>Indexes</b></td></tr>'; |
| 179 |
$indexes = []; |
| 180 |
foreach( $result as $info ) { |
| 181 |
$indexes[ $info['Key_name'] ]['Key_name'] = $info['Key_name']; |
| 182 |
$indexes[ $info['Key_name'] ]['Column_name'][] = $info['Column_name']; |
| 183 |
$indexes[ $info['Key_name'] ]['Non_unique'] = $info['Non_unique']; |
| 184 |
$indexes[ $info['Key_name'] ]['Index_type'] = $info['Index_type']; |
| 185 |
} |
| 186 |
foreach( $indexes as $info ) { |
| 187 |
echo '<tr>'; |
| 188 |
echo '<td>' . $info['Key_name'] . '</td>'; |
| 189 |
echo '<td>' . implode( ', ', $info['Column_name'] ) . '</td>'; |
| 190 |
echo '<td>' . ( $info['Non_unique'] ? '0' : 'Un' ) . '</td>'; |
| 191 |
echo '<td>' . $info['Index_type'] . '</td>'; |
| 192 |
echo '</tr>'; |
| 193 |
} |
| 194 |
echo '</table>'; |
| 195 |
|
| 196 |
echo '</td>'; |
| 197 |
echo '</tr>'; |
| 198 |
echo '</table>'; |
| 199 |
} else { |
| 200 |
echo '<h3>Table <span style="color: red;">' . $table . '</span> doesn\'t exist</h3>'; |
| 201 |
} |
| 202 |
} |
| 203 |
|