| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | /** |
| 12 | 12 | * Class DataBase |
| 13 | 13 | * |
| 14 | 14 | * @since 4.2.9.3 |
| 15 | - * @version 1.0.0 | |
| 15 | + * @version 1.0.1 | |
| 16 | 16 | */ |
| 17 | 17 | class DataBase { |
| 18 | 18 | private static $_instance; |
| 19 | 19 | public $wpdb, $tb_users; |
| @@ -31,8 +31,9 @@ | ||
| 31 | 31 | public $tb_lp_sessions; |
| 32 | 32 | public $tb_lp_files; |
| 33 | 33 | public $tb_lp_webhooks; |
| 34 | 34 | public $tb_thim_cache; |
| 35 | + public $tb_lp_mcp_api_keys; | |
| 35 | 36 | private $collate = ''; |
| 36 | 37 | public $max_index_length = '191'; |
| 37 | 38 | |
| 38 | 39 | protected function __construct() { |
| @@ -65,8 +66,9 @@ | ||
| 65 | 66 | $this->tb_lp_sessions = $prefix . 'learnpress_sessions'; |
| 66 | 67 | $this->tb_lp_files = $prefix . 'learnpress_files'; |
| 67 | 68 | $this->tb_lp_webhooks = $prefix . 'learnpress_webhooks'; |
| 68 | 69 | $this->tb_thim_cache = $prefix . 'thim_cache'; |
| 70 | + $this->tb_lp_mcp_api_keys = $prefix . 'learnpress_mcp_api_keys'; | |
| 69 | 71 | $this->wpdb->hide_errors(); |
| 70 | 72 | $this->set_collate(); |
| 71 | 73 | } |
| 72 | 74 | |
| @@ -108,11 +110,16 @@ | ||
| 108 | 110 | * |
| 109 | 111 | * @param string $name_table |
| 110 | 112 | * |
| 111 | 113 | * @return bool|int |
| 114 | + * @throws Exception | |
| 112 | 115 | */ |
| 113 | 116 | public function check_table_exists( string $name_table ) { |
| 114 | - return $this->wpdb->query( $this->wpdb->prepare( "SHOW TABLES LIKE '%s'", $name_table ) ); | |
| 117 | + return $this->wpdb->query( | |
| 118 | + $this->wpdb->prepare( | |
| 119 | + "SHOW TABLES LIKE '%s'", $name_table | |
| 120 | + ) | |
| 121 | + ); | |
| 115 | 122 | } |
| 116 | 123 | |
| 117 | 124 | /** |
| 118 | 125 | * Clone table |
| @@ -154,8 +161,9 @@ | ||
| 154 | 161 | * @return bool|int |
| 155 | 162 | */ |
| 156 | 163 | public function check_col_table( string $name_table = '', string $name_col = '' ) { |
| 157 | 164 | $query = $this->wpdb->prepare( "SHOW COLUMNS FROM $name_table LIKE '%s'", $name_col ); |
| 165 | + //$query = $this->wpdb->prepare( "SHOW COLUMNS FROM $name_table WHERE Field = '%s'", $name_col ); | |
| 158 | 166 | |
| 159 | 167 | return $this->wpdb->query( $query ); |
| 160 | 168 | } |
| 161 | 169 | |
| @@ -198,9 +206,9 @@ | ||
| 198 | 206 | * @throws Exception |
| 199 | 207 | */ |
| 200 | 208 | public function add_col_table( string $name_table, string $name_col, string $type, string $after_col = '' ) { |
| 201 | 209 | if ( ! current_user_can( ADMIN_ROLE ) ) { |
| 202 | - throw new Exception( 'You don\'t have permission' ); | |
| 210 | + return false; | |
| 203 | 211 | } |
| 204 | 212 | |
| 205 | 213 | $query_add = ''; |
| 206 | 214 | |
| @@ -789,9 +797,8 @@ | ||
| 789 | 797 | $data = $args['data'] ?? []; |
| 790 | 798 | $filter = $args['filter'] ?? null; |
| 791 | 799 | $table_name = $args['table_name'] ?? ''; |
| 792 | 800 | $key_auto_increment = $args['key_auto_increment'] ?? ''; |
| 793 | - $key_auto_increment = sanitize_key( $key_auto_increment ); | |
| 794 | 801 | |
| 795 | 802 | if ( empty( $data ) || ! is_array( $data ) ) { |
| 796 | 803 | throw new Exception( __( 'Data must be an array!', 'learnpress' ) . ' | ' . __FUNCTION__ ); |
| 797 | 804 | } |
| @@ -836,9 +843,9 @@ | ||
| 836 | 843 | * @return bool |
| 837 | 844 | * |
| 838 | 845 | * @throws Exception |
| 839 | 846 | * @since 4.2.9 |
| 840 | - * @version 1.0.1 | |
| 847 | + * @version 1.0.2 | |
| 841 | 848 | */ |
| 842 | 849 | public function update_data( array $args ): bool { |
| 843 | 850 | $data = $args['data'] ?? []; |
| 844 | 851 | $filter = $args['filter'] ?? null; |
| @@ -843,9 +850,8 @@ | ||
| 843 | 850 | $data = $args['data'] ?? []; |
| 844 | 851 | $filter = $args['filter'] ?? null; |
| 845 | 852 | $table_name = $args['table_name'] ?? ''; |
| 846 | 853 | $where_key = $args['where_key'] ?? ''; |
| 847 | - $where_key = sanitize_key( $where_key ); | |
| 848 | 854 | |
| 849 | 855 | /*if ( ! $filter instanceof FilterBase ) { |
| 850 | 856 | throw new Exception( __( 'Invalid filter!', 'learnpress' ) . ' | ' . __FUNCTION__ ); |
| 851 | 857 | }*/ |