Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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": "flagbit/magento-enterprise",
- "description": "Magento Enterprise",
- "type": "magento-core",
- "license": "proprietary",
- "require": {
- "php": ">=5.4.0,<7.0.0",
- "ext-curl": "*",
- "ext-dom": "*",
- "ext-gd": "*",
- "ext-hash": "*",
- "ext-iconv": "*",
- "ext-mcrypt": "*",
- "ext-pcre": "*",
- "ext-pdo": "*",
- "ext-pdo_mysql": "*",
- "ext-simplexml": "*"
- },
- "provide": {
- "connect20/mage_core_module": "self.version"
- }
- }';
- $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");
Advertisement
Add Comment
Please, Sign In to add comment