From 54c5733069ad02982070c25b58fb93a1e8234bbb Mon Sep 17 00:00:00 2001 From: bach Date: Sun, 22 Nov 2026 21:39:21 +0100 Subject: [PATCH] =?UTF-8?q?fix=20update-project-info:=20ecrit=20la=20versi?= =?UTF-8?q?on=20drupal.org=20(8.x-1.23,=208.x-3.x-dev)=20dans=20les=20.inf?= =?UTF-8?q?o.yml=20au=20lieu=20de=20la=20version=20composer=20normalisee?= =?UTF-8?q?=20(1.23.0)=20=E2=80=94=20sinon=20/admin/reports/updates=20affi?= =?UTF-8?q?che=20'Non=20support=C3=A9e=20!'=20sur=20tous=20les=20modules?= =?UTF-8?q?=20en=208.x-*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tag: version = source.reference (tag git drupal.org), fallback URL dist ftp.drupal.org - branche dev: version dev exacte retrouvée via release-history updates.drupal.org (8.x-3.x-dev, 2.0.x-dev...) - ne ecrase plus une version existante correcte Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- scripts/update-project-info.php | 59 ++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/scripts/update-project-info.php b/scripts/update-project-info.php index a3f63b9..2ce32ee 100644 --- a/scripts/update-project-info.php +++ b/scripts/update-project-info.php @@ -2,10 +2,16 @@ /** * @file - * Injecte 'project:' et 'version:' dans les .info.yml des packages drupal/* - * installés en SOURCE (git), car les tags git ne les contiennent pas (seuls - * les tarballs drupal.org les ajoutent). Sans ça, le module update ne voit - * que le core dans /admin/reports/updates. + * Injecte 'project:' et 'version:' dans les .info.yml des packages drupal/*. + * + * - Les installs git (source) ne contiennent ni project: ni version: dans le + * .info.yml (seuls les tarballs packagés par drupal.org les ajoutent) : sans + * ça, le module update ne voit que le core dans /admin/reports/updates. + * - La version écrite doit être la version drupal.org (ex. '8.x-1.23', + * '8.x-3.x-dev'), PAS la version normalisée par composer (ex. '1.23.0') : + * sinon /admin/reports/updates affiche « Non supportée ! » en rouge. + * Le tag drupal.org est retrouvé via source.reference (tag git) ou l'URL + * dist ; pour les branches dev, via le release-history updates.drupal.org. * * Appelé via composer scripts post-install-cmd / post-update-cmd. */ @@ -18,6 +24,43 @@ if (!file_exists($installedFile)) { $installed = json_decode(file_get_contents($installedFile), TRUE); $packages = $installed['packages'] ?? $installed; +/** + * Retourne la version drupal.org d'un package, ou NULL si indéterminable. + */ +function drupal_org_version(array $pkg): ?string { + $ref = $pkg['source']['reference'] ?? ''; + // Un tag (ex. '8.x-1.23', '4.1.4', '2.0.0-beta14') — pas un hash de commit. + if ($ref !== '' && !preg_match('/^[0-9a-f]{40}$/i', $ref) && preg_match('/^[vV]?[0-9]/', $ref)) { + return ltrim($ref, 'vV'); + } + // Sinon, essaie d'extraire le tag de l'URL dist (ftp.drupal.org/files/projects/-.zip). + $dist = $pkg['dist']['url'] ?? ''; + if ($dist !== '' && preg_match('/-([0-9][^\/]*?)\.(zip|tar\.gz|tgz)$/', $dist, $m)) { + return $m[1]; + } + // Branche dev (ex. 'dev-3.x', 'dev-2.0.x') : interroge le release-history + // drupal.org pour trouver la version dev exacte ('8.x-3.x-dev', '3.x-dev'…). + $version = $pkg['version'] ?? ''; + if (preg_match('/^dev-(\d+(?:\.\d+)?\.x)$/', $version, $m)) { + $branch = $m[1]; + $short = substr($pkg['name'] ?? '', 7); + $url = 'https://updates.drupal.org/release-history/' . $short . '/current'; + $ctx = stream_context_create(['http' => ['timeout' => 5], 'https' => ['timeout' => 5]]); + $xml = @file_get_contents($url, false, $ctx); + if ($xml !== false && preg_match_all('/([^<]+)<\/version>/', $xml, $mm)) { + $candidates = ['8.x-' . $branch . '-dev', $branch . '-dev']; + foreach ($candidates as $cand) { + if (in_array($cand, $mm[1], true)) { + return $cand; + } + } + // Le XML ne connaît aucune version dev de cette branche : on laisse tel quel. + } + return $version; + } + return $version !== '' ? $version : NULL; +} + $patched = 0; foreach ($packages as $pkg) { $name = $pkg['name'] ?? ''; @@ -49,11 +92,11 @@ foreach ($packages as $pkg) { if (!preg_match('/^project:/mi', $content)) { $content = "project: '" . $short . "'\n" . $content; } - // version: à la fin si absent (on retire une éventuelle ligne version existante - // pour rester cohérent avec le lock). + // version: remplacée par la version drupal.org (jamais la version composer + // normalisée, ex. '1.23.0' au lieu de '8.x-1.23'). + $version = drupal_org_version($pkg); $content = preg_replace('/^version:.*$/mi', '', $content); - $version = $pkg['version'] ?? ''; - if ($version !== '') { + if ($version !== NULL && $version !== '') { $content = trim($content) . "\n\nversion: '" . $version . "'\n"; } if ($content !== $original) {