public function multi_abort_from_workflow() { global $wpdb; if (!current_user_can('ow_abort_workflow')) { wp_die(__('You are not allowed to abort the workflow.')); } $post_ids = (array) $_POST['postids']; // sanitize the values $post_ids = array_map('esc_attr', $post_ids); $ow_history_service = new OW_History_Service(); foreach ($post_ids as $post_id) { $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . OW_Utility::instance()->get_action_history_table_name() . " WHERE post_id = %d AND action_status = 'assignment'", $post_id)); $action = $ow_history_service->get_action_history_by_id($row->ID); $comment[] = array("send_id" => get_current_user_id(), "comment" => "Post/Page was aborted from the workflow."); $data = array("action_status" => "aborted", "post_id" => $action->post_id, "comment" => json_encode($comment), "from_id" => $row->ID, "step_id" => $action->step_id, "assign_actor_id" => get_current_user_id(), 'create_datetime' => current_time('mysql')); $ow_email = new OW_Email(); $action_history_table = OW_Utility::instance()->get_action_history_table_name(); $action_table = OW_Utility::instance()->get_action_table_name(); $iid = OW_Utility::instance()->insert_to_table($action_history_table, $data); if ($iid) { // find all the history records for the given post id which has the status = "assignment" $post_action_histories = $ow_history_service->get_action_history_by_status("assignment", $post_id); foreach ($post_action_histories as $post_action_history) { // delete all the unsend emails for this workflow $ow_email->delete_step_email($post_action_history->ID); // update the current assignments to abort_no_action $wpdb->update($action_history_table, array("action_status" => "abort_no_action", "create_datetime" => current_time('mysql')), array("ID" => $post_action_history->ID)); // change the assignments in the action table to processed $wpdb->update($action_table, array("review_status" => "abort_no_action", "update_datetime" => current_time('mysql')), array("action_history_id" => $post_action_history->ID)); } $this->cleanup_after_workflow_complete($action->post_id); } } echo true; die; }