| @@ -1,5 +1,5 @@ | ||
| 1 | -<?php // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 1 | +<?php | |
| 2 | 2 | /** |
| 3 | 3 | * Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 4 | 4 | * |
| 5 | 5 | * @package WPDataAccess\Connection |
| @@ -254,9 +254,28 @@ | ||
| 254 | 254 | return true; |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - /** | |
| 258 | + /** | |
| 259 | + * Disable remote database connection | |
| 260 | + * | |
| 261 | + * @param string $database Remote database connection name. | |
| 262 | + * @return bool | |
| 263 | + */ | |
| 264 | + public static function dis_remote_database( $database, $disabled ) { | |
| 265 | + self::load_remote_databases(); | |
| 266 | + | |
| 267 | + if ( false === self::get_remote_database( $database, true ) ) { | |
| 268 | + return false; | |
| 269 | + } else { | |
| 270 | + self::$remote_databases[ $database ]['disabled'] = $disabled; | |
| 271 | + self::save_remote_databases(); | |
| 272 | + | |
| 273 | + return true; | |
| 274 | + } | |
| 275 | + } | |
| 276 | + | |
| 277 | + /** | |
| 259 | 278 | * Update remote connection |
| 260 | 279 | * |
| 261 | 280 | * @param string $database Database name. |
| 262 | 281 | * @param string $host Host name. |
| @@ -346,9 +365,9 @@ | ||
| 346 | 365 | * @return mixed|\wpdb |
| 347 | 366 | */ |
| 348 | 367 | public static function get_db_connection( $schema_name ) { |
| 349 | 368 | global $wpdb; |
| 350 | - if ( 'rdb:' === substr( $schema_name, 0, 4 ) ) { | |
| 369 | + if ( 'rdb:' === substr( (string) $schema_name, 0, 4 ) ) { | |
| 351 | 370 | // Remote database (other ip|port). |
| 352 | 371 | self::load_remote_databases(); |
| 353 | 372 | if ( ! isset( self::$db_connections[ $schema_name ] ) ) { |
| 354 | 373 | if ( |
| @@ -417,9 +436,9 @@ | ||
| 417 | 436 | */ |
| 418 | 437 | public static function iswpdb( $schema_name ) { |
| 419 | 438 | global $wpdb; |
| 420 | 439 | if ( null === self::$lower_case_table_names ) { |
| 421 | - $lower_case_table_names = $wpdb->get_results( "SHOW VARIABLES LIKE 'lower_case_table_names'", 'ARRAY_N' ); // db call ok; no-cache ok. | |
| 440 | + $lower_case_table_names = $wpdb->get_results( "SHOW VARIABLES LIKE 'lower_case_table_names'", 'ARRAY_N' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 422 | 441 | if ( is_array( $lower_case_table_names ) && isset( $lower_case_table_names[0][1] ) ) { |
| 423 | 442 | self::$lower_case_table_names = $lower_case_table_names[0][1]; |
| 424 | 443 | } else { |
| 425 | 444 | self::$lower_case_table_names = 0; |