From 6cbfad5a42fa5ba175ec5e13f071ff8e6c08ffd5 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Thu, 24 Sep 2026 09:20:55 +0200 Subject: [PATCH 1/2] fix(46499): mobile devices duplications --- inc/mobilesync.class.php | 6 +++--- tests/units/PluginJamfMobileSync.php | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/inc/mobilesync.class.php b/inc/mobilesync.class.php index c32bf60..091c840 100644 --- a/inc/mobilesync.class.php +++ b/inc/mobilesync.class.php @@ -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([ @@ -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 { diff --git a/tests/units/PluginJamfMobileSync.php b/tests/units/PluginJamfMobileSync.php index 615e8df..7d9bd33 100644 --- a/tests/units/PluginJamfMobileSync.php +++ b/tests/units/PluginJamfMobileSync.php @@ -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(); From 53313c3fb2ad1a4c6ce3775cfc87def5f7d5295a Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Thu, 24 Sep 2026 09:22:21 +0200 Subject: [PATCH 2/2] chore(46499): changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350398e..4260b1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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