| @@ -47,21 +47,28 @@ | ||
| 47 | 47 | 'methods' => array('POST'), |
| 48 | 48 | 'callback' => array($this, 'save'), |
| 49 | 49 | 'permission_callback' => '__return_true', |
| 50 | 50 | 'args' => array( |
| 51 | - 'access' => $this->get_param( 'access' ), | |
| 52 | - 'dbs' => $this->get_param( 'dbs' ), | |
| 53 | - 'name' => $this->get_param( 'name' ), | |
| 54 | - 'query' => $this->get_param( 'query' ), | |
| 55 | - 'vqb' => $this->get_param( 'vqb' ), | |
| 56 | - 'old_name' => array( | |
| 51 | + 'access' => $this->get_param( 'access' ), | |
| 52 | + 'dbs' => $this->get_param( 'dbs' ), | |
| 53 | + 'name' => $this->get_param( 'name' ), | |
| 54 | + 'query' => $this->get_param( 'query' ), | |
| 55 | + 'is_visual' => array( | |
| 57 | 56 | 'required' => false, |
| 57 | + 'type' => 'boolean', | |
| 58 | + 'description' => __( 'Is Visual Query?', 'wp-data-access' ), | |
| 59 | + 'sanitize_callback' => 'sanitize_text_field', | |
| 60 | + 'validate_callback' => 'rest_validate_request_arg', | |
| 61 | + ), | |
| 62 | + 'vqb' => $this->get_param( 'vqb' ), | |
| 63 | + 'old_name' => array( | |
| 64 | + 'required' => false, | |
| 58 | 65 | 'type' => 'string', |
| 59 | 66 | 'description' => __( 'Old query name', 'wp-data-access' ), |
| 60 | 67 | 'sanitize_callback' => 'sanitize_text_field', |
| 61 | 68 | 'validate_callback' => 'rest_validate_request_arg', |
| 62 | 69 | ), |
| 63 | - 'insert' => array( | |
| 70 | + 'insert' => array( | |
| 64 | 71 | 'required' => false, |
| 65 | 72 | 'type' => 'boolean', |
| 66 | 73 | 'description' => __( 'Perform insert', 'wp-data-access' ), |
| 67 | 74 | 'sanitize_callback' => 'sanitize_text_field', |
| @@ -66,9 +73,9 @@ | ||
| 66 | 73 | 'description' => __( 'Perform insert', 'wp-data-access' ), |
| 67 | 74 | 'sanitize_callback' => 'sanitize_text_field', |
| 68 | 75 | 'validate_callback' => 'rest_validate_request_arg', |
| 69 | 76 | ), |
| 70 | - 'params' => $this->get_param( 'params' ), | |
| 77 | + 'params' => $this->get_param( 'params' ), | |
| 71 | 78 | ), |
| 72 | 79 | ) ); |
| 73 | 80 | register_rest_route( WPDA_API::WPDA_NAMESPACE, 'qb/delete', array( |
| 74 | 81 | 'methods' => array('POST'), |
| @@ -178,9 +185,12 @@ | ||
| 178 | 185 | } |
| 179 | 186 | if ( !$this->current_user_token_valid( $request ) ) { |
| 180 | 187 | return $this->invalid_nonce(); |
| 181 | 188 | } |
| 182 | - return $this->unauthorized(); | |
| 189 | + $dbs = $request->get_param( 'dbs' ); | |
| 190 | + $tbl = $request->get_param( 'tbl' ); | |
| 191 | + $cols = WPDA_Dictionary_Lists::get_table_widget_info( $dbs, $tbl ); | |
| 192 | + return $this->WPDA_Rest_Response( '', $cols ); | |
| 183 | 193 | } |
| 184 | 194 | |
| 185 | 195 | public function vqb_get( $request ) { |
| 186 | 196 | if ( !$this->current_user_can_access() ) { |
| @@ -188,9 +198,17 @@ | ||
| 188 | 198 | } |
| 189 | 199 | if ( !$this->current_user_token_valid( $request ) ) { |
| 190 | 200 | return $this->invalid_nonce(); |
| 191 | 201 | } |
| 192 | - return $this->unauthorized(); | |
| 202 | + $access = $request->get_param( 'access' ); | |
| 203 | + $name = $request->get_param( 'name' ); | |
| 204 | + $qb = new WPDA_Query_Builder(); | |
| 205 | + if ( 'user' === $access ) { | |
| 206 | + $query = $qb->get_visual_query( $name ); | |
| 207 | + } else { | |
| 208 | + $query = maybe_unserialize( $qb->get_visual_query_global( $name ) ); | |
| 209 | + } | |
| 210 | + return $this->WPDA_Rest_Response( '', $query ); | |
| 193 | 211 | } |
| 194 | 212 | |
| 195 | 213 | public function open( $request ) { |
| 196 | 214 | if ( !$this->current_user_can_access() ) { |
| @@ -244,8 +262,9 @@ | ||
| 244 | 262 | $access = $request->get_param( 'access' ); |
| 245 | 263 | $dbs = $request->get_param( 'dbs' ); |
| 246 | 264 | $name = $request->get_param( 'name' ); |
| 247 | 265 | $query = $request->get_param( 'query' ); |
| 266 | + $is_visual = '1' === $request->get_param( 'is_visual' ); | |
| 248 | 267 | $vqb = $request->get_param( 'vqb' ); |
| 249 | 268 | $old_name = $request->get_param( 'old_name' ) ?? ''; |
| 250 | 269 | $insert = '1' === $request->get_param( 'insert' ); |
| 251 | 270 | $params = $request->get_param( 'params' ); |
| @@ -261,8 +280,9 @@ | ||
| 261 | 280 | $dbs, |
| 262 | 281 | $name, |
| 263 | 282 | $query, |
| 264 | 283 | $old_name, |
| 284 | + $is_visual, | |
| 265 | 285 | $vqb, |
| 266 | 286 | $params |
| 267 | 287 | ); |
| 268 | 288 | } |
| @@ -276,8 +296,9 @@ | ||
| 276 | 296 | $dbs, |
| 277 | 297 | $name, |
| 278 | 298 | $query, |
| 279 | 299 | $old_name, |
| 300 | + $is_visual, | |
| 280 | 301 | $vqb, |
| 281 | 302 | $params |
| 282 | 303 | ); |
| 283 | 304 | } |
| @@ -321,8 +342,9 @@ | ||
| 321 | 342 | $access_to = $request->get_param( 'access_to' ); |
| 322 | 343 | $to_name = $request->get_param( 'to' ); |
| 323 | 344 | $qb = new WPDA_Query_Builder(); |
| 324 | 345 | $source = ( 'user' === $access_from ? $qb->get_query( $from_name ) : $qb->get_query_global( $from_name ) ); |
| 346 | + $visual = ( 'user' === $access_from ? $qb->get_visual_query( $from_name ) : maybe_unserialize( $qb->get_visual_query_global( $from_name ) ) ); | |
| 325 | 347 | if ( 0 === count( $source ) ) { |
| 326 | 348 | return new \WP_Error('error', 'Source query not found', array( |
| 327 | 349 | 'status' => 403, |
| 328 | 350 | )); |
| @@ -330,13 +352,19 @@ | ||
| 330 | 352 | if ( 'user' === $access_to ) { |
| 331 | 353 | $saved = $qb->get_query( $to_name ); |
| 332 | 354 | if ( 0 === count( $saved ) ) { |
| 333 | 355 | $qb->add_query( $to_name, $source ); |
| 356 | + if ( !empty( $visual ) ) { | |
| 357 | + $qb->upd_visual_query( $to_name, $visual ); | |
| 358 | + } | |
| 334 | 359 | } |
| 335 | 360 | } else { |
| 336 | 361 | $saved = $qb->get_query_global( $to_name ); |
| 337 | 362 | if ( 0 === count( $saved ) ) { |
| 338 | 363 | $qb->add_query_global( $to_name, $source ); |
| 364 | + if ( !empty( $visual ) ) { | |
| 365 | + $qb->upd_visual_query_global( $to_name, $visual ); | |
| 366 | + } | |
| 339 | 367 | } |
| 340 | 368 | } |
| 341 | 369 | if ( 0 === count( $saved ) ) { |
| 342 | 370 | return $this->WPDA_Rest_Response( '' ); |
| @@ -381,31 +409,19 @@ | ||
| 381 | 409 | } |
| 382 | 410 | } |
| 383 | 411 | |
| 384 | 412 | public function cron_schedules( $request ) { |
| 385 | - if ( !$this->current_user_can_access() ) { | |
| 386 | - return $this->unauthorized(); | |
| 387 | - } | |
| 388 | - if ( !$this->current_user_token_valid( $request ) ) { | |
| 389 | - return $this->invalid_nonce(); | |
| 390 | - } | |
| 413 | + // This feature is implemented in the premium version | |
| 414 | + return $this->unauthorized(); | |
| 391 | 415 | } |
| 392 | 416 | |
| 393 | 417 | public function cron_add( $request ) { |
| 394 | - if ( !$this->current_user_can_access() ) { | |
| 395 | - return $this->unauthorized(); | |
| 396 | - } | |
| 397 | - if ( !$this->current_user_token_valid( $request ) ) { | |
| 398 | - return $this->invalid_nonce(); | |
| 399 | - } | |
| 418 | + // This feature is implemented in the premium version | |
| 419 | + return $this->unauthorized(); | |
| 400 | 420 | } |
| 401 | 421 | |
| 402 | 422 | public function cron_delete( $request ) { |
| 403 | - if ( !$this->current_user_can_access() ) { | |
| 404 | - return $this->unauthorized(); | |
| 405 | - } | |
| 406 | - if ( !$this->current_user_token_valid( $request ) ) { | |
| 407 | - return $this->invalid_nonce(); | |
| 408 | - } | |
| 423 | + // This feature is implemented in the premium version | |
| 424 | + return $this->unauthorized(); | |
| 409 | 425 | } |
| 410 | 426 | |
| 411 | 427 | } |