/scripts/upgrade/buildPackagesArray.php

https://bitbucket.org/valmy/openx · PHP · 123 lines · 79 code · 9 blank · 35 comment · 17 complexity · fa0a001c575dcc3aa3ab63ed78c2058f MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. // takes globals for tests
  27. // takes arguments when run from cli
  28. $path = dirname(dirname(dirname(__FILE__)));
  29. global $readPath, $writeFile;
  30. if ($argc>0)
  31. {
  32. $readPath = $argv[1];
  33. $writeFile = $argv[2];
  34. echo 'reading directory '.$readPath."\n";
  35. echo 'writing file '.$writeFile."\n";
  36. }
  37. if (is_null($readPath))
  38. {
  39. $readPath = $path.'/etc/changes';
  40. }
  41. if (is_null($writeFile))
  42. {
  43. $writeFile = $path.'/etc/changes/openads_upgrade_array.txt';
  44. }
  45. $fp = fopen($writeFile, 'w');
  46. if ($fp === false)
  47. {
  48. echo __FILE__.' : unable to open output file '.$writeFile."\n";
  49. exit();
  50. }
  51. $aVersions = array();
  52. $dh = opendir($readPath);
  53. if ($dh)
  54. {
  55. while (false !== ($file = readdir($dh)))
  56. {
  57. if (preg_match('/_upgrade_[\w\W]+\.xml/', $file, $aMatches))
  58. {
  59. preg_match('/(?P<release>[\d]+)\.(?P<major>[\d]+)\.(?P<minor>[\d]+)(?P<beta>\-beta)?(?P<rc>\-rc)?(?P<build>[\d]+)?(?P<toversion>_to_)?/i', $file, $aParsed);
  60. // we don't want *milestone* packages included in this array (openads_upgrade_n.n.nn_to_n.n.nn.xml)
  61. if (!$aParsed['toversion'])
  62. {
  63. $release = $aParsed['release'];
  64. $major = $aParsed['major'];
  65. $minor = $aParsed['minor'];
  66. $beta = $aParsed['beta'];
  67. $rc = $aParsed['rc'];
  68. $build = $aParsed['build'];
  69. if (!isset($aVersions[$release]))
  70. {
  71. $aVersions[$release] = array();
  72. }
  73. if (!isset($aVersions[$release][$major]))
  74. {
  75. $aVersions[$release][$major] = array();
  76. }
  77. if (!isset($aVersions[$release][$major][$minor]))
  78. {
  79. $aVersions[$release][$major][$minor] = array();
  80. }
  81. if ($rc && $beta)
  82. {
  83. $aVersions[$release][$major][$minor][$beta.$rc][$build]['file'] = $file;
  84. }
  85. else if ($beta)
  86. {
  87. $aVersions[$release][$major][$minor][$beta]['file'] = $file;
  88. }
  89. else if ($rc)
  90. {
  91. $aVersions[$release][$major][$minor][$rc][$build]['file'] = $file;
  92. }
  93. else
  94. {
  95. $aVersions[$release][$major][$minor]['file'] = $file;
  96. }
  97. }
  98. }
  99. }
  100. closedir($dh);
  101. }
  102. reset($aVersions);
  103. $array = serialize($aVersions);
  104. $x = fwrite($fp, $array);
  105. fclose($fp);
  106. // if (!file_exists($writeFile))
  107. // {
  108. // echo 'file was not written '.$writeFile."\n";
  109. // }
  110. // else
  111. // {
  112. // echo 'file written '.$writeFile."\n";
  113. // }
  114. ?>