UpdateController.class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class UpdateController
  19. {
  20. //返回Json类型
  21. private $returnJson = array('type' => 'update');
  22. /**
  23. * 检查是否有更新
  24. */
  25. public function checkUpdate()
  26. {
  27. if (ALLOW_UPDATE) {
  28. $server = new ProxyModule;
  29. $updateInfo = $server->proxyToDesURL('GET', 'https://api.eolinker.com/openSource/Update/checkout');
  30. $result = json_decode($updateInfo['testResult']['body'], TRUE);
  31. if ($result) {
  32. if (OS_VERSION_CODE < $result['versionCode']) {
  33. $this->returnJson['statusCode'] = '000000';
  34. if (!is_session_started()) {
  35. session_start();
  36. }
  37. if (is_session_started()) {
  38. session_destroy();
  39. }
  40. } else {
  41. $this->returnJson['statusCode'] = '320002';
  42. }
  43. } else {
  44. $this->returnJson['statusCode'] = '320001';
  45. }
  46. exitOutput($this->returnJson);
  47. } else {
  48. //更新已被禁用
  49. $this->returnJson['statusCode'] = '320004';
  50. }
  51. exitOutput($this->returnJson);
  52. }
  53. /**
  54. * 自动更新项目
  55. */
  56. public function autoUpdate()
  57. {
  58. ini_set("max_execution_time", 0);
  59. if (ALLOW_UPDATE) {
  60. try {
  61. $proxyServer = new ProxyModule;
  62. $updateInfo = $proxyServer->proxyToDesURL('GET', 'https://api.eolinker.com/openSource/Update/checkout');
  63. $result = json_decode($updateInfo['testResult']['body'], TRUE);
  64. if ($result) {
  65. if (OS_VERSION_CODE < $result['versionCode']) {
  66. $updateServer = new UpdateModule;
  67. if ($updateServer->autoUpdate($result['updateUrl'])) {
  68. $this->returnJson['statusCode'] = '000000';
  69. if (!is_session_started()) {
  70. session_start();
  71. }
  72. if (is_session_started()) {
  73. session_destroy();
  74. }
  75. } else {
  76. //更新失败
  77. $this->returnJson['statusCode'] = '320003';
  78. }
  79. } else {
  80. //已是最新版本,无需更新
  81. $this->returnJson['statusCode'] = '320002';
  82. }
  83. } else {
  84. //无法获取更新信息(可能断网等)
  85. $this->returnJson['statusCode'] = '320001';
  86. }
  87. } catch (Exception $e) {
  88. //更新失败
  89. $this->returnJson['statusCode'] = '320003';
  90. $this->returnJson['errorMsg'] = $e->getMessage();
  91. }
  92. } else {
  93. //更新已被禁用
  94. $this->returnJson['statusCode'] = '320004';
  95. }
  96. exitOutput($this->returnJson);
  97. }
  98. /**
  99. * 手动更新项目
  100. */
  101. public function manualUpdate()
  102. {
  103. ini_set("max_execution_time", 0);
  104. if (ALLOW_UPDATE) {
  105. try {
  106. $updateServer = new UpdateModule;
  107. if ($updateServer->manualUpdate()) {
  108. $this->returnJson['statusCode'] = '000000';
  109. if (!is_session_started()) {
  110. session_start();
  111. }
  112. if (is_session_started()) {
  113. session_destroy();
  114. }
  115. } else {
  116. //更新失败
  117. $this->returnJson['statusCode'] = '320003';
  118. }
  119. } catch (\Exception $e) {
  120. $this->returnJson['statusCode'] = '320003';
  121. $this->returnJson['errorMsg'] = $e->getMessage();
  122. }
  123. } else {
  124. //更新已被禁用
  125. $this->returnJson['statusCode'] = '320004';
  126. }
  127. exitOutput($this->returnJson);
  128. }
  129. }
  130. ?>