CwpWorkflowDefinitionExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 23 4
1
<?php
2
3
namespace CWP\CWP\Extensions;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\ORM\DataExtension;
7
use SilverStripe\ORM\DB;
8
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition;
0 ignored issues
show
Bug introduced by
The type Symbiote\AdvancedWorkflo...ects\WorkflowDefinition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Ensures that the default template is created
12
 */
13
class CwpWorkflowDefinitionExtension extends DataExtension
14
{
15
    /**
16
     * Create the default 'Two-step Workflow' when this extension is loaded
17
     *
18
     * @config
19
     * @var boolean
20
     */
21
    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...
22
23
    public function requireDefaultRecords()
24
    {
25
        if (Config::inst()->get(CwpWorkflowDefinitionExtension::class, 'create_default_workflow')) {
26
            // Only proceed if a definition using this template has not been created yet
27
            $definition = WorkflowDefinition::get()->filter("Template", "Review and Approve")->First();
28
            if ($definition && $definition->exists()) {
29
                return;
30
            }
31
32
            //generate from the template, which happens after we write the definition
33
            $definition = WorkflowDefinition::create();
34
            $definition->Template = "Review and Approve";
35
            $definition->write();
36
37
            //change the title, description, and reminder days
38
            $definition->update(array(
39
                'Title' => "Two-step Workflow",
40
                'Description' => "Content Authors can write content and Content Publishers can approve/reject.",
41
                'RemindDays' => 3,
42
            ));
43
            $definition->write();
44
45
            DB::alteration_message("Added default workflow definition to WorkflowDefinition table", "created");
46
        }
47
    }
48
}
49