Changeset 1171849
- Timestamp:
- 06/01/2015 12:09:51 PM (11 years ago)
- Location:
- angry-creative-logger/trunk
- Files:
-
- 1 added
- 1 deleted
- 6 edited
-
ac_debug.log (deleted)
-
classes/inspector.php (modified) (6 diffs)
-
classes/routine_handler.php (modified) (5 diffs)
-
classes/wp_cli.php (added)
-
plugin.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
routines/db_collations.php (modified) (2 diffs)
-
routines/site_visibility.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
angry-creative-logger/trunk/classes/inspector.php
r1125402 r1171849 2 2 /* 3 3 Class name: AC Inspector 4 Version: 0. 5.14 Version: 0.6 5 5 Author: Sammy Nordström, Angry Creative AB 6 6 */ … … 15 15 public static $errors = array(); 16 16 public static $log_count = 0; 17 public static $success_count = 0; 18 public static $error_count = 0; 17 19 18 20 private static $_default_log_path = ""; … … 245 247 } 246 248 249 public function increment_success_count() { 250 251 self::$success_count++; 252 253 } 254 255 public function increment_error_count() { 256 257 self::$error_count++; 258 259 } 260 261 public function get_success_count() { 262 263 return self::$success_count; 264 265 } 266 267 public function get_error_count() { 268 269 return self::$error_count; 270 271 } 272 247 273 /* 248 274 Main log function that does the actual output 249 275 */ 250 public static function log($message, $routine = '', $site_id = '') { 251 252 $log_level = ''; 276 public static function log($message, $routine = '', $args = array() ) { 277 278 if ( !is_array( $args ) && is_numeric( $args ) ) { 279 // For backwards compatibility... 280 $args = array( 'site_id' => $args ); 281 } 282 283 $default_args = array( 284 'site_id' => get_current_blog_id(), 285 'site_specific_settings' => false, 286 'log_level' => 'notice', 287 'success' => false, 288 'error' => false 289 ); 253 290 254 291 if (!empty($routine)) { … … 256 293 $routine_options = ACI_Routine_Handler::get_options($routine); 257 294 258 if (is_array($routine_options)) { 259 if ( $routine_options['site_specific_settings'] && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) { 295 $routine_args = wp_parse_args( $routine_options, $default_args ); 296 $args = wp_parse_args( $args, $routine_args ); 297 298 if ( is_array( $args ) ) { 299 if ( $args['site_specific_settings'] && is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) { 260 300 $site_id = ( is_numeric($site_id) ) ? $site_id : get_current_blog_id(); 261 if ( is_array($ routine_options[$site_id]) && isset($routine_options[$site_id]['log_level']) ) {262 $log_level = $ routine_options[$site_id]['log_level'];263 } else if ( is_array($ routine_options[1]) && isset($routine_options[1]['log_level']) ) {264 $log_level = $ routine_options[1]['log_level'];301 if ( is_array($args[$site_id]) && isset($args[$site_id]['log_level']) ) { 302 $log_level = $args[$site_id]['log_level']; 303 } else if ( is_array($args[1]) && isset($args[1]['log_level']) ) { 304 $log_level = $args[1]['log_level']; 265 305 } 266 306 } 267 if ( empty($log_level) && isset($ routine_options['log_level']) ) {268 $log_level = $ routine_options['log_level'];307 if ( empty($log_level) && isset($args['log_level']) ) { 308 $log_level = $args['log_level']; 269 309 } 270 310 } 311 312 } else { 313 314 $args = wp_parse_args( $args, $default_args ); 271 315 272 316 } … … 286 330 error_log( print_r( $message, true ) . "\n", 3, self::$log_path ); 287 331 332 if ( defined('WP_CLI') && WP_CLI ) { 333 echo $output . "\n"; 334 print_r( $message ); 335 echo "\n"; 336 } 337 288 338 } else { 289 339 … … 291 341 error_log( $message . "\n", 3, self::$log_path ); 292 342 343 if ( defined('WP_CLI') && WP_CLI ) { 344 echo $message . "\n"; 345 } 346 293 347 } 294 348 295 349 self::$log_count++; 296 350 351 if ( $args['error'] ) { 352 self::$error_count++; 353 } 354 355 if ( $args['success'] ) { 356 self::$success_count++; 357 } 358 297 359 } 298 360 -
angry-creative-logger/trunk/classes/routine_handler.php
r958566 r1171849 2 2 /* 3 3 Class name: ACI Routine Handler 4 Version: 0.3. 14 Version: 0.3.2 5 5 Depends: AC Inspector 0.5.x 6 6 Author: Sammy Nordström, Angry Creative AB … … 11 11 class ACI_Routine_Handler { 12 12 13 private static $force_enabled = array(); 13 14 private static $routine_events = array(); 14 15 … … 74 75 } 75 76 77 public static function get_repair_method( $routine, $options = array() ) { 78 79 if ( empty( $routine ) ) { 80 return false; 81 } 82 83 if ( !is_array( $options ) || empty( $options ) ) { 84 85 $options = self::get_options( $routine ); 86 87 if ( !is_array( $options ) ) { 88 $options = array(); 89 } 90 91 } 92 93 if ( class_exists( $routine ) ) { 94 95 if ( !empty( $options['repair_method'] ) && method_exists( $routine, $options['repair_method'] ) ) { 96 97 return array( $routine, $options['repair_method'] ); 98 99 } else if ( method_exists( $routine, 'repair' ) ) { 100 101 return array( $routine, 'repair' ); 102 103 } 104 105 } 106 107 if ( !empty( $options['repair_method'] ) && function_exists( $options['repair_method'] ) ) { 108 109 return $options['repair_method']; 110 111 } 112 113 return false; 114 115 } 116 76 117 public static function set_options($routine, $args = array()) { 77 118 … … 118 159 119 160 } 161 162 if ( in_array( $routine, self::$force_enabled ) && $options[$site_blog_id]['log_level'] == 'ignore' ) { 163 $options[$site_blog_id]['log_level'] = 'notice'; 164 } 165 120 166 } 121 167 122 168 } 123 169 170 } else { 171 172 if ( in_array( $routine, self::$force_enabled ) && $options['log_level'] == 'ignore' ) { 173 $options['log_level'] = 'notice'; 174 } 175 124 176 } 125 177 … … 135 187 136 188 $options_key = self::routine_options_key($routine); 189 190 } 191 192 public static function force_enable( $routine = "" ) { 193 194 if ( !empty( $routine ) ) { 195 self::$force_enabled = array_merge( self::$force_enabled, array( $routine ) ); 196 } 137 197 138 198 } -
angry-creative-logger/trunk/plugin.php
r1129379 r1171849 4 4 Plugin URI: http://angrycreative.se 5 5 Description: Inspects and logs possible issues with your Wordpress installation. 6 Version: 0. 6.16 Version: 0.7 7 7 Author: Robin Björklund, Sammy Nordström, Angry Creative AB 8 8 */ 9 9 10 define( 'ACI_PLUGIN_VERSION', '0. 6.1' );10 define( 'ACI_PLUGIN_VERSION', '0.7' ); 11 11 12 12 define( 'ACI_PLUGIN_DIR', dirname( __FILE__ ) ); … … 46 46 } else { 47 47 $ac_inspector = new AC_Inspector(); 48 if ( defined('WP_CLI') && WP_CLI ) { 49 require_once( dirname( __FILE__ ) . '/classes/wp_cli.php' ); 50 } 48 51 } 49 52 -
angry-creative-logger/trunk/readme.txt
r1129379 r1171849 1 1 === Angry Creative Inspector === 2 Contributors: ac-robin, samface, angrycreative 2 Contributors: ac-robin, samface, angrycreative 3 3 Tags: inspect, inspection, monitor, monitoring, log, logging, check, checking, validate, validation, permissions, install, installation 4 4 Requires at least: 4.0 5 Tested up to: 4. 1.16 Stable tag: 0. 6.15 Tested up to: 4.2.2 6 Stable tag: 0.7 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 22 22 == Changelog == 23 24 = 0.7.x = 25 * Added repair method support for inspection routines 26 * Added WP CLI support for operating the inspector via command line 27 * Added inspect command for doing inspections via command line 28 * Added repair command for doing repairs via command line 29 * Added repair method to mysql database collations routine 23 30 24 31 = 0.6.x = -
angry-creative-logger/trunk/routines/db_collations.php
r1125423 r1171849 28 28 global $wpdb; 29 29 30 $blog_charset = strtolower( str_replace( '-', '', get_option('blog_charset') ) ); 31 $locale = get_locale(); 32 33 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 34 $translations = wp_get_available_translations(); 35 36 $language = 'general'; 37 38 if ( 'en_US' != $language && isset( $translations[$locale] ) ) { 39 $language = strtolower( $translations[$locale]['english_name'] ); 40 } 41 42 $proper_tbl_collation = $blog_charset . '_' . $language . '_ci'; 43 44 $default_tbl_collation = $wpdb->get_var( "SELECT DEFAULT_COLLATION_NAME 45 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".DB_NAME."'" ); 46 47 if ( $proper_tbl_collation != $default_tbl_collation ) { 48 AC_Inspector::log( "Default table collation is $default_tbl_collation (should be $proper_tbl_collation).", __CLASS__ ); 30 $proper_db_collation = self::get_proper_db_collation(); 31 32 $default_db_collation = $wpdb->get_var( "SELECT DEFAULT_COLLATION_NAME 33 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".DB_NAME."'" ); 34 35 if ( $proper_db_collation != $default_db_collation ) { 36 AC_Inspector::log( "Default table collation is $default_db_collation (should be $proper_db_collation).", __CLASS__ ); 49 37 } 38 39 list( $proper_charset ) = explode( '_', $proper_db_collation ); 40 41 $tbl_collation_queries = self::get_table_collation_queries(); 42 43 if ( is_array( $tbl_collation_queries ) && count( $tbl_collation_queries ) > 0 ) { 44 45 foreach( $tbl_collation_queries as $tbl_collation_query ) { 46 47 $tbl_collation_data = $wpdb->get_row( $tbl_collation_query ); 48 $tbl_name = $tbl_collation_data->TABLE_NAME; 49 $tbl_collation = $tbl_collation_data->TABLE_COLLATION; 50 51 if ( $proper_db_collation != $tbl_collation ) { 52 AC_Inspector::log( "Table collation for $tbl_name is $tbl_collation (should be $proper_db_collation).", __CLASS__ ); 53 } 54 55 $tbl_columns = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$tbl_name`" ); 56 if ( ! $tbl_columns ) { 57 AC_Inspector::log( "Unable to determine column collations for table $tbl_name.", __CLASS__ ); 58 continue; 59 } 60 61 foreach ( $tbl_columns as $column ) { 62 if ( $column->Collation ) { 63 if ( $proper_db_collation !== $column->Collation ) { 64 AC_Inspector::log( "Column collation for {$column->Field} in $tbl_name is {$column->Collation} (should be $proper_db_collation).", __CLASS__ ); 65 } 66 } 67 } 68 69 } 70 71 } 72 73 return; 74 75 } 76 77 public static function repair() { 78 79 global $wpdb; 80 81 $proper_db_collation = self::get_proper_db_collation(); 82 83 $default_db_collation = $wpdb->get_var( "SELECT DEFAULT_COLLATION_NAME 84 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".DB_NAME."'" ); 85 86 list( $proper_charset ) = explode( '_', $proper_db_collation ); 87 88 if ( $proper_db_collation != $default_db_collation ) { 89 if ( $wpdb->query( $wpdb->prepare( "ALTER DATABASE ".DB_NAME." CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation ) ) ) { 90 AC_Inspector::log( "Converted default table collation from $default_db_collation to $proper_db_collation.", __CLASS__, array( 'success' => true ) ); 91 } else { 92 AC_Inspector::log( "Failed to convert default table collation from $default_db_collation to $proper_db_collation!", __CLASS__ , array( 'error' => true )); 93 } 94 } 95 96 $tbl_collation_queries = self::get_table_collation_queries(); 97 98 if ( is_array( $tbl_collation_queries ) && count( $tbl_collation_queries ) > 0 ) { 99 100 foreach( $tbl_collation_queries as $tbl_collation_query ) { 101 102 $tbl_collation_data = $wpdb->get_row( $tbl_collation_query ); 103 $tbl_name = $tbl_collation_data->TABLE_NAME; 104 $tbl_collation = $tbl_collation_data->TABLE_COLLATION; 105 106 if ( $proper_db_collation != $tbl_collation ) { 107 if ( $wpdb->query( $wpdb->prepare( "ALTER TABLE ".$tbl_name." CONVERT TO CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation ) ) ) { 108 AC_Inspector::log( "Converted collation for $tbl_name from $tbl_collation to $proper_db_collation.", __CLASS__, array( 'success' => true ) ); 109 } else { 110 AC_Inspector::log( "Failed to convert collation for $tbl_name from $tbl_collation to $proper_db_collation.", __CLASS__, array( 'error' => true ) ); 111 } 112 continue; 113 } 114 115 $tbl_columns = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$tbl_name`" ); 116 if ( ! $tbl_columns ) { 117 AC_Inspector::log( "Unable to determine column collations for table $tbl_name.", __CLASS__, array( 'error' => true ) ); 118 continue; 119 } 120 121 foreach ( $tbl_columns as $column ) { 122 if ( $column->Collation ) { 123 if ( $proper_db_collation !== $column->Collation ) { 124 if ( $wpdb->query( $wpdb->prepare( "ALTER TABLE ".$tbl_name." CONVERT TO CHARACTER SET %s COLLATE %s", $proper_charset, $proper_db_collation ) ) ) { 125 AC_Inspector::log( "Converted collation for $tbl_name from $tbl_collation to $proper_db_collation.", __CLASS__, array( 'success' => true ) ); 126 } else { 127 AC_Inspector::log( "Failed to convert collation for $tbl_name from $tbl_collation to $proper_db_collation.", __CLASS__, array( 'error' => true ) ); 128 } 129 break; 130 } 131 } 132 } 133 134 } 135 136 } 137 138 return; 139 140 } 141 142 private static function get_proper_db_collation() { 143 144 global $wp_version; 145 146 if ( $wp_version >= 4.2 ) { 147 148 $blog_charset = 'utf8mb4'; 149 $language = 'unicode'; 150 151 } else { 152 153 $blog_charset = strtolower( str_replace( '-', '', get_option('blog_charset') ) ); 154 155 $language = 'general'; 156 157 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 158 $translations = wp_get_available_translations(); 159 $locale = get_locale(); 160 161 if ( 'en_US' != $locale && isset( $translations[$locale] ) ) { 162 $language = strtolower( $translations[$locale]['english_name'] ); 163 } 164 165 } 166 167 return $blog_charset . '_' . $language . '_ci'; 168 169 } 170 171 private static function get_table_collation_queries() { 172 173 global $wpdb; 50 174 51 175 $tbl_collation_queries_query = "SELECT CONCAT('SELECT TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = \'', table_name, '\';') AS sql_statements … … 55 179 ORDER BY table_name DESC"; 56 180 57 $tbl_collation_queries = $wpdb->get_col( $tbl_collation_queries_query ); 58 59 if ( is_array( $tbl_collation_queries ) && count( $tbl_collation_queries ) > 0 ) { 60 61 foreach( $tbl_collation_queries as $tbl_collation_query ) { 62 63 $tbl_collation_data = $wpdb->get_row( $tbl_collation_query ); 64 $tbl_name = $tbl_collation_data->TABLE_NAME; 65 $tbl_collation = $tbl_collation_data->TABLE_COLLATION; 66 67 if ( $proper_tbl_collation != $tbl_collation ) { 68 AC_Inspector::log( "Table collation for $tbl_name is $tbl_collation (should be $proper_tbl_collation).", __CLASS__ ); 69 } 70 71 } 72 73 } 74 75 return; 181 return $wpdb->get_col( $tbl_collation_queries_query ); 76 182 77 183 } -
angry-creative-logger/trunk/routines/site_visibility.php
r943414 r1171849 37 37 if ( !$visible ) { 38 38 39 AC_Inspector::log( 'Site '.$site_blog_id.' is not visible to search engines.', __CLASS__, $site_blog_id);39 AC_Inspector::log( 'Site '.$site_blog_id.' is not visible to search engines.', __CLASS__, array( 'site_id' => $site_blog_id ) ); 40 40 41 41 }
Note: See TracChangeset
for help on using the changeset viewer.