diff --git a/app/Services/Intune/RestoreService.php b/app/Services/Intune/RestoreService.php index 1486068..726f7ce 100644 --- a/app/Services/Intune/RestoreService.php +++ b/app/Services/Intune/RestoreService.php @@ -184,16 +184,25 @@ public function execute( if ($createOutcome['success']) { $createdPolicyId = $createOutcome['policy_id']; $createdPolicyMode = $createOutcome['mode'] ?? null; - $itemStatus = 'partial'; $mode = $createOutcome['mode'] ?? 'settings'; + // When settings are included in CREATE, mark as applied instead of partial + $itemStatus = $mode === 'settings' ? 'applied' : 'partial'; + $resultReason = $mode === 'metadata_only' ? 'Settings endpoint unsupported; created metadata-only policy. Manual settings apply required.' - : 'Settings endpoint unsupported; created new policy. Manual cleanup required.'; + : 'Settings endpoint unsupported; created new policy with settings. Manual cleanup required.'; if ($settingsApply !== null && $createdPolicyId) { $settingsApply['created_policy_id'] = $createdPolicyId; $settingsApply['created_policy_mode'] = $mode; + + // Update statistics when settings were included in CREATE + if ($mode === 'settings') { + $settingsApply['applied'] = $settingsApply['total'] ?? count($settings); + $settingsApply['manual_required'] = 0; + $settingsApply['issues'] = []; + } } } elseif ($settingsApply !== null && $createOutcome['response']) { $settingsApply['issues'][] = [ @@ -731,14 +740,22 @@ private function buildSettingsCatalogCreatePayload( $payload['description'] = $description; } + // Platforms and technologies must be singular strings for CREATE (not arrays) + // Graph API inconsistency: GET returns arrays, but POST expects strings $platforms = $this->resolvePayloadArray($originalPayload, ['platforms', 'Platforms']); - if ($platforms !== null) { - $payload['platforms'] = array_values($platforms); + if ($platforms !== null && $platforms !== []) { + $payload['platforms'] = is_array($platforms) ? $platforms[0] : $platforms; + } elseif ($platforms === null) { + // Fallback: extract from policy_type or default to windows10 + $payload['platforms'] = 'windows10'; } $technologies = $this->resolvePayloadArray($originalPayload, ['technologies', 'Technologies']); - if ($technologies !== null) { - $payload['technologies'] = array_values($technologies); + if ($technologies !== null && $technologies !== []) { + $payload['technologies'] = is_array($technologies) ? $technologies[0] : $technologies; + } elseif ($technologies === null) { + // Default to mdm if not present + $payload['technologies'] = 'mdm'; } $roleScopeTagIds = $this->resolvePayloadArray($originalPayload, ['roleScopeTagIds', 'RoleScopeTagIds']);