人人商城

upgrade.ctrl.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. *[淘淘源码铺微擎系统 System] Copyright (c) 2018 www.330code.com
  4. */
  5. defined('IN_IA') or exit('Access Denied');
  6. load()->model('cloud');
  7. load()->func('communication');
  8. load()->func('db');
  9. $r = cloud_prepare();
  10. if (is_error($r)) {
  11. itoast($r['message'], url('cloud/profile') , 'error');
  12. }
  13. $dos = array(
  14. 'upgrade'
  15. );
  16. $do = in_array($do, $dos) ? $do : 'upgrade';
  17. uni_user_permission_check('system_cloud_upgrade');
  18. if (empty($_W['setting']['site']['profile_perfect'])) {
  19. }
  20. if ($do == 'upgrade') {
  21. $_W['page']['title'] = '一键更新 - 云服务';
  22. if (empty($_W['setting']['cloudip']) || $_W['setting']['cloudip']['expire'] < TIMESTAMP) {
  23. $cloudip = gethostbyname('www.sq.com');
  24. if (empty($cloudip) || !preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $cloudip)) {
  25. itoast('云服务域名解析失败,请查看服务器DNS设置或是在“云服务诊断”中手动设置云服务IP', url('cloud/diagnose') , 'error');
  26. }
  27. setting_save(array(
  28. 'ip' => $cloudip,
  29. 'expire' => TIMESTAMP + 3600
  30. ) , 'cloudip');
  31. }
  32. if (checksubmit('submit')) {
  33. $upgrade = cloud_build();
  34. if (is_error($upgrade)) {
  35. itoast($upgrade['message'], '', 'error');
  36. }
  37. if ($upgrade['upgrade']) {
  38. itoast("检测到新版本: <strong>{$upgrade['version']} (Release {$upgrade['release']})</strong>, 请立即更新.", 'refresh');
  39. } else {
  40. cache_delete('checkupgrade:system');
  41. cache_delete('cloud:transtoken');
  42. itoast('检查结果: 恭喜, 你的程序已经是最新版本. ', 'refresh');
  43. }
  44. }
  45. cache_load('upgrade');
  46. if (!empty($_W['cache']['upgrade'])) {
  47. $upgrade_cache = $_W['cache']['upgrade'];
  48. }
  49. if (!empty($upgrade_cache) || TIMESTAMP - $upgrade_cache['lastupdate'] >= 3600 * 24 || empty($upgrade_cache['data'])) {
  50. $upgrade = cloud_build();
  51. } else {
  52. $upgrade = $upgrade_cache['data'];
  53. }
  54. cache_delete('cloud:transtoken');
  55. if (!empty($upgrade['schemas'])) {
  56. $upgrade['database'] = array();
  57. foreach ($upgrade['schemas'] as $remote) {
  58. $row = array();
  59. $row['tablename'] = $remote['tablename'];
  60. $name = substr($remote['tablename'], 4);
  61. $local = db_table_schema(pdo() , $name);
  62. unset($remote['increment']);
  63. unset($local['increment']);
  64. if (empty($local)) {
  65. $row['new'] = true;
  66. } else {
  67. $row['new'] = false;
  68. $row['fields'] = array();
  69. $row['indexes'] = array();
  70. $diffs = db_schema_compare($local, $remote);
  71. if (!empty($diffs['fields']['less'])) {
  72. $row['fields'] = array_merge($row['fields'], $diffs['fields']['less']);
  73. }
  74. if (!empty($diffs['fields']['diff'])) {
  75. $row['fields'] = array_merge($row['fields'], $diffs['fields']['diff']);
  76. }
  77. if (!empty($diffs['indexes']['less'])) {
  78. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['less']);
  79. }
  80. if (!empty($diffs['indexes']['diff'])) {
  81. $row['indexes'] = array_merge($row['indexes'], $diffs['indexes']['diff']);
  82. }
  83. $row['fields'] = implode($row['fields'], ' ');
  84. $row['indexes'] = implode($row['indexes'], ' ');
  85. }
  86. $upgrade['database'][] = $row;
  87. }
  88. }
  89. $path = IA_ROOT . '/data/patch/' . date('Ymd') . '/';
  90. if (is_dir($path)) {
  91. if ($handle = opendir($path)) {
  92. while (false !== ($patchpath = readdir($handle))) {
  93. if ($patchpath != '.' && $patchpath != '..') {
  94. if (is_dir($path . $patchpath)) {
  95. $patchs[] = $patchpath;
  96. }
  97. }
  98. }
  99. }
  100. if (!empty($patchs)) {
  101. sort($patchs, SORT_NUMERIC);
  102. }
  103. }
  104. }
  105. template('cloud/upgrade');