-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportTeamConfigurationCommand.php
More file actions
86 lines (67 loc) · 2.48 KB
/
Copy pathExportTeamConfigurationCommand.php
File metadata and controls
86 lines (67 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace App\Console\Commands;
use App\Actions\Teams\ExportTeamConfiguration;
use App\Models\Team;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
class ExportTeamConfigurationCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'team:export-configuration
{team_ulid : The ULID of the team to export}
{--output= : Output file path (optional)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Export team print infrastructure configuration to JSON';
/**
* Execute the console command.
*
* @param \App\Actions\Teams\ExportTeamConfiguration $exporter
* @return int
*/
public function handle(ExportTeamConfiguration $exporter): int
{
$teamUlid = $this->argument('team_ulid');
// Find team by ULID
$team = Team::where('ulid', $teamUlid)->first();
if (! $team) {
$this->error("Team with ULID '{$teamUlid}' not found.");
return self::FAILURE;
}
if ($team->personal_team) {
$this->error('Cannot export personal team configuration.');
return self::FAILURE;
}
$this->info("Exporting configuration for team: {$team->name}");
// Export the configuration
$json = $exporter->exportAsJson($team);
// Determine output path
$outputPath = $this->option('output');
if (! $outputPath) {
$outputPath = storage_path('app/'.$exporter->generateFilename($team));
}
// Ensure directory exists
$directory = dirname($outputPath);
if (! File::isDirectory($directory)) {
File::makeDirectory($directory, 0755, true);
}
// Write to file
File::put($outputPath, $json);
$this->info("Configuration exported successfully to: {$outputPath}");
// Show statistics
$data = json_decode($json, true);
$this->newLine();
$this->line('<fg=cyan>Export Statistics:</>');
$this->line(' Print Servers: '.count($data['print_servers'] ?? []));
$this->line(' Printers: '.collect($data['print_servers'] ?? [])->sum(fn ($server) => count($server['printers'] ?? [])));
$this->line(' Client Applications: '.count($data['client_applications'] ?? []));
return self::SUCCESS;
}
}