| @@ -136,9 +136,9 @@ | ||
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Get table meta info. |
| 139 | 139 | * |
| 140 | - * @param WP_REST_Request $request Rest API request. | |
| 140 | + * @param \WP_REST_Request $request Rest API request. | |
| 141 | 141 | * @return \WP_Error|\WP_REST_Response |
| 142 | 142 | */ |
| 143 | 143 | public function table_meta( $request ) { |
| 144 | 144 | $dbs = $request->get_param( 'dbs' ); |
| @@ -165,9 +165,9 @@ | ||
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * Database table query using the full primary key. Must return exactly one row. |
| 168 | 168 | * |
| 169 | - * @param WP_REST_Request $request Rest API request. | |
| 169 | + * @param \WP_REST_Request $request Rest API request. | |
| 170 | 170 | * @return \WP_Error|\WP_REST_Response |
| 171 | 171 | */ |
| 172 | 172 | public function table_get( $request ) { |
| 173 | 173 | $dbs = $request->get_param( 'dbs' ); |
| @@ -200,9 +200,9 @@ | ||
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * Insert one row. |
| 203 | 203 | * |
| 204 | - * @param WP_REST_Request $request Rest API request. | |
| 204 | + * @param \WP_REST_Request $request Rest API request. | |
| 205 | 205 | * @return \WP_Error|\WP_REST_Response |
| 206 | 206 | */ |
| 207 | 207 | public function table_insert( $request ) { |
| 208 | 208 | $dbs = $request->get_param( 'dbs' ); |
| @@ -229,9 +229,9 @@ | ||
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * Update uses primary key. Must return exactly one row. |
| 232 | 232 | * |
| 233 | - * @param WP_REST_Request $request Rest API request. | |
| 233 | + * @param \WP_REST_Request $request Rest API request. | |
| 234 | 234 | * @return \WP_Error|\WP_REST_Response |
| 235 | 235 | */ |
| 236 | 236 | public function table_update( $request ) { |
| 237 | 237 | $dbs = $request->get_param( 'dbs' ); |
| @@ -264,9 +264,9 @@ | ||
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Delete uses primary key. Must return exactly one row. |
| 267 | 267 | * |
| 268 | - * @param WP_REST_Request $request Rest API request. | |
| 268 | + * @param \WP_REST_Request $request Rest API request. | |
| 269 | 269 | * @return \WP_Error|\WP_REST_Response |
| 270 | 270 | */ |
| 271 | 271 | public function table_delete( $request ) { |
| 272 | 272 | $dbs = $request->get_param( 'dbs' ); |
| @@ -293,12 +293,13 @@ | ||
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Database table query to populate a list of values for a specific table/column. |
| 296 | 296 | * |
| 297 | - * @param WP_REST_Request $request Rest API request. | |
| 297 | + * @param \WP_REST_Request $request Rest API request. | |
| 298 | 298 | * @return \WP_Error|\WP_REST_Response |
| 299 | 299 | */ |
| 300 | 300 | public function table_lov( $request ) { |
| 301 | + return null; | |
| 301 | 302 | } |
| 302 | 303 | |
| 303 | 304 | /** |
| 304 | 305 | * Database table query. |
| @@ -304,9 +305,9 @@ | ||
| 304 | 305 | * Database table query. |
| 305 | 306 | * |
| 306 | 307 | * Supports: searching, ordering and pagination. |
| 307 | 308 | * |
| 308 | - * @param WP_REST_Request $request Rest API request. | |
| 309 | + * @param \WP_REST_Request $request Rest API request. | |
| 309 | 310 | * @return \WP_Error|\WP_REST_Response |
| 310 | 311 | */ |
| 311 | 312 | public function table_select( $request ) { |
| 312 | 313 | $dbs = $request->get_param( 'dbs' ); |
| @@ -391,8 +392,9 @@ | ||
| 391 | 392 | $md = array(), |
| 392 | 393 | $m2m_relationship = array(), |
| 393 | 394 | $search_data_types = array() |
| 394 | 395 | ) { |
| 396 | + return null; | |
| 395 | 397 | } |
| 396 | 398 | |
| 397 | 399 | public function lookup( |
| 398 | 400 | $dbs, |
| @@ -433,10 +435,21 @@ | ||
| 433 | 435 | } |
| 434 | 436 | } |
| 435 | 437 | $dynamic_where = array(); |
| 436 | 438 | if ( is_array( $column_dynamic_values ) && 0 < count( $column_dynamic_values ) ) { |
| 439 | + $dynamic_allowed = array(); | |
| 440 | + $dynamic_table = WPDA_List_Columns_Cache::get_list_columns( $dbs, $tbl ); | |
| 441 | + $dynamic_columns = $dynamic_table->get_table_columns(); | |
| 442 | + foreach ( $dynamic_columns as $column ) { | |
| 443 | + if ( isset( $column['column_name'] ) ) { | |
| 444 | + $dynamic_allowed[] = $column['column_name']; | |
| 445 | + } | |
| 446 | + } | |
| 437 | 447 | foreach ( $column_dynamic_values as $key => $value ) { |
| 438 | - $dynamic_where[] = $wpdadb->prepare( " `{$key}` = %s ", $value ); | |
| 448 | + if ( !in_array( $key, $dynamic_allowed, true ) ) { | |
| 449 | + continue; | |
| 450 | + } | |
| 451 | + $dynamic_where[] = $wpdadb->prepare( " %i = %s ", array($key, $value) ); | |
| 439 | 452 | } |
| 440 | 453 | $where .= (( '' === $where ? ' where ' : ' and ' )) . ' (' . implode( ' and ', $dynamic_where ) . ') '; |
| 441 | 454 | } |
| 442 | 455 | $column_count = ( '' === $subquery ? '' : ", stats.total_rows as 'count'" ); |
| @@ -538,10 +551,12 @@ | ||
| 538 | 551 | // Prepare selected column list |
| 539 | 552 | $columns_selected = array(); |
| 540 | 553 | $search_data_types = array(); |
| 541 | 554 | foreach ( $table_columns as $table_column ) { |
| 542 | - $columns_selected[$table_column['column_name']] = true; | |
| 543 | - $search_data_types[$table_column['column_name']] = $table_column['data_type']; | |
| 555 | + if ( isset( $table_column['column_name'], $table_column['data_type'] ) && (in_array( $table_column['column_name'], $column_names ) || empty( $column_names )) ) { | |
| 556 | + $columns_selected[$table_column['column_name']] = true; | |
| 557 | + $search_data_types[$table_column['column_name']] = $table_column['data_type']; | |
| 558 | + } | |
| 544 | 559 | } |
| 545 | 560 | $selected_columns = $this->get_selected_columns( $columns_selected, $search_data_types ); |
| 546 | 561 | $sql = $wpdadb->prepare( "\n select {$selected_columns}\n from `%1s`\n {$where}\n ", array($tbl) ); |
| 547 | 562 | $dataset = $wpdadb->get_results( $sql, 'ARRAY_A' ); |
| @@ -796,8 +811,9 @@ | ||
| 796 | 811 | return $sql; |
| 797 | 812 | } |
| 798 | 813 | |
| 799 | 814 | private function get_md( $md, $wpdadb, $m2m_relationship ) { |
| 815 | + return null; | |
| 800 | 816 | } |
| 801 | 817 | |
| 802 | 818 | private function get_global_filter( |
| 803 | 819 | $wpdadb, |
| @@ -839,8 +855,9 @@ | ||
| 839 | 855 | $lookups, |
| 840 | 856 | $m2m_relationship, |
| 841 | 857 | $search_data_types |
| 842 | 858 | ) { |
| 859 | + return null; | |
| 843 | 860 | } |
| 844 | 861 | |
| 845 | 862 | private function get_where( |
| 846 | 863 | $wpdadb, |
| @@ -899,8 +916,12 @@ | ||
| 899 | 916 | if ( !is_array( $column_names ) ) { |
| 900 | 917 | return '*'; |
| 901 | 918 | // select all columns |
| 902 | 919 | } |
| 920 | + if ( 0 === count( $column_names ) ) { | |
| 921 | + return '*'; | |
| 922 | + // select all columns | |
| 923 | + } | |
| 903 | 924 | // Check for geo columns |
| 904 | 925 | $geometryColumns = array(); |
| 905 | 926 | if ( is_array( $search_data_types ) ) { |
| 906 | 927 | foreach ( $search_data_types as $column_name => $search_data_type ) { |
| @@ -1177,8 +1198,9 @@ | ||
| 1177 | 1198 | $search_value, |
| 1178 | 1199 | $m2m_relationship = array(), |
| 1179 | 1200 | $search_data_types = array() |
| 1180 | 1201 | ) { |
| 1202 | + return null; | |
| 1181 | 1203 | } |
| 1182 | 1204 | |
| 1183 | 1205 | public static function add_condition( $where_lines, $operand = 'and' ) { |
| 1184 | 1206 | if ( 0 < count( array_filter( $where_lines ) ) ) { |
| @@ -1194,9 +1216,9 @@ | ||
| 1194 | 1216 | * |
| 1195 | 1217 | * @param string $dbs Database schema name. |
| 1196 | 1218 | * @param string $tbl Database table name. |
| 1197 | 1219 | * @param string $waa With admin actions. |
| 1198 | - * @return array\object | |
| 1220 | + * @return array | object | |
| 1199 | 1221 | */ |
| 1200 | 1222 | public function get_table_meta_data( $dbs, $tbl, $waa ) { |
| 1201 | 1223 | $sql_create_table = ''; |
| 1202 | 1224 | if ( WPDA::current_user_is_admin() ) { |
| @@ -1332,9 +1354,9 @@ | ||
| 1332 | 1354 | if ( isset( $table[$action]['authorized_users'] ) && is_array( $table[$action]['authorized_users'] ) && 0 < count( $table[$action]['authorized_users'] ) && in_array( (string) $this->get_user_login(), $table[$action]['authorized_users'] ) ) { |
| 1333 | 1355 | return $table[$action]['methods']; |
| 1334 | 1356 | } |
| 1335 | 1357 | // Check authorized roles |
| 1336 | - if ( isset( $table[$action]['authorized_roles'] ) && is_array( $table[$action]['authorized_roles'] ) && 0 < count( $table[$action]['authorized_roles'] ) && 0 < count( array_intersect( $this->get_user_roles(), $table[$action]['authorized_roles'] ) ) ) { | |
| 1358 | + if ( isset( $table[$action]['authorized_roles'] ) && is_array( $table[$action]['authorized_roles'] ) && 0 < count( $table[$action]['authorized_roles'] ) && 0 < count( array_intersect( ( is_array( $this->get_user_roles() ) ? $this->get_user_roles() : array() ), $table[$action]['authorized_roles'] ) ) ) { | |
| 1337 | 1359 | return $table[$action]['methods']; |
| 1338 | 1360 | } |
| 1339 | 1361 | } |
| 1340 | 1362 | } |
| @@ -1345,9 +1367,9 @@ | ||
| 1345 | 1367 | * Check if access is grant for requested database/table. |
| 1346 | 1368 | * |
| 1347 | 1369 | * @param string $dbs Remote or local database connection string. |
| 1348 | 1370 | * @param string $tbl Database table name. |
| 1349 | - * @param onject $request Request object. | |
| 1371 | + * @param object $request Request object. | |
| 1350 | 1372 | * @param string $action Possible values: select, insert, update, delete. |
| 1351 | 1373 | * @return bool |
| 1352 | 1374 | */ |
| 1353 | 1375 | private function check_table_access( |