From: Jeroen De Meerleer <me@jeroened.be>
Date: Sat, 14 Jul 2018 18:01:17 +0000 (+0200)
Subject: Add worker queue details (#5375)
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=678efab1c9105c9a1a4098a42c4a7bc7ae0dfabc;p=friendica.git

Add worker queue details (#5375)

* Added Worker queue page

* Added worker queue template

* Added translation strings

* Added en-US translation

* #TGWHT: Thank god we have Typo

* Where donkey == true

* Added in to menu correctly

* Updated link in summary page

* Updated link on summary page for frio theme

* Updated q() to dba::select()

* Revert "Added translation strings"

This reverts commit f1f3694a2412f69c39559650759b6483013f0f17.

* Revert "Added en-US translation"

This reverts commit 61777489e3add56e81c4f976599d8a2e025265cb.
---

diff --git a/mod/admin.php b/mod/admin.php
index 30aeb27f53..54b7e6504e 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -189,7 +189,8 @@ function admin_content(App $a)
 			'tos'          => ["admin/tos/"         , L10n::t("Terms of Service")     , "tos"] ]],
 		'database' => [ L10n::t('Database'), [
 			'dbsync'       => ["admin/dbsync/"      , L10n::t('DB updates')           , "dbsync"],
-			'queue'        => ["admin/queue/"       , L10n::t('Inspect Queue')        , "queue"], ]],
+			'queue'        => ["admin/queue/"       , L10n::t('Inspect Queue')        , "queue"],
+			'workerqueue'  => ["admin/workerqueue/" , L10n::t('Inspect worker Queue') , "workerqueue"] ]],
 		'tools' => [ L10n::t('Tools'), [
 			'contactblock' => ["admin/contactblock/", L10n::t('Contact Blocklist')    , "contactblock"],
 			'blocklist'    => ["admin/blocklist/"   , L10n::t('Server Blocklist')     , "blocklist"],
@@ -258,6 +259,9 @@ function admin_content(App $a)
 			case 'queue':
 				$o = admin_page_queue($a);
 				break;
+			case 'workerqueue':
+				$o = admin_page_workerqueue($a);
+				break;
 			case 'federation':
 				$o = admin_page_federation($a);
 				break;
@@ -729,7 +733,7 @@ function admin_page_federation(App $a)
  * @brief Admin Inspect Queue Page
  *
  * Generates a page for the admin to have a look into the current queue of
- * postings that are not deliverabke. Shown are the name and url of the
+ * postings that are not deliverable. Shown are the name and url of the
  * recipient, the delivery network and the dates when the posting was generated
  * and the last time tried to deliver the posting.
  *
@@ -762,6 +766,37 @@ function admin_page_queue(App $a)
 	]);
 }
 
+/**
+ * @brief Admin Inspect Worker Queue Page
+ *
+ * Generates a page for the admin to have a look into the current queue of
+ * worker jobs. Shown are the parameters for the job and its priority.
+ *
+ * The returned string holds the content of the page.
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_workerqueue(App $a)
+{
+	// get jobs from the workerqueue table
+	$statement = dba::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]);
+	$r = dba::inArray($statement);
+
+	$t = get_markup_template('admin/workerqueue.tpl');
+	return replace_macros($t, [
+		'$title' => L10n::t('Administration'),
+		'$page' => L10n::t('Inspect Worker Queue'),
+		'$count' => count($r),
+		'$id_header' => L10n::t('ID'),
+		'$param_header' => L10n::t('Job Parameters'),
+		'$created_header' => L10n::t('Created'),
+		'$prio_header' => L10n::t('Priority'),
+		'$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.'),
+		'$entries' => $r,
+	]);
+}
+
 /**
  * @brief Admin Summary Page
  *
diff --git a/view/templates/admin/summary.tpl b/view/templates/admin/summary.tpl
index 6b1ebe40ea..8929cfbecd 100644
--- a/view/templates/admin/summary.tpl
+++ b/view/templates/admin/summary.tpl
@@ -11,7 +11,7 @@
 
 	<dl>
 		<dt>{{$queues.label}}</dt>
-		<dd><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - {{$queues.workerq}}</dd>
+		<dd><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></dd>
 	</dl>
 	<dl>
 		<dt>{{$pending.0}}</dt>
diff --git a/view/templates/admin/workerqueue.tpl b/view/templates/admin/workerqueue.tpl
new file mode 100644
index 0000000000..5bab58a5e9
--- /dev/null
+++ b/view/templates/admin/workerqueue.tpl
@@ -0,0 +1,21 @@
+<div id='adminpage'>
+	<h1>{{$title}} - {{$page}} ({{$count}})</h1>
+	
+	<p>{{$info}}</p>
+	<table>
+		<tr>
+			<th>{{$id_header}}</th>
+			<th>{{$param_header}}</th>
+			<th>{{$created_header}}</th>
+			<th>{{$prio_header}}</th>
+		</tr>
+		{{foreach $entries as $e}}
+		<tr>
+			<td>{{$e.id}}</td>
+			<td>{{$e.parameter}}</td>
+			<td>{{$e.created}}</td>
+			<td>{{$e.priority}}</td>
+		</tr>
+		{{/foreach}}
+	</table>
+</div>
diff --git a/view/theme/frio/templates/admin/summary.tpl b/view/theme/frio/templates/admin/summary.tpl
index 26c9991756..30eca8dc0f 100644
--- a/view/theme/frio/templates/admin/summary.tpl
+++ b/view/theme/frio/templates/admin/summary.tpl
@@ -14,7 +14,7 @@
 		{{* The work queues short statistic. *}}
 		<div id="admin-summary-queues" class="col-lg-12 col-md-12 col-sm-12 col-xs-12 admin-summary">
 			<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 admin-summary-label-name text-muted">{{$queues.label}}</div>
-			<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - {{$queues.workerq}}</div>
+			<div class="col-lg-8 col-md-8 col-sm-8 col-xs-12 admin-summary-entry"><a href="{{$baseurl}}/admin/queue">{{$queues.queue}}</a> - <a href="{{$baseurl}}/admin/workerqueue">{{$queues.workerq}}</a></div>
 		</div>
 
 		{{* Number of pending registrations. *}}