Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
From the thor#1 plan: each reporter (gandalf, hwmonDaemon, thor) decides
what "the same problem" is, and Tinker enforces it.
- dedup_key on create_ticket_api.php (scope:subject:kind, A-Za-z0-9_.:-,
case-sensitive). The hash becomes sha256("key:" + key) and the title is
not looked at; an invalid key is a 400. Keyless callers hash exactly as
before (checked over every prod title).
- Recurrence window for every reporter, keyed or not: a match on a ticket
closed under AUTO_REOPEN_WINDOW_DAYS (7) ago reopens it as before
(subject to the Workflow Designer); an older one gets a new ticket that
takes over the dedup slot (tickets.hash stays UNIQUE, the old ticket
gives it up), carries the key, records recurrence_of, is linked
relates_to, and gets a history comment. action: new_recurrence.
- GET api/tickets_api.php?dedup_key= returns the newest ticket with that
key plus its recurrence chain; ?source= filters the list.
- New api/ticket_link_api.php (link/unlink, read_write) through
DependencyService::link()/unlink(), now shared with MCP
link_tickets/unlink_tickets; audit rows record the key name.
- tickets.source records the API key name. Shown as the creator instead of
"System" on the dashboard and ticket page, a Source filter in the
sidebar, source in MCP results and a search_tickets filter. Comments the
create API writes name the reporter instead of a hard-coded
"hwmonDaemon", and system-linked comments display that name.
- Migration 008 (dedup_key, source, recurrence_of). Scripts:
backfill_ticket_source.php (pre-#123 tickets, where certain) and
backfill_dedup_keys.php (mapping file supplied by the app).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.2 KiB
PHP
108 lines
3.2 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
|
|
/**
|
|
* Fill in tickets.source for tickets the API created before #123.
|
|
*
|
|
* Since #123, create_ticket_api.php records the API key name (gandalf,
|
|
* hwmonDaemon, thor) as the ticket's source. Older API tickets only show the
|
|
* "system" user. This script sets source where the reporter is certain and
|
|
* leaves the rest NULL:
|
|
*
|
|
* - hwmonDaemon: description uses its box-drawing layout
|
|
* - gandalf: [auto] title and Gandalf's own footer
|
|
* ("automatically by Gandalf" / "from the Gandalf monitor")
|
|
*
|
|
* Only tickets created by the system user with no source yet are touched.
|
|
* Each change writes an audit_log row. Safe to re-run.
|
|
*
|
|
* php scripts/backfill_ticket_source.php --dry-run # report only
|
|
* php scripts/backfill_ticket_source.php
|
|
*/
|
|
|
|
if (php_sapi_name() !== 'cli') {
|
|
http_response_code(403);
|
|
exit('CLI access only');
|
|
}
|
|
|
|
require_once dirname(__DIR__) . '/config/config.php';
|
|
require_once dirname(__DIR__) . '/helpers/Database.php';
|
|
require_once dirname(__DIR__) . '/models/UserModel.php';
|
|
require_once dirname(__DIR__) . '/models/AuditLogModel.php';
|
|
|
|
$dryRun = in_array('--dry-run', $argv, true);
|
|
$conn = Database::getConnection();
|
|
|
|
$system = (new UserModel($conn))->getSystemUser();
|
|
if (!$system) {
|
|
fwrite(STDERR, "No system user found\n");
|
|
exit(1);
|
|
}
|
|
$systemId = (int)$system['user_id'];
|
|
|
|
/** The reporter a ticket certainly came from, or null. */
|
|
function detectSource(array $t): ?string
|
|
{
|
|
$title = (string)$t['title'];
|
|
$description = (string)$t['description'];
|
|
if (preg_match('/[┏┃┗━┣]/u', $description)) {
|
|
return 'hwmonDaemon';
|
|
}
|
|
if (
|
|
stripos($title, '[auto]') !== false
|
|
&& preg_match('/automatically by Gandalf|from the Gandalf monitor/i', $description)
|
|
) {
|
|
return 'gandalf';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
$stmt = $conn->prepare(
|
|
"SELECT ticket_id, title, description FROM tickets WHERE created_by = ? AND source IS NULL ORDER BY ticket_id"
|
|
);
|
|
$stmt->bind_param('i', $systemId);
|
|
$stmt->execute();
|
|
$rows = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
|
$stmt->close();
|
|
|
|
$update = $conn->prepare("UPDATE tickets SET source = ? WHERE ticket_id = ? AND source IS NULL");
|
|
$audit = new AuditLogModel($conn);
|
|
$counts = [];
|
|
$unknown = [];
|
|
|
|
foreach ($rows as $row) {
|
|
$source = detectSource($row);
|
|
if ($source === null) {
|
|
$unknown[] = $row;
|
|
continue;
|
|
}
|
|
$counts[$source] = ($counts[$source] ?? 0) + 1;
|
|
if ($dryRun) {
|
|
continue;
|
|
}
|
|
$update->bind_param('ss', $source, $row['ticket_id']);
|
|
$update->execute();
|
|
if ($update->affected_rows > 0) {
|
|
$audit->log($systemId, 'update', 'ticket', $row['ticket_id'], [
|
|
'source' => ['from' => null, 'to' => $source],
|
|
'reason' => 'source backfilled from the description (tinker_tickets#123)',
|
|
]);
|
|
}
|
|
}
|
|
|
|
foreach ($unknown as $row) {
|
|
echo 'left unset ' . $row['ticket_id'] . ' ' . mb_substr((string)$row['title'], 0, 100) . "\n";
|
|
}
|
|
ksort($counts);
|
|
$summary = [];
|
|
foreach ($counts as $source => $n) {
|
|
$summary[] = "$n $source";
|
|
}
|
|
printf(
|
|
"%s%s %s, %d left unset\n",
|
|
$dryRun ? '[dry run] ' : '',
|
|
$dryRun ? 'would set' : 'set',
|
|
$summary ? implode(', ', $summary) : 'none',
|
|
count($unknown)
|
|
);
|