-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_import.php
More file actions
73 lines (63 loc) · 2.83 KB
/
validate_import.php
File metadata and controls
73 lines (63 loc) · 2.83 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
<?php
// Simple validation of the import functionality
$testFile = __DIR__ . '/../php-vitexsoftware-multiflexi-core/tests/test.credential-type.json';
echo "MultiFlexi CLI Credential Type Import Validation\n";
echo "===============================================\n\n";
if (file_exists($testFile)) {
echo "✓ Test file found: $testFile\n";
$jsonContent = file_get_contents($testFile);
$data = json_decode($jsonContent, true);
if (json_last_error() === JSON_ERROR_NONE) {
echo "✓ JSON file is valid\n";
// Check required fields
$requiredFields = ['id', 'uuid', 'name', 'description', 'fields'];
$missing = [];
foreach ($requiredFields as $field) {
if (!isset($data[$field])) {
$missing[] = $field;
}
}
if (empty($missing)) {
echo "✓ All required fields present:\n";
echo " - ID: " . $data['id'] . "\n";
echo " - UUID: " . $data['uuid'] . "\n";
echo " - Code: " . ($data['code'] ?? 'N/A') . "\n";
echo " - Name: " . (is_array($data['name']) ? json_encode($data['name']) : $data['name']) . "\n";
echo " - Fields count: " . count($data['fields']) . "\n";
echo "\n✓ Field validation:\n";
foreach ($data['fields'] as $i => $field) {
$fieldRequired = ['keyword', 'name', 'type'];
$fieldMissing = [];
foreach ($fieldRequired as $req) {
if (!isset($field[$req])) {
$fieldMissing[] = $req;
}
}
if (empty($fieldMissing)) {
echo " - Field $i: " . $field['keyword'] . " (" . $field['type'] . ") ✓\n";
} else {
echo " - Field $i: Missing " . implode(', ', $fieldMissing) . " ✗\n";
}
}
} else {
echo "✗ Missing required fields: " . implode(', ', $missing) . "\n";
}
} else {
echo "✗ Invalid JSON: " . json_last_error_msg() . "\n";
}
} else {
echo "✗ Test file not found: $testFile\n";
}
echo "\n" . str_repeat("=", 50) . "\n";
echo "IMPORT FUNCTIONALITY ADDED\n";
echo str_repeat("=", 50) . "\n";
echo "The CredentialTypeCommand has been updated with:\n";
echo " • New 'import' action\n";
echo " • --file option for specifying JSON file\n";
echo " • JSON validation against schema\n";
echo " • Duplicate checking by UUID and ID\n";
echo " • Database insertion with proper field encoding\n";
echo " • Error handling and status reporting\n\n";
echo "Usage:\n";
echo " multiflexi-cli credtype import --file /path/to/credential-type.json\n";
echo " multiflexi-cli credtype import --file /path/to/credential-type.json --format json\n\n";