GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 85f263...c5393f )
by Daniel
10:52 queued 10s
created

QueuedTaskRunner::queueTask()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 43
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 8.439
c 0
b 0
f 0
cc 6
eloc 27
nc 4
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Controllers;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Convert;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Dev\BuildTask;
9
use SilverStripe\Dev\DebugView;
10
use SilverStripe\Dev\TaskRunner;
11
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
12
use Symbiote\QueuedJobs\Jobs\RunBuildTaskJob;
13
use Symbiote\QueuedJobs\Services\QueuedJobService;
14
use Symbiote\QueuedJobs\Tasks\CreateQueuedJobTask;
15
use Symbiote\QueuedJobs\Tasks\DeleteAllJobsTask;
16
use Symbiote\QueuedJobs\Tasks\ProcessJobQueueChildTask;
17
use Symbiote\QueuedJobs\Tasks\ProcessJobQueueTask;
18
19
class QueuedTaskRunner extends TaskRunner
20
{
21
22
    private static $url_handlers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_handlers 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
        'queue/$TaskName' => 'queueTask'
24
    );
25
26
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions 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...
27
        'queueTask'
28
    );
29
30
    private static $task_blacklist = array(
0 ignored issues
show
Unused Code introduced by
The property $task_blacklist 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...
31
        ProcessJobQueueTask::class,
32
        ProcessJobQueueChildTask::class,
33
        CreateQueuedJobTask::class,
34
        DeleteAllJobsTask::class,
35
    );
36
37
    public function index()
38
    {
39
        $tasks = $this->getTasks();
40
41
        $blacklist = (array)$this->config()->task_blacklist;
42
        $backlistedTasks = array();
43
44
        // Web mode
45
        if(!Director::is_cli()) {
46
            $renderer = new DebugView();
47
            echo $renderer->renderHeader();
48
            echo $renderer->renderInfo("SilverStripe Development Tools: Tasks (QueuedJobs version)", Director::absoluteBaseURL());
0 ignored issues
show
Security Bug introduced by
It seems like \SilverStripe\Control\Director::absoluteBaseURL() targeting SilverStripe\Control\Director::absoluteBaseURL() can also be of type false; however, SilverStripe\Dev\DebugView::renderInfo() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
49
            $base = Director::absoluteBaseURL();
50
51
            echo "<div class=\"options\">";
52
            echo "<h2>Queueable jobs</h2>\n";
53
            echo "<p>By default these jobs will be added the job queue, rather than run immediately</p>\n";
54
            echo "<ul>";
55
            foreach ($tasks as $task) {
56
                if (in_array($task['class'], $blacklist)) {
57
                    $backlistedTasks[] = $task;
58
                    continue;
59
                }
60
61
                $queueLink = $base . "dev/tasks/queue/" . $task['segment'];
62
                $immediateLink = $base . "dev/tasks/" . $task['segment'];
63
64
                echo "<li><p>";
65
                echo "<a href=\"$queueLink\">" . $task['title'] . "</a> <a style=\"font-size: 80%; padding-left: 20px\" href=\"$immediateLink\">[run immediately]</a><br />";
66
                echo "<span class=\"description\">" . $task['description'] . "</span>";
67
                echo "</p></li>\n";
68
            }
69
            echo "</ul></div>";
70
71
            echo "<div class=\"options\">";
72
            echo "<h2>Non-queueable tasks</h2>\n";
73
            echo "<p>These tasks shouldn't be added the queuejobs queue, but you can run them immediately.</p>\n";
74
            echo "<ul>";
75
            foreach ($backlistedTasks as $task) {
76
                $immediateLink = $base . "dev/tasks/" . $task['segment'];
77
78
                echo "<li><p>";
79
                echo "<a href=\"$immediateLink\">" . $task['title'] . "</a><br />";
80
                echo "<span class=\"description\">" . $task['description'] . "</span>";
81
                echo "</p></li>\n";
82
            }
83
            echo "</ul></div>";
84
85
            echo $renderer->renderFooter();
86
87
        // CLI mode - revert to default behaviour
88
        } else {
89
            return parent::index();
90
        }
91
    }
92
93
94
    /**
95
     * Adds a RunBuildTaskJob to the job queue for a given task
96
     * @param HTTPRequest $request
97
     */
98
    public function queueTask($request)
99
    {
100
        $name = $request->param('TaskName');
101
        $tasks = $this->getTasks();
102
103
        $variables = $request->getVars();
104
        unset($variables['url']);
105
        unset($variables['flush']);
106
        unset($variables['flushtoken']);
107
        unset($variables['isDev']);
108
        $querystring = http_build_query($variables);
109
110
        $title = function ($content) {
111
            printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
112
        };
113
114
        $message = function ($content) {
115
            printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
116
        };
117
118
        foreach ($tasks as $task) {
119
            if ($task['segment'] == $name) {
120
                /** @var BuildTask $inst */
121
                $inst = Injector::inst()->create($task['class']);
122
                if (!$inst->isEnabled()) {
123
                    $message('The task is disabled');
124
                    return;
125
                }
126
127
                $title(sprintf('Queuing Task %s', $inst->getTitle()));
128
129
                $job = new RunBuildTaskJob($task['class'], $querystring);
130
                $jobID = Injector::inst()->get(QueuedJobService::class)->queueJob($job);
131
132
                $message('Done: queued with job ID ' . $jobID);
133
                $adminLink = Director::baseURL() . "admin/queuedjobs/" . str_replace('\\', '-', QueuedJobDescriptor::class);
134
                $message("Visit <a href=\"$adminLink\">queued jobs admin</a> to see job status");
135
                return;
136
            }
137
        }
138
139
        $message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name)));
140
    }
141
}
142