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:
@@ -159,5 +159,13 @@
|
||||
"Replace Twitter with X https://www.drupal.org/project/social_media_links/issues/3384469": "https://www.drupal.org/files/issues/2023-09-12/social_media_links-change_twitter_to_x-3384469-7.patch"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-install-cmd": [
|
||||
"@php scripts/update-project-info.php"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php scripts/update-project-info.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
Reference in New Issue
Block a user