---
suivi: 1067
date: 2026-07-29
sujet: Fix site_id SharePoint HECTARE (path → composite + encodage)
chantier: sharepoint_ged
type: fix
statut: poussé
hash: 5ee32264
fichiers:
  - app/Services/SharePointService.php
  - app/Support/SharePointArborescenceStructures.php
  - app/Support/SharePointHectareAccessProbe.php
  - database/migrations/2026_07_29_190000_fix_hectare_sharepoint_site_id_composite.php
  - docs/suivi/SUIVI_1067_fix_site_id_sharepoint_hectare.md
  - docs/suivi/SUIVI_1065_sharepoint_site_hectare.md
---

## PROMPT ENVOYÉ

SUIVI #1067 — correctif « drive introuvable » HECTARE. Cause : `rawurlencode` sur un
site PATH stocké en base (#1065). Remplacer par site_id composite + encoder les deux
formes correctement. Enrichir les logs. Ne pas retoucher la migration #1065 déjà passée.

## SYNTHÈSE

### Volet A — donnée
Nouvelle migration `2026_07_29_190000_fix_hectare_sharepoint_site_id_composite.php` :
si HECTARE.sharepoint_site_id === path → composite
`hectaresa.sharepoint.com,3a240051-…,f010e27b-…`. ENVOL/GEMME non touchés.

### Volet B — encodage
`SharePointService::encodeSiteIdentifier()` + `graphSiteUrl()`.
- path (contient `:`) : littéral (pas de rawurlencode)
- composite : `rawurlencode` inchangé → URL ENVOL identique

Points `/sites/{…}` traités (exhaustif dans SharePointService) :
1. diagnoseDriveResolution → `/drives`
2. diagnoseDriveResolution → `/lists`
3. diagnoseDriveResolution → `/drive`
4. createListItem → `/lists/{id}/items`

### Volet C — log
`drive introuvable` inclut désormais `graph_url_drives`, `site_id_form`,
`strategies_failed` (status, url, body tronqué).

### Journal (#412)
NON — correctif technique invisible ; GED déjà couverte conceptuellement au #1065.

## DÉPLOIEMENT-TEST

```bash
git pull origin main
find app/ -name "*.php" -exec touch {} +
php artisan migrate --force
php artisan optimize:clear
# pas de route:clear ; pas de journal:sync ; pas de rebuild
```

Puis sync SharePoint programme 14 (TEST) et 13 (EQUILIBRE) ; non-régression ENVOL.

## LEÇON
Graph accepte deux formes d’identifiant de site (composite `host,guid,guid` et path
`host:/sites/nom`), mais `rawurlencode()` détruit la seconde en encodant `:` et `/`.
Un backfill au format path a donc produit un « drive introuvable » qui ressemblait à
un problème de permission alors que l’accès était confirmé. Corollaire : quand un
diagnostic renvoie un identifiant, **stocker exactement celui que le code consomme**,
pas une forme équivalente.
