PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.2
4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 3.8.0 All 110 releases
wp-optimize / optimizations / optimizetables.php

optimizetables.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 2.2.2, at optimizations/optimizetables.php

108 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_VERSION')) die('No direct access allowed');
4
5 class WP_Optimization_optimizetables extends WP_Optimization {
6
7 protected $auto_id = 'optimize';
8
9 protected $setting_id = 'optimize';
10
11 protected $dom_id = 'optimize-db';
12
13 public $available_for_saving = true;
14
15 public $available_for_auto = true;
16
17 public $setting_default = true;
18
19 public $changes_table_data = true;
20
21 public $ui_sort_order = 500;
22
23 public $run_sort_order = 100000;
24
25 public $run_multisite = false;
26
27 /**
28 * Run optimization.
29 */
30 public function optimize() {
31 // check if force optimize sent.
32 $force = (isset($this->data['optimization_force']) && $this->data['optimization_force']) ? true : false;
33
34 // check if single table name posted or optimize all tables.
35 if (isset($this->data['optimization_table']) && '' != $this->data['optimization_table']) {
36 $table = $this->optimizer->get_table($this->data['optimization_table']);
37
38 $this->optimize_table($table, $force);
39 } else {
40 $tables = $this->optimizer->get_tables();
41
42 foreach ($tables as $table) {
43 $this->optimize_table($table, $force);
44 }
45 }
46 }
47
48 /**
49 * Optimize table and generate log and output information.
50 *
51 * @param object $table_obj table object returned by $this->optimizer->get_tables().
52 * @param bool $force if true then will optimize
53 */
54 private function optimize_table($table_obj, $force = false) {
55
56 // if not forced and table is not optimizable then exit.
57 if (false == $force && (false == $table_obj->is_optimizable || false == $table_obj->is_type_supported)) return;
58
59 if ($table_obj->is_type_supported) {
60 $this->logger->info('Optimizing: ' . $table_obj->Name);
61 $this->query('OPTIMIZE TABLE ' . $table_obj->Name);
62
63 $this->optimizer->update_total_cleaned(strval($table_obj->Data_free));
64
65 $this->register_output(__('Optimizing Table:', 'wp-optimize') . ' ' . $table_obj->Name);
66 }
67 }
68
69 /**
70 * Return info about optimization.
71 */
72 public function get_info() {
73 // This gathers information to be displayed onscreen before optimization.
74 $tablesstatus = $this->optimizer->get_table_information();
75
76 // Check if database is not optimizable.
77 if (false === $tablesstatus['is_optimizable']) {
78 if (isset($this->data['optimization_table']) && '' != $this->data['optimization_table']) {
79 // This is used for grabbing information before optimizations.
80 $this->register_output(__('Total gain:', 'wp-optimize').' '.WP_Optimize()->format_size(($tablesstatus['total_gain'])));
81 }
82
83 if ($tablesstatus['inno_db_tables'] > 0) {
84 // Output message for how many InnoDB tables will not be optimized.
85 $this->register_output(sprintf(__('Tables using the InnoDB engine (%d) will not be optimized.'), $tablesstatus['inno_db_tables']));
86
87 if ($tablesstatus['non_inno_db_tables'] > 0) {
88 $this->register_output(sprintf(__('Other tables will be optimized (%s).', 'wp-optimize'), $tablesstatus['non_inno_db_tables']));
89 }
90
91 $faq_url = apply_filters('wpo_faq_url', 'https://wordpress.org/plugins/wp-optimize/#faq');
92 $force_db_option = $this->options->get_option('innodb-force-optimize', 'false');
93 $this->register_output('<input id="innodb_force_optimize" name="innodb-force-optimize" type="checkbox" value="true" '.checked($force_db_option, 'true').'><label for="innodb_force_optimize">'.__('Optimize InnoDB tables anyway.', 'wp-optimize').'</label><br><a href="'.$faq_url.'" target="_blank">'.__('Warning: you should read the FAQ on the risks of this operation first.', 'wp-optimize').'</a>');
94 }
95 } else {
96 $this->register_output(sprintf(__('Tables will be optimized (%s).', 'wp-optimize'), $tablesstatus['non_inno_db_tables'] + $tablesstatus['inno_db_tables']));
97 }
98 }
99
100 public function get_auto_option_description() {
101 return __('Optimize database tables', 'wp-optimize');
102 }
103
104 public function settings_label() {
105 return __('Optimize database tables', 'wp-optimize');
106 }
107 }
108