Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

CwpWorkflowDefinitionExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 20 4
1
<?php
2
3
/**
4
 * Ensures that the default template is created
5
 */
6
class CwpWorkflowDefinitionExtension extends DataExtension {
7
8
	/**
9
	 * Create the default 'Two-step Workflow' when this extension is loaded
10
	 *
11
	 * @config
12
	 * @var boolean
13
	 */
14
	private static $create_default_workflow = true;
0 ignored issues
show
introduced by
The private property $create_default_workflow is not used, and could be removed.
Loading history...
15
16
	public function requireDefaultRecords() {
17
		if(Config::inst()->get('CwpWorkflowDefinitionExtension', 'create_default_workflow')) {
18
			// Only proceed if a definition using this template has not been created yet
19
			$definition = WorkflowDefinition::get()->filter("Template", "Review and Approve")->First();
20
			if($definition && $definition->exists()) return;
21
22
			//generate from the template, which happens after we write the definition
23
			$definition = WorkflowDefinition::create();
24
			$definition->Template = "Review and Approve";
25
			$definition->write();
26
27
			//change the title, description, and reminder days
28
			$definition->update(array(
29
				'Title' => "Two-step Workflow",
30
				'Description' => "Content Authors can write content and Content Publishers can approve/reject.",
31
				'RemindDays' => 3,
32
			));
33
			$definition->write();
34
35
			DB::alteration_message("Added default workflow definition to WorkflowDefinition table", "created");
36
		}
37
	}
38
}
39