/setup_factory/upgrade.php5.php

https://github.com/joelwan/php-object-generator · PHP · 140 lines · 110 code · 7 blank · 23 comment · 27 complexity · 07f416df06526867e79b86d3f5884061 MD5 · raw file

  1. <?php
  2. /**
  3. * @author Joel Wan & Mark Slemko. Designs by Jonathan Easton
  4. * @link http://www.phpobjectgenerator.com
  5. * @copyright Offered under the BSD license
  6. *
  7. * This upgrade file does the following:
  8. * 1. Checks if there is a new version of POG
  9. * 2. If there is, it reads generates newer versions of all objects in the object directory,
  10. * zip then and present them to the user to 'download'
  11. */
  12. ini_set("max_execution_time", 0);
  13. include_once "../../configuration.php";
  14. include_once "class.zipfile.php";
  15. include_once "setup_misc.php";
  16. /**
  17. * Connects to POG SOAP server defined in configuration.php and
  18. * generates new versions of all objects detected in /objects/ dir.
  19. * All upgraded objects are then zipped and presented to user.
  20. *
  21. * @param string $path
  22. */
  23. function UpdateAllObjects($path)
  24. {
  25. $dir = opendir($path);
  26. $objects = array();
  27. while(($file = readdir($dir)) !== false)
  28. {
  29. if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "configuration.php" && $file != "setup.php" && $file != "class.pog_base.php")
  30. {
  31. $objects[] = $file;
  32. }
  33. }
  34. closedir($dir);
  35. $i = 0;
  36. foreach($objects as $object)
  37. {
  38. $content = file_get_contents($path."/".$object);
  39. $contentParts = split("<b>",$content);
  40. if (isset($contentParts[1]))
  41. {
  42. $contentParts2 = split("</b>",$contentParts[1]);
  43. }
  44. if (isset($contentParts2[0]))
  45. {
  46. $className = trim($contentParts2[0]);
  47. }
  48. if (isset($className))
  49. {
  50. eval ('include_once("../../objects/class.'.strtolower($className).'.php");');
  51. $instance = new $className();
  52. if (!TestIsMapping($instance))
  53. {
  54. $objectNameList[] = $className;
  55. $linkParts1 = split("\*\/", $contentParts[1]);
  56. $linkParts2 = split("\@link", $linkParts1[0]);
  57. $link = $linkParts2[1];
  58. $options = array();
  59. if ($GLOBALS['configuration']['proxy_host'] != false &&
  60. $GLOBALS['configuration']['proxy_port'] != false &&
  61. $GLOBALS['configuration']['proxy_username'] != false &&
  62. $GLOBALS['configuration']['proxy_password'] != false)
  63. {
  64. $options = array(
  65. 'proxy_host' => $GLOBALS['configuration']['proxy_host'],
  66. 'proxy_port' => $GLOBALS['configuration']['proxy_port'],
  67. 'proxy_login' => $GLOBALS['configuration']['proxy_username'],
  68. 'proxy_password' => $GLOBALS['configuration']['proxy_password']
  69. );
  70. }
  71. $client = new SoapClient(
  72. $GLOBALS['configuration']['soap'],
  73. $options) ;
  74. if ($i == 0)
  75. {
  76. $package = unserialize($client->GeneratePackageFromLink($link));
  77. }
  78. else
  79. {
  80. $objectString = $client->GenerateObjectFromLink($link);
  81. $package["objects"]["class.".strtolower($className).".php"] = $objectString;
  82. }
  83. }
  84. }
  85. $i++;
  86. }
  87. //upgrade mapping classes if any
  88. foreach ($objectNameList as $objectName)
  89. {
  90. $instance = new $objectName();
  91. foreach ($instance->pog_attribute_type as $key => $attribute_type)
  92. {
  93. if ($attribute_type['db_attributes'][1] == "JOIN")
  94. {
  95. $mappingString = $client->GenerateMapping($objectName, $key, (isset($GLOBALS['configuration']['pdoDriver']) ? 'php5.1' :'php5'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'pdo' :'pog'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'mysql' :''));
  96. $package["objects"]['class.'.strtolower(MappingName($objectName, $key)).'.php'] = $mappingString;
  97. }
  98. }
  99. }
  100. $zipfile = new createZip();
  101. $zipfile -> addPOGPackage($package);
  102. $zipfile -> forceDownload("pog.".time().".zip");
  103. }
  104. /**
  105. * Checks if POG generator has been updated
  106. *
  107. * @return unknown
  108. */
  109. function UpdateAvailable()
  110. {
  111. $client = new SoapClient($GLOBALS['configuration']['soap']);
  112. $generatorVersion = base64_decode($client -> GetGeneratorVersion());
  113. if ($generatorVersion != $GLOBALS['configuration']['versionNumber'].$GLOBALS['configuration']['revisionNumber'])
  114. {
  115. return true;
  116. }
  117. else
  118. {
  119. return false;
  120. }
  121. }
  122. if (UpdateAvailable())
  123. {
  124. UpdateAllObjects("../../objects/");
  125. }
  126. else
  127. {
  128. echo "<script>
  129. alert('All POG objects are already up to date');
  130. window.close();
  131. </script>";
  132. }
  133. ?>