added support for legacy tickets, fixed switching of modes and also style updates

This commit is contained in:
Mark Gregory
2026-09-28 15:21:32 +01:00
parent fd6646c1ee
commit 0fb4223bfc
30 changed files with 162 additions and 186 deletions
@@ -16,6 +16,7 @@ use Throwable;
final class ImportLegacyHelpdeskCommand extends Command
{
protected $signature = 'helpdesk:import-legacy {--connection= : Laravel database connection containing the old tickets tables} {--fresh : Clear previously imported legacy records first}';
protected $description = 'Import the old Helpdesk tickets and categories into the read-only Legacy System';
public function handle(): int
@@ -33,6 +34,7 @@ final class ImportLegacyHelpdeskCommand extends Command
foreach (['tickets', 'tickets_categories'] as $table) {
if (! $schema->hasTable($table)) {
$this->error("Source table {$table} was not found on connection [{$connectionName}].");
return self::FAILURE;
}
}
@@ -49,6 +51,7 @@ final class ImportLegacyHelpdeskCommand extends Command
$this->refreshCategoryCounts();
$this->info(sprintf('Legacy import complete: %d tickets, %d categories, %d comments.', LegacyTicket::count(), LegacyCategory::count(), LegacyComment::count()));
return self::SUCCESS;
}
@@ -72,7 +75,7 @@ final class ImportLegacyHelpdeskCommand extends Command
'user' => $this->lookup($source, $schema, 'users'),
];
$source->table('tickets')->orderBy('id')->chunk(250, function ($rows) use ($columns, $lookups): void {
$source->table('tickets')->orderBy('id')->chunk(250, function ($rows) use ($lookups): void {
foreach ($rows as $row) {
$data = (array) $row;
LegacyTicket::updateOrCreate(['legacy_id' => $row->id], [
@@ -99,7 +102,9 @@ final class ImportLegacyHelpdeskCommand extends Command
private function importComments(ConnectionInterface $source, $schema): void
{
if (! $schema->hasTable('tickets_comments')) return;
if (! $schema->hasTable('tickets_comments')) {
return;
}
$users = $this->lookup($source, $schema, 'users');
$source->table('tickets_comments')->orderBy('id')->chunk(500, function ($rows) use ($users): void {
foreach ($rows as $row) {
@@ -118,11 +123,19 @@ final class ImportLegacyHelpdeskCommand extends Command
private function lookup(ConnectionInterface $source, $schema, string $table): array
{
if (! $schema->hasTable($table)) return [];
if (! $schema->hasTable($table)) {
return [];
}
$columns = $schema->getColumnListing($table);
$nameColumn = in_array('name', $columns, true) ? 'name' : (in_array('username', $columns, true) ? 'username' : null);
if ($nameColumn === null) return [];
try { return $source->table($table)->pluck($nameColumn, 'id')->map(fn ($v) => (string) $v)->all(); } catch (Throwable) { return []; }
if ($nameColumn === null) {
return [];
}
try {
return $source->table($table)->pluck($nameColumn, 'id')->map(fn ($v) => (string) $v)->all();
} catch (Throwable) {
return [];
}
}
private function refreshCategoryCounts(): void