|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Script to download the latest Magento packages |
| 6 | + * This script: |
| 7 | + * 1. Finds the latest version for each major.minor release in resource/history/magento/magento2-base |
| 8 | + * 2. Uses composer to create a project with each version |
| 9 | + * 3. Uses the download-missing-packages-from-repo-magento-com.php script to download missing packages |
| 10 | + * 4. Removes the project directory |
| 11 | + */ |
| 12 | + |
| 13 | +// Set error reporting |
| 14 | +error_reporting(E_ALL); |
| 15 | +ini_set('display_errors', 1); |
| 16 | + |
| 17 | +// Directory containing version files |
| 18 | +$versionDir = "resource/history/magento/magento2-base"; |
| 19 | + |
| 20 | +// Get all version files |
| 21 | +$versionFiles = glob("$versionDir/*.json"); |
| 22 | +if (empty($versionFiles)) { |
| 23 | + echo "Error: No version files found in $versionDir\n"; |
| 24 | + exit(1); |
| 25 | +} |
| 26 | + |
| 27 | +// Collect all versions |
| 28 | +$versions = []; |
| 29 | +foreach ($versionFiles as $file) { |
| 30 | + $versions[] = basename($file, '.json'); |
| 31 | +} |
| 32 | + |
| 33 | +usort($versions, function($a, $b) { |
| 34 | + return version_compare($a, $b); |
| 35 | +}); |
| 36 | + |
| 37 | +$latestVersions = []; |
| 38 | +foreach ($versions as $version) { |
| 39 | + $versionAndPatch = explode('-', $version); |
| 40 | + $latestVersions[$versionAndPatch[0]] = $version; |
| 41 | +} |
| 42 | + |
| 43 | +// Process each version |
| 44 | +foreach ($latestVersions as $version) { |
| 45 | + echo "Processing version: $version\n"; |
| 46 | + |
| 47 | + // Create project directory using composer |
| 48 | + echo "Creating Magento project with version $version...\n"; |
| 49 | + $command = "composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:$version --ignore-platform-reqs --no-progress -q -n --no-plugins"; |
| 50 | + passthru($command, $returnCode); |
| 51 | + |
| 52 | + if ($returnCode !== 0) { |
| 53 | + echo "Error: Composer command failed with return code $returnCode\n"; |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
| 57 | + // Download missing packages |
| 58 | + echo "Downloading missing packages...\n"; |
| 59 | + $command = "php bin/download-missing-packages-from-repo-magento-com.php project-community-edition/composer.lock build resource/additional-packages"; |
| 60 | + passthru($command, $returnCode); |
| 61 | + |
| 62 | + // Remove project directory |
| 63 | + echo "Cleaning up project directory...\n"; |
| 64 | + $command = "rm -rf project-community-edition"; |
| 65 | + passthru($command); |
| 66 | + |
| 67 | + echo "\n\n"; |
| 68 | +} |
| 69 | + |
| 70 | +echo "Done!\n"; |
0 commit comments