-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-magic-mapper-import.php
More file actions
105 lines (84 loc) · 5.15 KB
/
test-magic-mapper-import.php
File metadata and controls
105 lines (84 loc) · 5.15 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env php
<?php
/**
* Test script for importing the magic mapper version of softwarecatalogus_register.json
*
* This script tests the import of registers with magic mapper configuration.
* It should be run from within the Nextcloud container as user www-data.
*
* Usage:
* docker exec -u 33 nextcloud php /var/www/html/custom_apps/softwarecatalog/test-magic-mapper-import.php
*/
require_once __DIR__ . '/../../lib/base.php';
use OCA\OpenRegister\Service\ConfigurationService;
use OCP\Server;
try {
echo "╔══════════════════════════════════════════════════════════════════════════════╗\n";
echo "║ Magic Mapper Register Import Test ║\n";
echo "╚══════════════════════════════════════════════════════════════════════════════╝\n\n";
// Load the magic mapper JSON file.
$jsonPath = __DIR__ . '/lib/Settings/softwarecatalogus_register_magic.json';
echo "📂 Loading JSON from: $jsonPath\n";
if (!file_exists($jsonPath)) {
throw new Exception("JSON file not found: $jsonPath");
}
$jsonContent = file_get_contents($jsonPath);
$data = json_decode($jsonContent, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("Failed to parse JSON: " . json_last_error_msg());
}
echo "✓ JSON loaded successfully\n\n";
// Get the configuration service.
$configService = Server::get(ConfigurationService::class);
// Import the configuration.
echo "⚙️ Starting import...\n";
$result = $configService->importFromApp(
appId: 'softwarecatalog',
data: $data,
version: $data['info']['version'] ?? '2.0.1-magic',
force: true // Force import for testing
);
echo "✓ Import completed!\n\n";
// Display results.
echo "═══════════════════════════════════════════════════════════════════════════════\n";
echo "Import Results:\n";
echo "═══════════════════════════════════════════════════════════════════════════════\n\n";
if (!empty($result['registers'])) {
echo "📋 Registers imported: " . count($result['registers']) . "\n";
foreach ($result['registers'] as $register) {
echo " • " . $register->getTitle() . " (slug: " . $register->getSlug() . ")\n";
// Check if configuration was set.
$config = $register->getConfiguration();
if ($config && isset($config['schemas'])) {
echo " 🔮 Magic Mapper enabled for " . count($config['schemas']) . " schemas:\n";
foreach ($config['schemas'] as $schemaSlug => $schemaConfig) {
if ($schemaConfig['magicMapping'] ?? false) {
echo " ✓ " . $schemaSlug . "\n";
}
}
} else {
echo " ⚠️ No magic mapper configuration found\n";
}
echo "\n";
}
}
if (!empty($result['schemas'])) {
echo "\n📝 Schemas imported: " . count($result['schemas']) . "\n";
}
if (!empty($result['objects'])) {
echo "\n📦 Objects imported: " . count($result['objects']) . "\n";
}
echo "\n";
echo "╔══════════════════════════════════════════════════════════════════════════════╗\n";
echo "║ ✅ Test completed successfully! ║\n";
echo "╚══════════════════════════════════════════════════════════════════════════════╝\n";
exit(0);
} catch (Exception $e) {
echo "\n";
echo "╔══════════════════════════════════════════════════════════════════════════════╗\n";
echo "║ ❌ Test failed! ║\n";
echo "╚══════════════════════════════════════════════════════════════════════════════╝\n\n";
echo "Error: " . $e->getMessage() . "\n";
echo "Trace:\n" . $e->getTraceAsString() . "\n";
exit(1);
}