]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Queue.php
Merge pull request #8277 from MrPetovan/task/8251-use-about-for-pdesc
[friendica.git] / src / Module / Admin / Queue.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin;
23
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Arrays;
29 use Friendica\Util\DateTimeFormat;
30
31 /**
32  * Admin Inspect Queue Page
33  *
34  * Generates a page for the admin to have a look into the current queue of
35  * worker jobs. Shown are the parameters for the job and its priority.
36  *
37  * @return string
38  */
39 class Queue extends BaseAdmin
40 {
41         public static function content(array $parameters = [])
42         {
43                 parent::content($parameters);
44
45                 $a = DI::app();
46
47                 // @TODO: Replace with parameter from router
48                 $deferred = $a->argc > 2 && $a->argv[2] == 'deferred';
49
50                 // get jobs from the workerqueue table
51                 if ($deferred) {
52                         $condition = ["NOT `done` AND `retrial` > ?", 0];
53                         $sub_title = DI::l10n()->t('Inspect Deferred Worker Queue');
54                         $info = DI::l10n()->t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
55                 } else {
56                         $condition = ["NOT `done` AND `retrial` = ?", 0];
57                         $sub_title = DI::l10n()->t('Inspect Worker Queue');
58                         $info = DI::l10n()->t('This page lists the currently queued worker jobs. These jobs are handled by the worker cronjob you\'ve set up during install.');
59                 }
60
61                 // @TODO Move to Model\WorkerQueue::getEntries()
62                 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
63
64                 $r = [];
65                 while ($entry = DBA::fetch($entries)) {
66                         // fix GH-5469. ref: src/Core/Worker.php:217
67                         $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
68                         $entry['created'] = DateTimeFormat::local($entry['created']);
69                         $r[] = $entry;
70                 }
71                 DBA::close($entries);
72
73                 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
74                 return Renderer::replaceMacros($t, [
75                         '$title' => DI::l10n()->t('Administration'),
76                         '$page' => $sub_title,
77                         '$count' => count($r),
78                         '$id_header' => DI::l10n()->t('ID'),
79                         '$param_header' => DI::l10n()->t('Job Parameters'),
80                         '$created_header' => DI::l10n()->t('Created'),
81                         '$prio_header' => DI::l10n()->t('Priority'),
82                         '$info' => $info,
83                         '$entries' => $r,
84                 ]);
85         }
86 }