Last active
February 15, 2024 08:18
-
-
Save AydinHassan/6ed0bf2219ea0f122402 to your computer and use it in GitHub Desktop.
Add a new version of Magento to a repository compatible with https://github.com/AydinHassan/magento-core-composer-installer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Script to manage to version of Magento in a git mirror | |
* php $argv[0] core-repository new-version-of-magento | |
* | |
* It will look for Mage.php in new-version-of-magento and parse the version | |
* and edition from it. | |
* | |
* It will copy the code, remove the old files, create new branches if necessary | |
* and tag the release. | |
* | |
* Branches are major.minor | |
* | |
* so 1.9.0.0, 1.9.0.1, 1.9.10 all go in the 1.9 branch | |
* 1.10.0.0 would cause a new 1.10 branch to be created. | |
* | |
* 1.10 will be branched of 1.9 so you can diff them easily | |
* | |
* @author Aydin Hassan <[email protected]> | |
*/ | |
function cp($from, $to) { | |
$iterator = new \RecursiveIteratorIterator( | |
new \RecursiveDirectoryIterator($from, \RecursiveDirectoryIterator::SKIP_DOTS), | |
\RecursiveIteratorIterator::SELF_FIRST | |
); | |
foreach ($iterator as $item) { | |
if ($item->isDir()) { | |
mkdir($to . "/" . $iterator->getSubPathName()); | |
} else { | |
copy($item, $to . "/" . $iterator->getSubPathName()); | |
} | |
} | |
} | |
function rmOldMagento() | |
{ | |
exec("rm -rf *"); | |
exec("rm -rf *.ht"); | |
} | |
function commitAndTag($version, $edition) | |
{ | |
exec("git add --all"); | |
exec("git commit -m 'Magento $edition $version'"); | |
exec("git tag $version"); | |
} | |
function parseCore($location) { | |
if (!file_exists(rtrim($location, "/") . "/app/Mage.php")) { | |
die("$location does not look like a Magento code base"); | |
} | |
require_once rtrim($location, "/") . "/app/Mage.php"; | |
$edition = Mage::getEdition(); | |
$version = Mage::getVersionInfo(); | |
$versionStr = Mage::getVersion(); | |
return array('edition' => $edition, 'version' => $version, 'versionStr' => $versionStr); | |
} | |
if (!isset($argv[1]) || !isset($argv[2])) { | |
die("{$argv[0]} core-repo magento-code-location"); | |
} | |
$coreRepoLocation = $argv[1]; | |
$coreLocation = $argv[2]; | |
$packageName = isset($argv[3]) ? $argv[3] : 'magento/magento'; | |
if (!file_exists($coreRepoLocation)) { | |
die("Core Repo Location is invalid"); | |
} | |
$info = parseCore($coreLocation); | |
$coreRepoLocation = realpath($coreRepoLocation); | |
chdir($coreRepoLocation); | |
exec("git for-each-ref refs/heads/ --format='%(refname:short)'", $branches); | |
usort($branches, function ($a, $b) { | |
return version_compare($a, $b); | |
}); | |
$composerFile = '{ | |
"name": "' . $packageName . '", | |
"description": "Magento ' . $info['edition'] . '", | |
"type": "magento-core" | |
}'; | |
$major = $info['version']['major']; | |
$minor = $info['version']['minor']; | |
$version = $info['versionStr']; | |
$branch = $major . "." . $minor; | |
if (!count($branches)) { | |
exec("git checkout -b $branch"); | |
cp($coreLocation, $coreRepoLocation); | |
file_put_contents("composer.json", $composerFile); | |
commitAndTag($version, $info['edition']); | |
exit("Created branch: $branch and tagged: $version"); | |
} | |
$earliestBranch = $branches[0]; | |
if (version_compare($version, $earliestBranch, '<')) { | |
die("Adding previous releases not supported"); | |
} | |
$foundBranch = false; | |
foreach ($branches as $b) { | |
if ($b === $branch) { | |
$foundBranch = true; | |
} | |
} | |
if ($foundBranch) { | |
exec("git checkout $branch"); | |
rmOldMagento(); | |
cp($coreLocation, $coreRepoLocation); | |
file_put_contents("composer.json", $composerFile); | |
commitAndTag($version, $info['edition']); | |
exit("Added to branch: $branch and tagged: $version"); | |
} | |
$mostRecentVersion = end($branches); | |
if (version_compare($version, $mostRecentVersion, '<')) { | |
die("Adding new previous minors is unsupported"); | |
} | |
exec("git checkout -b $branch $mostRecentVersion"); | |
rmOldMagento(); | |
cp($coreLocation, $coreRepoLocation); | |
file_put_contents("composer.json", $composerFile); | |
commitAndTag($version, $info['edition']); | |
exit("Created new branch: $branch and tagged: $version"); |
Just got back to this. A quick search returns that the getEdition method wasn't available until Magento Community 1.7 or EE 1.12.
This confused me
This confused me
This confused me
This confused me
@SageRiley2015 obviously!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Magento Enterprise 1.9.1.1
php add-magento-version.php ~/Projects/ REDACTED /magento-enterprise ~/Projects/ REDACTED /1.9.1.1
...and the following error is the result.