]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Queue.php
post/thread views are renamed, search bugs fixed
[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                 $status = $parameters['status'] ?? '';
46
47                 // get jobs from the workerqueue table
48                 if ($status == 'deferred') {
49                         $condition = ["NOT `done` AND `retrial` > ?", 0];
50                         $sub_title = DI::l10n()->t('Inspect Deferred Worker Queue');
51                         $info = DI::l10n()->t("This page lists the deferred worker jobs. This are jobs that couldn't be executed at the first time.");
52                 } else {
53                         $condition = ["NOT `done` AND `retrial` = ?", 0];
54                         $sub_title = DI::l10n()->t('Inspect Worker Queue');
55                         $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.');
56                 }
57
58                 // @TODO Move to Model\WorkerQueue::getEntries()
59                 $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], $condition, ['limit' => 999, 'order' => ['created']]);
60
61                 $r = [];
62                 while ($entry = DBA::fetch($entries)) {
63                         // fix GH-5469. ref: src/Core/Worker.php:217
64                         $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
65                         $entry['created'] = DateTimeFormat::local($entry['created']);
66                         $r[] = $entry;
67                 }
68                 DBA::close($entries);
69
70                 $t = Renderer::getMarkupTemplate('admin/queue.tpl');
71                 return Renderer::replaceMacros($t, [
72                         '$title' => DI::l10n()->t('Administration'),
73                         '$page' => $sub_title,
74                         '$count' => count($r),
75                         '$id_header' => DI::l10n()->t('ID'),
76                         '$param_header' => DI::l10n()->t('Job Parameters'),
77                         '$created_header' => DI::l10n()->t('Created'),
78                         '$prio_header' => DI::l10n()->t('Priority'),
79                         '$info' => $info,
80                         '$entries' => $r,
81                 ]);
82         }
83 }