feat : DATA_PATH configurable, DataGit auto-commit, UpdateChecker branche (v1.4.0)

- DATA_PATH : chemin /data hors document root, configurable via .env
  (fallback sur BASE_PATH/data si absent)
- DataGit : auto-commit git sur toutes les écritures articles/livres
  (create, update, delete, meta, tags, fichiers, liens…) sauf autosave
- UpdateChecker : getBranch() / getLastChecked() / clearCache(),
  branche configurable via FOLIO_UPDATE_BRANCH (plus de main hardcodé)
- Admin dashboard : affiche la branche suivie, date du dernier contrôle,
  bouton Vérifier pour forcer le check sans attendre le TTL
- CLAUDE.md : architecture DATA_PATH et flux de déploiement documentés

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 09:17:55 +02:00
parent 55a2120be1
commit 16965ee8cb
18 changed files with 236 additions and 37 deletions
+27 -3
View File
@@ -89,8 +89,31 @@ class UpdateChecker
return version_compare($remoteVer, $deployedVer, '>') ? $remoteVer : null;
}
public function getBranch(): string
{
return (string) ($_ENV['FOLIO_UPDATE_BRANCH'] ?? getenv('FOLIO_UPDATE_BRANCH') ?: 'main');
}
public function getLastChecked(): ?int
{
$cacheFile = $this->dataDir . '/.version_check_cache.json';
if (!file_exists($cacheFile)) {
return null;
}
$cache = json_decode((string) file_get_contents($cacheFile), true) ?? [];
return isset($cache['fetched_at']) ? (int) $cache['fetched_at'] : null;
}
public function clearCache(): void
{
$cacheFile = $this->dataDir . '/.version_check_cache.json';
if (file_exists($cacheFile)) {
unlink($cacheFile);
}
}
/**
* Récupère `public/version.txt` depuis le dépôt Gitea (branche main).
* Récupère `public/version.txt` depuis le dépôt Gitea.
* Résultat mis en cache 1 h dans `data/.version_check_cache.json`.
*/
private function fetchRemoteVersion(string $repoUrl): ?string
@@ -107,8 +130,9 @@ class UpdateChecker
}
}
// URL du fichier brut : {repo}/raw/branch/main/public/version.txt
$rawUrl = $repoUrl . '/raw/branch/main/public/version.txt';
$branch = $this->getBranch();
// URL du fichier brut : {repo}/raw/branch/{branch}/public/version.txt
$rawUrl = $repoUrl . '/raw/branch/' . $branch . '/public/version.txt';
$token = (string) ($_ENV['GITEA_TOKEN'] ?? getenv('GITEA_TOKEN') ?: '');
$opts = [