BatchProcess.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. class NF_AJAX_REST_BatchProcess extends NF_AJAX_REST_Controller
  3. {
  4. protected $action = 'nf_batch_process';
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. /**
  10. * POST /forms/<id>/
  11. * @param array $request_data [ int $clone_id ]
  12. * @return array $data [ int $new_form_id ]
  13. */
  14. public function post( $request_data )
  15. {
  16. $data = array();
  17. // If we don't have a nonce...
  18. // OR if the nonce is invalid...
  19. if ( ! isset( $request_data[ 'security' ] ) || ! wp_verify_nonce( $request_data[ 'security' ], 'ninja_forms_batch_nonce' ) ) {
  20. // Kick the request out now.
  21. $data[ 'error' ] = __( 'Request forbidden.', 'ninja-forms' );
  22. }
  23. // If we have a batch type...
  24. if ( isset( $request_data[ 'batch_type' ]) ){
  25. $batch_type = $request_data[ 'batch_type' ];
  26. // Route the request to the proper controller.
  27. switch ( $batch_type ) {
  28. case 'chunked_publish':
  29. $batch = new NF_Admin_Processes_ChunkPublish(
  30. $request_data );
  31. break;
  32. case 'data_cleanup':
  33. $batch = new NF_Admin_Processes_DataCleanup(
  34. $request_data );
  35. break;
  36. case 'expired_submission_cleanup':
  37. $batch = new NF_Admin_Processes_ExpiredSubmissionCleanup(
  38. $request_data );
  39. break;
  40. default:
  41. $data[ 'error' ] = __( 'Invalid request.', 'ninja-forms' );
  42. break;
  43. }
  44. } // Otherwise... (We don't have a batch type.)
  45. else {
  46. // Kick the request out.
  47. $data[ 'error' ] = __( 'Invalid request.', 'ninja-forms' );
  48. }
  49. return $data;
  50. }
  51. protected function get_request_data()
  52. {
  53. $request_data = array();
  54. if( isset( $_REQUEST[ 'batch_type' ] ) && $_REQUEST[ 'batch_type' ] ){
  55. $request_data[ 'batch_type' ] = $_REQUEST[ 'batch_type' ];
  56. }
  57. if( isset( $_REQUEST[ 'data' ] ) && $_REQUEST[ 'data' ] ){
  58. $request_data[ 'data' ] = $_REQUEST[ 'data' ];
  59. }
  60. if( isset( $_REQUEST[ 'security' ] ) && $_REQUEST[ 'security' ] ){
  61. $request_data[ 'security' ] = $_REQUEST[ 'security' ];
  62. }
  63. if( isset( $_REQUEST[ 'action' ] ) && $_REQUEST[ 'action' ] ){
  64. $request_data[ 'action' ] = $_REQUEST[ 'action' ];
  65. }
  66. return $request_data;
  67. }
  68. }