人人商城

process.ctrl.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. */
  4. load()->func('communication');
  5. load()->model('cloud');
  6. $prepare = cloud_prepare();
  7. if (is_error($prepare)) {
  8. itoast($prepare['message'], url('cloud/profile'), 'error');
  9. }
  10. $step = $_GPC['step'];
  11. $steps = array('files', 'schemas', 'scripts');
  12. $step = in_array($step, $steps) ? $step : 'files';
  13. if ($step == 'files' && $_W['ispost']) {
  14. $ret = cloud_download($_GPC['path'], $_GPC['type']);
  15. if (!is_error($ret)) {
  16. exit('success');
  17. }
  18. exit($ret['message']);
  19. }
  20. if ($step == 'scripts' && $_W['ispost']) {
  21. $fname = trim($_GPC['fname']);
  22. $entry = IA_ROOT . '/data/update/' . $fname;
  23. if (is_file($entry) && preg_match('/^update\(\d{12}\-\d{12}\)\.php$/', $fname)) {
  24. $evalret = include $entry;
  25. if (!empty($evalret)) {
  26. cache_build_users_struct();
  27. cache_build_setting();
  28. @unlink($entry);
  29. exit('success');
  30. }
  31. }
  32. exit('failed');
  33. }
  34. if (!empty($_GPC['m'])) {
  35. $m = $_GPC['m'];
  36. $type = 'module';
  37. $is_upgrade = intval($_GPC['is_upgrade']);
  38. $packet = cloud_m_build($_GPC['m']);
  39. } elseif (!empty($_GPC['t'])) {
  40. $m = $_GPC['t'];
  41. $type = 'theme';
  42. $is_upgrade = intval($_GPC['is_upgrade']);
  43. $packet = cloud_t_build($_GPC['t']);
  44. } elseif (!empty($_GPC['w'])) {
  45. $m = $_GPC['w'];
  46. $type = 'webtheme';
  47. $is_upgrade = intval($_GPC['is_upgrade']);
  48. $packet = cloud_w_build($_GPC['w']);
  49. } else {
  50. $m = '';
  51. $packet = cloud_build();
  52. }
  53. if ($step == 'schemas' && $_W['ispost']) {
  54. $tablename = $_GPC['table'];
  55. foreach ($packet['schemas'] as $schema) {
  56. if (substr($schema['tablename'], 4) == $tablename) {
  57. $remote = $schema;
  58. break;
  59. }
  60. }
  61. if (!empty($remote)) {
  62. load()->func('db');
  63. $local = db_table_schema(pdo(), $tablename);
  64. $sqls = db_table_fix_sql($local, $remote);
  65. $error = false;
  66. foreach ($sqls as $sql) {
  67. if (pdo_query($sql) === false) {
  68. $error = true;
  69. $errormsg .= pdo_debug(false);
  70. break;
  71. }
  72. }
  73. if (!$error) {
  74. exit('success');
  75. }
  76. }
  77. exit;
  78. }
  79. if (!empty($packet) && (!empty($packet['upgrade']) || !empty($packet['install']))) {
  80. $schemas = array();
  81. if (!empty($packet['schemas'])) {
  82. foreach ($packet['schemas'] as $schema) {
  83. $schemas[] = substr($schema['tablename'], 4);
  84. }
  85. }
  86. $scripts = array();
  87. if (empty($packet['install'])) {
  88. $updatefiles = array();
  89. if (!empty($packet['scripts']) && empty($packet['type'])) {
  90. $updatedir = IA_ROOT . '/data/update/';
  91. load()->func('file');
  92. rmdirs($updatedir, true);
  93. mkdirs($updatedir);
  94. $cversion = IMS_VERSION;
  95. $crelease = IMS_RELEASE_DATE;
  96. foreach ($packet['scripts'] as $script) {
  97. if ($script['release'] <= $crelease) {
  98. continue;
  99. }
  100. $fname = "update({$crelease}-{$script['release']}).php";
  101. $crelease = $script['release'];
  102. $script['script'] = @base64_decode($script['script']);
  103. if (empty($script['script'])) {
  104. $script['script'] = <<<DAT
  105. <?php
  106. load()->model('setting');
  107. setting_upgrade_version('{$packet['family']}', '{$script['version']}', '{$script['release']}');
  108. return true;
  109. DAT;
  110. }
  111. $updatefile = $updatedir . $fname;
  112. file_put_contents($updatefile, $script['script']);
  113. $updatefiles[] = $updatefile;
  114. $s = array_elements(array('message', 'release', 'version'), $script);
  115. $s['fname'] = $fname;
  116. $scripts[] = $s;
  117. }
  118. }
  119. }
  120. } else {
  121. if (is_error($packet)) {
  122. itoast($packet['message'], '', 'error');
  123. } else {
  124. cache_delete('checkupgrade:system');
  125. cache_delete('cloud:transtoken');
  126. itoast('更新已完成. ', url('cloud/upgrade'), 'success');
  127. }
  128. }
  129. template('cloud/process');