]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Queue.php
Added parameters
[friendica.git] / src / Module / Admin / Queue.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
5 use Friendica\Core\L10n;
6 use Friendica\Core\Renderer;
7 use Friendica\Database\DBA;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Arrays;
10 use Friendica\Util\DateTimeFormat;
11
12 /**
13  * @brief Admin Inspect Queue Page
14  *
15  * Generates a page for the admin to have a look into the current queue of
16  * worker jobs. Shown are the parameters for the job and its priority.
17  *
18  * @return string
19  */
20 class Queue extends BaseAdminModule
21 {
22         public static function content($parameters)
23         {
24                 parent::content($parameters);
25
26                 $a = self::getApp();
27
28                 // @TODO: Replace with parameter from router
29                 $deferred = $a->argc > 2 && $a->argv[2] == 'deferred';
30
31                 // get jobs from the workerqueue table
32                 if ($deferred) {
33                         $condition = ["NOT `done` AND `retrial` > ?", 0];
34                         $sub_title = L10n::t('Inspect Deferred Worker Queue');
35                         $info = L10n::t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
36                 } else {
37                         $condition = ["NOT `done` AND `retrial` = ?", 0];
38                         $sub_title = L10n::t('Inspect Worker Queue');
39                         $info = L10n::t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
40                 }
41
42                 // @TODO Move to Model\WorkerQueue::getEntries()
43                 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
44
45                 $r = [];
46                 while ($entry = DBA::fetch($entries)) {
47                         // fix GH-5469. ref: src/Core/Worker.php:217
48                         $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
49                         $entry['created'] = DateTimeFormat::local($entry['created']);
50                         $r[] = $entry;
51                 }
52                 DBA::close($entries);
53
54                 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
55                 return Renderer::replaceMacros($t, [
56                         '$title' => L10n::t('Administration'),
57                         '$page' => $sub_title,
58                         '$count' => count($r),
59                         '$id_header' => L10n::t('ID'),
60                         '$param_header' => L10n::t('Job Parameters'),
61                         '$created_header' => L10n::t('Created'),
62                         '$prio_header' => L10n::t('Priority'),
63                         '$info' => $info,
64                         '$entries' => $r,
65                 ]);
66         }
67 }