---
suivi: 1338
date: 2026-08-14
sujet: reprise_siwi_pdf_resolution_fichier
chantier: marches_reprise
type: fix
statut: poussé
hash: 7d12146b
fichiers:
  - app/Http/Controllers/SiwiImportController.php
  - database/data/journal_mises_a_jour_post_2026_06_12.php
  - docs/suivi/SUIVI_1338_siwi_pdf_resolution_fichier.md
---

## PROMPT ENVOYÉ

SUIVI #1338 — diagnostic puis fix : tous les PDF SIWI affichent
« Dépôt PDF SIWI inaccessible » alors que le dépôt
`storage/app/private/siwi-import/` est lisible et que `.env` est correct.

## SYNTHÈSE

### Fiches lues
- `#1336` : `documentPdf` + messages ; introduisait `realpath($base)` en gate.
- `#1337` : Dialog PDF — **non touchée** ; consomme toujours la même route.

### Cause exacte
```
$baseReal = realpath($baseConfigured);
if ($baseReal === false || ! is_dir($baseReal)) {
    return … "Dépôt PDF SIWI inaccessible."
}
```
`realpath()` renvoie `false` (déplacement du dossier / cache realpath /
comportement FPM) alors que `is_dir` + `is_readable` réussissent sur le
même chemin. Le message confondait dépôt illisible et simple échec de
`realpath`. Les fichiers `.PDF` n’étaient jamais testés.

### Hypothèses
| # | Hypothèse | Verdict |
|---|-----------|---------|
| a | `.pdf` minuscule vs `.PDF` | **FAUX** pour CE message (aurait donné « fichier absent ») ; corrigé quand même |
| b | `open_basedir` FPM bloquant le dir | **FAUX** absolu (frère `factures` OK) ; peut contribuer à l’échec de `realpath` |
| c | `realpath()` en échec | **VRAI** — condition exacte du 503 |
| d | `is_executable` / `is_writable` | **FAUX** — absents du code |
| e | `base_path`/`storage_path` doublon | **FAUX** — chemin = `config('siwi.import_path')` seul |

### Fix
- Gate : `is_dir` + `is_readable` uniquement.
- Résolution : `{id}.PDF`, `{id}.pdf`, `{id}.Pdf`, puis `glob({id}.*)`, puis `opendir`.
- Messages distincts : dépôt inaccessible (503) vs fichier introuvable (404).
- Logs `siwi.document_pdf.*` avec chemins réellement testés.
- `.env` / Dialog / verrou contrôle : inchangés.

### Vérification écran
**NON faite** depuis Cursor (pas de session prod). Lot **non validé écran**.

## DÉPLOIEMENT-TEST

```bash
git pull origin main
php artisan optimize:clear && php artisan view:clear
php artisan journal:sync
```

Pas de migrate. Tester `/siwi-import/documents/3372/pdf` et Dialog œil.

## LEÇON

Ne jamais utiliser `realpath()` comme seule preuve d’existence d’un dépôt
sous OVH FPM : après un déplacement, `realpath` peut échouer alors que
`is_dir`/`is_readable` passent. Les factures (Storage disk) n’avaient pas
ce piège.
