Upload via GUI (10 Dateien)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS plugin_beispiel_log (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
ticket_id INT NOT NULL,
|
||||
event VARCHAR(40) NOT NULL,
|
||||
created_at DATETIME NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS plugin_beispiel_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ticket_id INT NOT NULL,
|
||||
event VARCHAR(40) NOT NULL,
|
||||
created_at DATETIME NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// Seite des Beispiel-Plugins. Verfügbar: $staff, $pdo.
|
||||
$rows = $pdo->query('SELECT ticket_id, event, created_at FROM plugin_beispiel_log ORDER BY id DESC LIMIT 50')->fetchAll();
|
||||
?>
|
||||
<h1>Ticket-Protokoll</h1>
|
||||
<p class="muted">Letzter Plugin-Cron: <?= e(plugin_setting('beispiel', 'last_cron', 'noch nie')) ?></p>
|
||||
<div class="card"><table>
|
||||
<thead><tr><th>Ticket</th><th>Ereignis</th><th>Zeit</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($rows as $r): ?><tr><td>#<?= (int) $r['ticket_id'] ?></td><td><?= e($r['event']) ?></td><td><?= e($r['created_at']) ?></td></tr><?php endforeach; ?>
|
||||
<?php if (!$rows): ?><tr><td colspan="3" class="muted">Noch keine Ereignisse.</td></tr><?php endif; ?>
|
||||
</tbody>
|
||||
</table></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"slug": "beispiel",
|
||||
"name": "Beispiel: Ticket-Protokoll",
|
||||
"version": "1.0.0",
|
||||
"description": "Demonstriert Hooks, Menüpunkt, Seite, API-Endpunkt, Ticket-Seitenleiste, Einstellungen und Datenbank-Migration.",
|
||||
"author": "DeskHub",
|
||||
"requires": "1.0.0",
|
||||
"permissions": ["hooks.tickets", "hooks.cron", "ui.menu", "ui.sidebar", "api.endpoints", "db.migrations"]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// Beispiel-Plugin: protokolliert Ticket-Ereignisse in einer eigenen Tabelle.
|
||||
// Wird beim Aktivieren geladen; hier werden nur Erweiterungen registriert.
|
||||
|
||||
plugin_add_hook('ticket.created', function (array $e) {
|
||||
$pdo = get_db();
|
||||
$pdo->prepare('INSERT INTO plugin_beispiel_log (ticket_id, event, created_at) VALUES (?,?,?)')->execute([$e['ticketId'], 'created', db_now()]);
|
||||
});
|
||||
plugin_add_hook('ticket.status_changed', function (array $e) {
|
||||
$pdo = get_db();
|
||||
$pdo->prepare('INSERT INTO plugin_beispiel_log (ticket_id, event, created_at) VALUES (?,?,?)')->execute([$e['ticketId'], 'status_changed', db_now()]);
|
||||
});
|
||||
|
||||
// Baustein in der Ticketansicht (Plugins liefern fertiges HTML und müssen Ausgaben selbst escapen)
|
||||
plugin_add_filter('ticket.view.sidebar', function (string $html, array $ctx) {
|
||||
$stmt = get_db()->prepare('SELECT COUNT(*) FROM plugin_beispiel_log WHERE ticket_id = ?');
|
||||
$stmt->execute([$ctx['ticketId']]);
|
||||
return $html . '<div class="card" style="margin-top:16px;padding:14px 16px"><strong>Protokoll-Plugin</strong><br>'
|
||||
. (int) $stmt->fetchColumn() . ' Ereignis(se) zu diesem Ticket</div>';
|
||||
});
|
||||
|
||||
plugin_register_menu('Ticket-Protokoll', 'log');
|
||||
|
||||
plugin_register_api('count', function (array $staff, array $request): array {
|
||||
return ['count' => (int) get_db()->query('SELECT COUNT(*) FROM plugin_beispiel_log')->fetchColumn()];
|
||||
});
|
||||
|
||||
plugin_add_hook('cron.run', function () {
|
||||
plugin_set_setting('beispiel', 'last_cron', db_now());
|
||||
});
|
||||
|
||||
// Aufräumen beim Entfernen mit "Daten löschen"
|
||||
plugin_add_hook('plugin.uninstall.beispiel', function () {
|
||||
get_db()->exec('DROP TABLE IF EXISTS plugin_beispiel_log');
|
||||
});
|
||||
Reference in New Issue
Block a user