forked from cconard96/jamf
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmerge.php
More file actions
109 lines (96 loc) · 3.59 KB
/
merge.php
File metadata and controls
109 lines (96 loc) · 3.59 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
105
106
107
108
109
<?php
/**
* -------------------------------------------------------------------------
* JAMF plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of JAMF plugin for GLPI.
*
* JAMF plugin for GLPI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* JAMF plugin for GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JAMF plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2024-2024 by Teclib'
* @copyright Copyright (C) 2019-2024 by Curtis Conard
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/jamf
* -------------------------------------------------------------------------
*/
use Glpi\Application\View\TemplateRenderer;
use Glpi\Toolbox\Sanitizer;
include('../../../inc/includes.php');
$plugin = new Plugin();
if (!$plugin->isActivated('jamf')) {
Html::displayNotFoundError();
}
Session::checkRight('plugin_jamf_mobiledevice', CREATE);
Html::header('Jamf Plugin', '', 'tools', 'PluginJamfMenu', 'import');
global $DB, $CFG_GLPI;
$start = $_GET['start'] ?? 0;
$import = new PluginJamfImport();
$importcount = countElementsInTable(PluginJamfImport::getTable());
$pending = iterator_to_array($DB->request([
'FROM' => PluginJamfImport::getTable(),
'START' => $start,
'LIMIT' => $_SESSION['glpilist_limit'],
]));
$linked_devices = $DB->request([
'SELECT' => ['jamf_type', 'itemtype', 'items_id'],
'FROM' => 'glpi_plugin_jamf_devices',
]);
$linked = [];
foreach ($linked_devices as $data) {
$linked[$data['itemtype']][] = $data;
}
$supported_glpi_types = [
'Computer' => PluginJamfComputerSync::getSupportedGlpiItemtypes(),
'MobileDevice' => PluginJamfMobileSync::getSupportedGlpiItemtypes()
];
foreach ($pending as &$data) {
$queries = [];
foreach ($supported_glpi_types[$data['jamf_type']] as $type) {
$queries[] = [
'SELECT' => [
new QueryExpression($DB::quoteValue($type) . ' AS ' . $DB::quoteName('itemtype')),
'id'
],
'FROM' => $type::getTable(),
'WHERE' => [
'OR' => [
'uuid' => $data['udid'],
'name' => Sanitizer::sanitize($data['name'])
],
'is_deleted' => 0,
'is_template' => 0
],
'ORDER' => new QueryExpression("CASE WHEN uuid='" . $data['udid'] . "' THEN 0 ELSE 1 END"),
'LIMIT' => 1
];
}
$guesses = $DB->request(new QueryUnion($queries));
$data['guessed_item'] = null;
foreach ($guesses as $guess) {
$data['guessed_item'][$guess['itemtype']] = $guess['id'];
}
}
TemplateRenderer::getInstance()->display('@jamf/merge.html.twig', [
'pending' => $pending,
'total_count' => $importcount,
'linked' => $linked,
'supported_glpi_types' => array_map(
static fn ($ts) => array_combine($ts, array_map(static fn ($t) => $t::getTypeName(1), $ts)),
$supported_glpi_types
)
]);
Html::footer();