Guest User

Untitled

a guest
Oct 14th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Script to manage to version of Magento in a git mirror
  5. * php $argv[0] core-repository new-version-of-magento
  6. *
  7. * It will look for Mage.php in new-version-of-magento and parse the version
  8. * and edition from it.
  9. *
  10. * It will copy the code, remove the old files, create new branches if necessary
  11. * and tag the release.
  12. *
  13. * Branches are major.minor
  14. *
  15. * so 1.9.0.0, 1.9.0.1, 1.9.10 all go in the 1.9 branch
  16. * 1.10.0.0 would cause a new 1.10 branch to be created.
  17. *
  18. * 1.10 will be branched of 1.9 so you can diff them easily
  19. *
  20. * @author Aydin Hassan <[email protected]>
  21. */
  22.  
  23. function cp($from, $to) {
  24. $iterator = new \RecursiveIteratorIterator(
  25. new \RecursiveDirectoryIterator($from, \RecursiveDirectoryIterator::SKIP_DOTS),
  26. \RecursiveIteratorIterator::SELF_FIRST
  27. );
  28. foreach ($iterator as $item) {
  29. if ($item->isDir()) {
  30. mkdir($to . "/" . $iterator->getSubPathName());
  31. } else {
  32. copy($item, $to . "/" . $iterator->getSubPathName());
  33. }
  34. }
  35. }
  36.  
  37. function rmOldMagento()
  38. {
  39. exec("rm -rf *");
  40. exec("rm -rf *.ht");
  41. }
  42.  
  43. function commitAndTag($version, $edition)
  44. {
  45. exec("git add --all");
  46. exec("git commit -m 'Magento $edition $version'");
  47. exec("git tag $version");
  48. }
  49.  
  50. function parseCore($location) {
  51. if (!file_exists(rtrim($location, "/") . "/app/Mage.php")) {
  52. die("$location does not look like a Magento code base");
  53. }
  54.  
  55. require_once rtrim($location, "/") . "/app/Mage.php";
  56. $edition = Mage::getEdition();
  57. $version = Mage::getVersionInfo();
  58. $versionStr = Mage::getVersion();
  59. return array('edition' => $edition, 'version' => $version, 'versionStr' => $versionStr);
  60. }
  61.  
  62. if (!isset($argv[1]) || !isset($argv[2])) {
  63. die("{$argv[0]} core-repo magento-code-location");
  64. }
  65.  
  66. $coreRepoLocation = $argv[1];
  67. $coreLocation = $argv[2];
  68. $packageName = isset($argv[3]) ? $argv[3] : 'magento/magento';
  69.  
  70. if (!file_exists($coreRepoLocation)) {
  71. die("Core Repo Location is invalid");
  72. }
  73. $info = parseCore($coreLocation);
  74.  
  75. $coreRepoLocation = realpath($coreRepoLocation);
  76. chdir($coreRepoLocation);
  77. exec("git for-each-ref refs/heads/ --format='%(refname:short)'", $branches);
  78.  
  79. usort($branches, function ($a, $b) {
  80. return version_compare($a, $b);
  81. });
  82.  
  83. $composerFile = '{
  84. "name": "flagbit/magento-enterprise",
  85. "description": "Magento Enterprise",
  86. "type": "magento-core",
  87. "license": "proprietary",
  88. "require": {
  89. "php": ">=5.4.0,<7.0.0",
  90. "ext-curl": "*",
  91. "ext-dom": "*",
  92. "ext-gd": "*",
  93. "ext-hash": "*",
  94. "ext-iconv": "*",
  95. "ext-mcrypt": "*",
  96. "ext-pcre": "*",
  97. "ext-pdo": "*",
  98. "ext-pdo_mysql": "*",
  99. "ext-simplexml": "*"
  100. },
  101. "provide": {
  102. "connect20/mage_core_module": "self.version"
  103. }
  104. }';
  105.  
  106. $major = $info['version']['major'];
  107. $minor = $info['version']['minor'];
  108. $version = $info['versionStr'];
  109.  
  110. $branch = $major . "." . $minor;
  111.  
  112. if (!count($branches)) {
  113. exec("git checkout -b $branch");
  114. cp($coreLocation, $coreRepoLocation);
  115. file_put_contents("composer.json", $composerFile);
  116. commitAndTag($version, $info['edition']);
  117. exit("Created branch: $branch and tagged: $version");
  118. }
  119.  
  120. $earliestBranch = $branches[0];
  121. if (version_compare($version, $earliestBranch, '<')) {
  122. die("Adding previous releases not supported");
  123. }
  124.  
  125. $foundBranch = false;
  126. foreach ($branches as $b) {
  127. if ($b === $branch) {
  128. $foundBranch = true;
  129. }
  130. }
  131.  
  132. if ($foundBranch) {
  133. exec("git checkout $branch");
  134. rmOldMagento();
  135. cp($coreLocation, $coreRepoLocation);
  136. file_put_contents("composer.json", $composerFile);
  137. commitAndTag($version, $info['edition']);
  138. exit("Added to branch: $branch and tagged: $version");
  139. }
  140.  
  141. $mostRecentVersion = end($branches);
  142.  
  143. if (version_compare($version, $mostRecentVersion, '<')) {
  144. die("Adding new previous minors is unsupported");
  145. }
  146.  
  147. exec("git checkout -b $branch $mostRecentVersion");
  148. rmOldMagento();
  149. cp($coreLocation, $coreRepoLocation);
  150. file_put_contents("composer.json", $composerFile);
  151. commitAndTag($version, $info['edition']);
  152. exit("Created new branch: $branch and tagged: $version");
Advertisement
Add Comment
Please, Sign In to add comment