diff --git a/composer.json b/composer.json index 0cb9bea..0effa43 100644 --- a/composer.json +++ b/composer.json @@ -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" + ] } } diff --git a/scripts/update-project-info.php b/scripts/update-project-info.php new file mode 100644 index 0000000..3a9dba5 --- /dev/null +++ b/scripts/update-project-info.php @@ -0,0 +1,72 @@ +/.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");