人人商城

process.ctrl.php 3.5KB

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