| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | namespace LassoLite\Models; |
| 9 | 9 | |
| 10 | 10 | use LassoLite\Classes\Cache_Per_Process; |
| 11 | 11 | use LassoLite\Classes\Helper as Lasso_Helper; |
| 12 | -use LassoLite\Classes\Setting_Enum as Lasso_Setting_Enum; | |
| 13 | 12 | use LassoLite\Classes\Update_DB; |
| 14 | 13 | |
| 15 | 14 | /** |
| 16 | 15 | * Model |
| @@ -508,17 +507,8 @@ | ||
| 508 | 507 | return self::query( $sql ); |
| 509 | 508 | } |
| 510 | 509 | |
| 511 | 510 | /** |
| 512 | - * Format keyword for searching | |
| 513 | - * | |
| 514 | - * @param string $keyword Keyword. | |
| 515 | - */ | |
| 516 | - public static function esc_like( $keyword ) { | |
| 517 | - return self::get_wpdb()->esc_like( $keyword ); | |
| 518 | - } | |
| 519 | - | |
| 520 | - /** | |
| 521 | 511 | * Get property name by method |
| 522 | 512 | * |
| 523 | 513 | * @param string $method Method. |
| 524 | 514 | */ |
| @@ -582,15 +572,12 @@ | ||
| 582 | 572 | * @return mixed Property value. |
| 583 | 573 | */ |
| 584 | 574 | public function __get( $name ) { |
| 585 | 575 | $method = strtolower( $name ); |
| 586 | - $property = $method; | |
| 576 | + $property = $this->get_property_name( $method ); | |
| 587 | 577 | |
| 588 | - if ( 0 === strpos( $method, 'get_' ) || 0 === strpos( $method, 'set_' ) ) { | |
| 589 | - $derived = $this->get_property_name( $method ); | |
| 590 | - if ( $derived ) { | |
| 591 | - $property = $derived; | |
| 592 | - } | |
| 578 | + if ( ! $property ) { | |
| 579 | + $property = $method; | |
| 593 | 580 | } |
| 594 | 581 | |
| 595 | 582 | if ( ! in_array( $property, $this->columns, true ) ) { |
| 596 | 583 | return; |
| @@ -899,9 +886,9 @@ | ||
| 899 | 886 | Update_DB::create_tables(); |
| 900 | 887 | } |
| 901 | 888 | |
| 902 | 889 | // ? Add force write log for lasso_debug, to see what happen when Lasso call query. |
| 903 | - trigger_error( '[lasso-lite-sql] ' . $error, E_USER_NOTICE ); // phpcs:ignore | |
| 890 | + trigger_error( $error, E_USER_NOTICE ); // phpcs:ignore | |
| 904 | 891 | } |
| 905 | 892 | } |
| 906 | 893 | |
| 907 | 894 | /** |
| @@ -909,30 +896,23 @@ | ||
| 909 | 896 | * |
| 910 | 897 | * @return bool |
| 911 | 898 | */ |
| 912 | 899 | private static function should_recreate_tables() { |
| 913 | - $lasso_recreate_table_time = Lasso_Helper::get_option( Lasso_Setting_Enum::RECREATE_TABLE_TIME, 0 ); | |
| 914 | - $lasso_recreate_table_time = intval( $lasso_recreate_table_time ); | |
| 900 | + // ? Define global $$lasso_recreate_table_time if not existed. | |
| 901 | + if ( ! array_key_exists( 'lasso_recreate_table_time', $GLOBALS ) ) { | |
| 902 | + global $lasso_recreate_table_time; | |
| 903 | + $lasso_recreate_table_time = 0; | |
| 904 | + } else { | |
| 905 | + global $lasso_recreate_table_time; | |
| 906 | + } | |
| 915 | 907 | |
| 916 | - // ? Increase number of times we call Update_DB::create_tables(). | |
| 908 | + // ? Increase number of times we call Lasso_Activator::create_lasso_table(). | |
| 917 | 909 | ++$lasso_recreate_table_time; |
| 910 | + | |
| 918 | 911 | if ( $lasso_recreate_table_time > self::LASSO_RECREATE_TABLES_LIMIT_TIMES ) { |
| 919 | - $now = time(); | |
| 920 | - $next_run = Lasso_Helper::get_option( Lasso_Setting_Enum::NEXT_TIME_RECREATE_TABLE, 0 ); | |
| 921 | - $next_run = intval( $next_run ); | |
| 922 | - if ( 0 === $next_run ) { | |
| 923 | - Lasso_Helper::update_option( Lasso_Setting_Enum::NEXT_TIME_RECREATE_TABLE, strtotime( '+1 hour' ) ); | |
| 924 | - } | |
| 925 | - | |
| 926 | - if ( $next_run && $now > $next_run ) { | |
| 927 | - Lasso_Helper::update_option( Lasso_Setting_Enum::RECREATE_TABLE_TIME, 1 ); | |
| 928 | - Lasso_Helper::update_option( Lasso_Setting_Enum::NEXT_TIME_RECREATE_TABLE, 0 ); | |
| 929 | - return true; | |
| 930 | - } | |
| 931 | - | |
| 932 | 912 | return false; |
| 933 | 913 | } |
| 934 | - Lasso_Helper::update_option( Lasso_Setting_Enum::RECREATE_TABLE_TIME, $lasso_recreate_table_time ); | |
| 914 | + | |
| 935 | 915 | return true; |
| 936 | 916 | } |
| 937 | 917 | |
| 938 | 918 | /** |
| @@ -960,9 +940,9 @@ | ||
| 960 | 940 | $reference_charset_table = $reference_charset_table ? $reference_charset_table : self::get_wp_table_name( 'posts' ); |
| 961 | 941 | $reference_charset_status = $this->get_table_charset( $reference_charset_table, true ); |
| 962 | 942 | $current_table_status = $this->get_table_charset( $table, false ); |
| 963 | 943 | |
| 964 | - if ( $reference_charset_status[1] !== $current_table_status[1] ) { | |
| 944 | + if ( ! $reference_charset_status[1] !== $current_table_status[1] ) { | |
| 965 | 945 | $result = $this->update_table_collation( $table, $reference_charset_status[0], $reference_charset_status[1] ); |
| 966 | 946 | } else { |
| 967 | 947 | $result = true; |
| 968 | 948 | } |
| @@ -973,9 +953,15 @@ | ||
| 973 | 953 | $check_msg_txt = $check->Msg_text ?? ''; // phpcs:ignore |
| 974 | 954 | if ( 'OK' === $check_msg_txt ) { |
| 975 | 955 | $result = 'The table is okay, it does not need to be repaired.'; |
| 976 | 956 | } else { |
| 977 | - self::log_error( $check_msg_txt ); | |
| 957 | + // @codeCoverageIgnoreStart | |
| 958 | + $repair = self::get_row( "REPAIR TABLE $table" ); | |
| 959 | + $repair_msg_txt = $repair->Msg_text ?? ''; // phpcs:ignore | |
| 960 | + $result = 'OK' === $repair_msg_txt | |
| 961 | + ? "Successfully repaired the $table table." | |
| 962 | + : "Failed to repair the $table table. Error: $repair->Msg_text"; | |
| 963 | + // @codeCoverageIgnoreEnd | |
| 978 | 964 | } |
| 979 | 965 | } |
| 980 | 966 | |
| 981 | 967 | return array( $table, $result ); |