function test_cancel_workflow() { $step_id = $this->_add_approval_step(); $steps = $this->api->get_steps(); $count_steps = count($steps); $this->assertEquals(1, $count_steps); $this->_create_entries(); $entries = GFAPI::get_entries($this->form_id); $entry = $entries[0]; $entry_id = $entry['id']; // Refresh entry $entry = GFAPI::get_entry($entry_id); // Check status $status = $this->api->get_status($entry); $this->assertEquals('pending', $status); $this->api->cancel_workflow($entry); // Refresh entry $entry = GFAPI::get_entry($entry_id); // Check status $status = $this->api->get_status($entry); $this->assertEquals('cancelled', $status); }
function maybe_process_admin_action($form, $entry) { $feedback = false; if (isset($_POST['_gravityflow_admin_action']) && check_admin_referer('gravityflow_admin_action', '_gravityflow_admin_action_nonce') && GFAPI::current_user_can_any('gravityflow_workflow_detail_admin_actions')) { $admin_action = rgpost('gravityflow_admin_action'); switch ($admin_action) { case 'cancel_workflow': $api = new Gravity_Flow_API($form['id']); $success = $api->cancel_workflow($entry); if ($success) { $this->log_debug(__METHOD__ . '() - workflow cancelled. entry id ' . $entry['id']); $feedback = esc_html__('Workflow cancelled.', 'gravityflow'); } else { $this->log_debug(__METHOD__ . '() - workflow cancel failed. entry id ' . $entry['id']); $feedback = esc_html__('The entry does not currently have an active step.', 'gravityflow'); } break; case 'restart_step': $api = new Gravity_Flow_API($form['id']); $success = $api->restart_step($entry); if ($success) { $this->log_debug(__METHOD__ . '() - step restarted. entry id ' . $entry['id']); $feedback = esc_html__('Workflow Step restarted.', 'gravityflow'); } else { $this->log_debug(__METHOD__ . '() - step restart failed. entry id ' . $entry['id']); $feedback = esc_html__('The entry does not currently have an active step.', 'gravityflow'); } break; case 'restart_workflow': $api = new Gravity_Flow_API($form['id']); $api->restart_workflow($entry); $this->log_debug(__METHOD__ . '() - workflow restarted. entry id ' . $entry['id']); $feedback = esc_html__('Workflow restarted.', 'gravityflow'); break; } list($admin_action, $action_id) = rgexplode('|', $admin_action, 2); if ($admin_action == 'send_to_step') { $step_id = $action_id; $api = new Gravity_Flow_API($form['id']); $api->send_to_step($entry, $step_id); $new_step = $api->get_current_step($entry); $feedback = sprintf(esc_html__('Sent to step: %s', 'gravityflow'), $new_step->get_name()); } } return $feedback; }