fix: injecte project/version dans les .info.yml des packages drupal/* installes en source (post-install/update-cmd) — sinon /admin/reports/updates ne voit que le core

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-22 18:51:29 +01:00
co-authored by Mistral Vibe
parent b260a96c43
commit f1c22bbe50
2 changed files with 80 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
/**
* @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.
*
* Appelé via composer scripts post-install-cmd / post-update-cmd.
*/
$root = dirname(__DIR__);
$installedFile = $root . '/vendor/composer/installed.json';
if (!file_exists($installedFile)) {
return;
}
$installed = json_decode(file_get_contents($installedFile), TRUE);
$packages = $installed['packages'] ?? $installed;
$patched = 0;
foreach ($packages as $pkg) {
$name = $pkg['name'] ?? '';
if (!str_starts_with($name, 'drupal/')) {
continue;
}
$short = substr($name, 7);
$installPath = $pkg['install-path'] ?? NULL;
if (!$installPath) {
continue;
}
$dir = $root . '/vendor/' . $installPath;
if (!is_dir($dir)) {
continue;
}
// .info.yml principal du package : <dir>/<short>.info.yml, sinon le 1er trouvé.
$infoFile = $dir . '/' . $short . '.info.yml';
if (!file_exists($infoFile)) {
$found = glob($dir . '/*.info.yml');
if (!$found) {
continue;
}
$infoFile = $found[0];
}
$content = file_get_contents($infoFile);
$original = $content;
// project: en tête si absent.
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).
$content = preg_replace('/^version:.*$/mi', '', $content);
$version = $pkg['version'] ?? '';
if ($version !== '') {
$content = trim($content) . "\n\nversion: '" . $version . "'\n";
}
if ($content !== $original) {
file_put_contents($infoFile, $content);
$patched++;
}
}
// Invalide le cache des projets update si Drupal est bootstrappable.
if (class_exists('Drupal')) {
try {
\Drupal::keyValue('update')->delete('update_project_projects');
\Drupal::keyValue('update')->delete('update_project_data');
}
catch (\Throwable $e) {
}
}
fwrite(STDOUT, "update-project-info: $patched .info.yml patchés\n");