diff --git a/inc/computersync.class.php b/inc/computersync.class.php index d5666a3..e19f5c7 100644 --- a/inc/computersync.class.php +++ b/inc/computersync.class.php @@ -540,6 +540,7 @@ public static function discover(): bool $imported[] = $data['jamf_items_id']; } $pending_iterator = $DB->request([ + 'SELECT' => ['jamf_items_id'], 'FROM' => 'glpi_plugin_jamf_imports', 'WHERE' => [ 'jamf_type' => 'Computer' @@ -547,7 +548,7 @@ public static function discover(): bool ]); $pending_import = []; foreach ($pending_iterator as $data) { - $pending_import[$data['jamf_items_id']] = $data; + $pending_import[] = $data['jamf_items_id']; } $config = Config::getConfigurationValues('plugin:Jamf'); @@ -564,7 +565,7 @@ public static function discover(): bool // Some other error } } else { - if (!array_key_exists($jamf_device['id'], $pending_import)) { + if (!in_array((int) $jamf_device['id'], $pending_import, true)) { // Just discovered and cannot auto-import. Save to imports table instead. $DB->insert('glpi_plugin_jamf_imports', [ 'jamf_type' => 'Computer', diff --git a/inc/migration.class.php b/inc/migration.class.php index 7f8bf59..f332554 100644 --- a/inc/migration.class.php +++ b/inc/migration.class.php @@ -605,4 +605,12 @@ public function apply_3_0_1_migration(): void // Change udid column in glpi_plugin_jamf_imports to allow NULL values $this->db->queryOrDie('ALTER TABLE `glpi_plugin_jamf_imports` MODIFY `udid` VARCHAR(100) NULL DEFAULT NULL'); } + + public function apply_3_1_1_migration(): void + { + // Fix unicity constraint on imports table + $this->glpiMigration->dropKey('glpi_plugin_jamf_imports', 'unicity'); + // Unicity should be on jamf_type (The type in Jamf: Computer/MobileDevice) and jamf_items_id, not jamf_items_id and type (The type of asset in GLPI) + $this->glpiMigration->addKey('glpi_plugin_jamf_imports', ['jamf_type', 'jamf_items_id'], 'unicity', 'UNIQUE'); + } } diff --git a/inc/mobilesync.class.php b/inc/mobilesync.class.php index b30fb48..3c91179 100644 --- a/inc/mobilesync.class.php +++ b/inc/mobilesync.class.php @@ -659,6 +659,7 @@ public static function discover(): bool $imported[] = $data['udid']; } $pending_iterator = $DB->request([ + 'SELECT' => ['jamf_items_id'], 'FROM' => 'glpi_plugin_jamf_imports', 'WHERE' => [ 'jamf_type' => 'MobileDevice' @@ -666,12 +667,12 @@ public static function discover(): bool ]); $pending_import = []; foreach ($pending_iterator as $data) { - $pending_import[$data['udid']] = $data; + $pending_import[] = $data['jamf_items_id']; } $config = Config::getConfigurationValues('plugin:Jamf'); foreach ($jamf_devices as $jamf_device) { - if (!in_array($jamf_device['udid'], $imported, true)) { + if (!in_array($jamf_device['id'], $imported, true)) { $itemtype = strpos($jamf_device['model_identifier'], 'iPhone') !== false ? 'Phone' : 'Computer'; if (isset($config['autoimport']) && $config['autoimport']) { try { @@ -683,7 +684,7 @@ public static function discover(): bool // Some other error } } else { - if (!array_key_exists($jamf_device['udid'], $pending_import)) { + if (!in_array((int) $jamf_device['id'], $pending_import, true)) { $DB->insert('glpi_plugin_jamf_imports', [ 'jamf_type' => 'MobileDevice', 'jamf_items_id' => $jamf_device['id'],