]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Queue.php
748a12a6a6332eee33a64e1733263545afc57a58
[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()
23         {
24                 parent::content();
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 `next_try` > ?", DateTimeFormat::utcNow()];
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 `next_try` < ?", DateTimeFormat::utcNow()];
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                 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['order' => ['priority']]);
43
44                 $r = [];
45                 while ($entry = DBA::fetch($entries)) {
46                         // fix GH-5469. ref: src/Core/Worker.php:217
47                         $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
48                         $entry['created'] = DateTimeFormat::local($entry['created']);
49                         $r[] = $entry;
50                 }
51                 DBA::close($entries);
52
53                 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
54                 return Renderer::replaceMacros($t, [
55                         '$title' => L10n::t('Administration'),
56                         '$page' => $sub_title,
57                         '$count' => count($r),
58                         '$id_header' => L10n::t('ID'),
59                         '$param_header' => L10n::t('Job Parameters'),
60                         '$created_header' => L10n::t('Created'),
61                         '$prio_header' => L10n::t('Priority'),
62                         '$info' => $info,
63                         '$entries' => $r,
64                 ]);
65         }
66 }