AdvancedWorkflowActionController::transition()   C
last analyzed

Complexity

Conditions 8
Paths 9

Size

Total Lines 45
Code Lines 30

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 45
rs 5.3846
cc 8
eloc 30
nc 9
nop 1
1
<?php
2
3
/**
4
 * Handles actions triggered from external sources, eg emails or web frontend
5
 *
6
 * @author [email protected]
7
 * @license BSD License http://silverstripe.org/bsd-license/
8
 */
9
class AdvancedWorkflowActionController extends Controller {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
	
11
	public function transition($request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
		if (!Member::currentUserID()) {
13
			return Security::permissionFailure($this, 
14
				_t(
15
					'AdvancedWorkflowActionController.ACTION_ERROR',
16
					"You must be logged in"
17
					)
18
			);
19
		}
20
21
		$id = $this->request->requestVar('id');
22
		$transition = $this->request->requestVar('transition');
23
24
		$instance = DataObject::get_by_id('WorkflowInstance', (int) $id);
25
		if ($instance && $instance->canEdit()) {
26
			$transition = DataObject::get_by_id('WorkflowTransition', (int) $transition);
27
			if ($transition) {
28
				if ($this->request->requestVar('comments')) {
29
					$action = $instance->CurrentAction();
30
					$action->Comment = $this->request->requestVar('comments');
31
					$action->write();
32
				}
33
34
				singleton('WorkflowService')->executeTransition($instance->getTarget(), $transition->ID);
35
				$result = array(
36
					'success'	=> true,
37
					'link'		=> $instance->getTarget()->AbsoluteLink()
38
				);
39
				if (Director::is_ajax()) {
40
					return Convert::raw2json($result);
41
				} else {
42
					return $this->redirect($instance->getTarget()->Link());
43
				}
44
			}
45
		}
46
47
		if (Director::is_ajax()) {
48
			$result = array(
49
				'success'		=> false,
50
			);
51
			return Convert::raw2json($result);
52
		} else {
53
			$this->redirect($instance->getTarget()->Link());
54
		}
55
	}
56
}
57