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 ( 95a104...d03d4c )
by Guy
27s
created

src/Controllers/QueuedTaskRunner.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 = [
23
        'queue/$TaskName' => 'queueTask',
24
    ];
25
26
    private static $allowed_actions = [
27
        'queueTask',
28
    ];
29
30
    private static $task_blacklist = [
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 = [];
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
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
     *
97
     * @param HTTPRequest $request
98
     */
99
    public function queueTask($request)
100
    {
101
        $name = $request->param('TaskName');
102
        $tasks = $this->getTasks();
103
104
        $variables = $request->getVars();
105
        unset($variables['url']);
106
        unset($variables['flush']);
107
        unset($variables['flushtoken']);
108
        unset($variables['isDev']);
109
        $querystring = http_build_query($variables);
110
111
        $title = function ($content) {
112
            printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
113
        };
114
115
        $message = function ($content) {
116
            printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
117
        };
118
119
        foreach ($tasks as $task) {
120
            if ($task['segment'] == $name) {
121
                /** @var BuildTask $inst */
122
                $inst = Injector::inst()->create($task['class']);
123
                if (!$inst->isEnabled()) {
124
                    $message('The task is disabled');
125
                    return;
126
                }
127
128
                $title(sprintf('Queuing Task %s', $inst->getTitle()));
129
130
                $job = new RunBuildTaskJob($task['class'], $querystring);
131
                $jobID = Injector::inst()->get(QueuedJobService::class)->queueJob($job);
132
133
                $message('Done: queued with job ID ' . $jobID);
134
                $adminLink = Director::baseURL() . "admin/queuedjobs/" . str_replace('\\', '-', QueuedJobDescriptor::class);
135
                $message("Visit <a href=\"$adminLink\">queued jobs admin</a> to see job status");
136
                return;
137
            }
138
        }
139
140
        $message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name)));
141
    }
142
}
143