-.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'] ?? ''; if (!str_starts_with($name, 'drupal/')) { continue; } $short = substr($name, 7); $installPath = $pkg['install-path'] ?? NULL; if (!$installPath) { continue; } // install-path est relatif à vendor/composer/ (où réside installed.json). $dir = $root . '/vendor/composer/' . $installPath; if (!is_dir($dir)) { continue; } // .info.yml principal du package : /.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: 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); if ($version !== NULL && $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");