DevTaskRun::getCMSFields()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
namespace Webtorque\DevTaskRunner\Model;
4
5
use SilverStripe\ORM\DataObject;
6
use SilverStripe\Dev\BuildTask;
7
use SilverStripe\Core\ClassInfo;
8
use SilverStripe\Forms\DropdownField;
9
use SilverStripe\Forms\TextField;
10
11
class DevTaskRun extends DataObject
12
{
13
    private static $table_name = 'DevTaskRun';
0 ignored issues
show
Unused Code introduced by
The property $table_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'Task' => 'Varchar(150)',
17
        'Params' => 'Varchar(255)',
18
        'Status' => 'Enum("Queued,Running,Finished", "Queued")',
19
        'FinishDate' => 'Datetime'
20
    );
21
22
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
        'TaskTitle' => 'Task',
24
        'Params' => 'Params',
25
        'Status' => 'Status',
26
        'FinishDate' => 'Finish Date'
27
    );
28
29
    private static $default_sort = 'Created DESC';
0 ignored issues
show
Unused Code introduced by
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
    {
33
        $fields = parent::getCMSFields();
34
35
        $taskList = array();
36
37
        //defined allowed task list
38
        $tasks = $this->config()->task_list;
39
40
        //default to all tasks
41
        if (!$tasks) {
42
            $tasks = ClassInfo::subclassesFor(BuildTask::class);
43
            array_shift($tasks);
44
        }
45
46
        foreach ($tasks as $task) {
47
            $taskList[$task] = singleton($task)->getTitle();
48
        }
49
50
        $fields->addFieldsToTab('Root.Main', array(
51
            DropdownField::create('Task', 'Task', $taskList),
52
            TextField::create('Params')->setDescription('add a list of params to be passed to task, separate with space, e.g. param1=value1 param2=value2')
53
        ));
54
55
        return $fields;
56
    }
57
58
    public function TaskTitle()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
59
    {
60
        if ($this->Task) {
61
            return singleton($this->Task)->getTitle();
62
        }
63
64
        return '';
65
    }
66
67
    public static function get_next_task()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
68
    {
69
        return DevTaskRun::get()->filter('Status', 'Queued')->sort('Created ASC')->first();
70
    }
71
}