jobs_actions = $jobs_actions; $this->translation_management = $translation_management; } function add_hooks() { $this->register_routes(); } function register_routes() { parent::register_route( self::ENDPOINT_JOBS_RECEIVE . '(?P\d+)', array( 'methods' => 'GET', 'callback' => array( $this, 'receive_ate_job' ), 'args' => array( 'wpmlJobId' => array( 'required' => true, 'type' => 'int', 'validate_callback' => array( 'WPML_REST_Arguments_Validation', 'integer' ), 'sanitize_callback' => array( 'WPML_REST_Arguments_Sanitation', 'integer' ), ), ), 'permission_callback' => '__return_true', ) ); } public function get_allowed_capabilities( WP_REST_Request $request ) { return array(); } /** * @param WP_REST_Request $request * * @return WP_REST_Response|WP_Error */ public function receive_ate_job( WP_REST_Request $request ) { $wpml_job_id = $request->get_param( 'wpmlJobId' ); $wpml_job = $this->translation_management->get_translation_job( $wpml_job_id ); if ( ! $wpml_job ) { return new WP_Error( self::CODE_UNPROCESSABLE_ENTITY ); } try { $this->jobs_actions->update_jobs( false, array( $wpml_job ) ); } catch ( Exception $e ) { return new WP_Error( self::CODE_UNPROCESSABLE_ENTITY ); } return new WP_REST_Response( null, self::CODE_OK ); } /** * @param int $wpml_job_id * * @return string */ public static function get_receive_ate_job_url( $wpml_job_id ) { return self::get_url( self::ENDPOINT_JOBS_RECEIVE . $wpml_job_id ); } }