Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed

- Fix mobile devices duplication during mobile sync
- Fix leftover data (profile rights and config values) after plugin uninstall

## [3.2.2] - 2026-08-03
Expand Down
6 changes: 3 additions & 3 deletions inc/mobilesync.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,12 @@ public static function discover(): int

$imported = [];
$iterator = $DB->request([
'SELECT' => ['udid'],
'SELECT' => ['jamf_items_id'],
'FROM' => 'glpi_plugin_jamf_devices',
'WHERE' => ['jamf_type' => static::$jamf_itemtype],
]);
foreach ($iterator as $data) {
$imported[] = $data['udid'];
$imported[] = (int) $data['jamf_items_id'];
}

$pending_iterator = $DB->request([
Expand All @@ -742,7 +742,7 @@ public static function discover(): int

$config = Config::getConfigurationValues('plugin:Jamf');
foreach ($jamf_devices as $jamf_device) {
if (!in_array($jamf_device['id'], $imported, true)) {
if (!in_array((int) $jamf_device['id'], $imported, true)) {
$itemtype = str_contains((string) $jamf_device['model_identifier'], 'iPhone') ? 'Phone' : 'Computer';
if (isset($config['autoimport']) && $config['autoimport']) {
try {
Expand Down
26 changes: 26 additions & 0 deletions tests/units/PluginJamfMobileSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,32 @@ public function testImportAsPhone()
$this->assertEquals('1aec6610a9401d2cc47cb55e1a2f7b500ab75864', $ext_field['value']);
}

public function testDiscoverSkipsAlreadyImportedDevices()
{
/** @var DBmysql $DB */
global $DB;

// Ensure the device is imported (may already be done by a previous test)
PluginJamfMobileTestSync::import('Phone', 5, false);
$this->assertGreaterThan(0, countElementsInTable('glpi_plugin_jamf_devices', [
'jamf_type' => 'MobileDevice',
'jamf_items_id' => 5,
]));

$DB->delete(PluginJamfImport::getTable(), ['jamf_type' => 'MobileDevice']);
PluginJamfMobileTestSync::discover();

// The imported device must not be queued again for import
$this->assertEquals(0, countElementsInTable(PluginJamfImport::getTable(), [
'jamf_type' => 'MobileDevice',
'jamf_items_id' => 5,
]));
// The other devices are still discovered
$this->assertEquals(5, countElementsInTable(PluginJamfImport::getTable(), [
'jamf_type' => 'MobileDevice',
]));
}

public static function deviceSyncEnginesProvider()
{
$engines = PluginJamfSync::getDeviceSyncEngines();
Expand Down
Loading