upgrade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * The upgrade router file of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package ZenTaoPMS
  9. * @version $Id: upgrade.php 4677 2013-04-26 06:23:58Z chencongzhi520@gmail.com $
  10. * @link http://www.zentao.net
  11. */
  12. /* Judge my.php exists or not. */
  13. $basePath = dirname(dirname(__FILE__));
  14. $dbConfig = $basePath . '/config/db.php';
  15. $myConfig = $basePath . '/config/my.php';
  16. if(file_exists($dbConfig))
  17. {
  18. if(file_exists($myConfig))
  19. {
  20. $myContent = trim(file_get_contents($myConfig));
  21. $myContent = str_replace('<?php', '', $myContent);
  22. }
  23. if(!@rename($dbConfig, $myConfig))
  24. {
  25. $configDir = $basePath . '/config/';
  26. echo "请执行命令 chmod 777 $configDir 来修改权限,保证禅道在该目录有操作文件权限" . "<br />";
  27. echo "Please execute the command 'chmod 777 $configDir' to modify the permissions to ensure that the ZenTao has operating file permissions in this directory";
  28. exit;
  29. }
  30. if(!empty($myContent))
  31. {
  32. $myContent = file_get_contents($myConfig) . "\n" . $myContent;
  33. file_put_contents($myConfig, $myContent);
  34. }
  35. }
  36. if(!file_exists($myConfig)) die(header('location: install.php'));
  37. if(file_exists("{$basePath}/config/ext/secret.php") and !unlink("{$basePath}/config/ext/secret.php"))
  38. {
  39. echo "请删除文件 {$basePath}/config/ext/secret.php,后刷新页面<br />";
  40. echo "Please delete {$basePath}/config/ext/secret.php and refresh.";
  41. exit;
  42. }
  43. error_reporting(0);
  44. /* Load the framework. */
  45. include '../framework/router.class.php';
  46. include '../framework/control.class.php';
  47. include '../framework/model.class.php';
  48. include '../framework/helper.class.php';
  49. /* Instance the app. */
  50. $app = router::createApp('pms', dirname(dirname(__FILE__)), 'router', 'upgrading');
  51. $common = $app->loadCommon();
  52. /* Reset the config params to make sure the install program will be lauched. */
  53. $oldRequestType = zget($config, 'requestType', '');
  54. $config->set('requestType', 'GET');
  55. $config->set('default.module', 'upgrade');
  56. if($config->debug > 1) $config->debug = true;
  57. $app->setDebug();
  58. /* Check the installed version is the latest or not. */
  59. $config->installedVersion = $common->loadModel('setting')->getVersion();
  60. if(!$app->session->upgrading && ($config->version[0] == $config->installedVersion[0] or (is_numeric($config->version[0]) and is_numeric($config->installedVersion[0]))) and version_compare($config->version, $config->installedVersion) <= 0) die(header('location: index.php'));
  61. /* 删除临时 model 文件。*/
  62. /* Delete tmp mode files. */
  63. if(!isset($_SESSION['deleteTmpModel']))
  64. {
  65. $upgradeModel = $common->loadModel('upgrade');
  66. $upgradeModel->deleteTmpModel();
  67. $_SESSION['deleteTmpModel'] = true;
  68. }
  69. /* Upgrade to latest version if it can be upgraded automatically. */
  70. if($app->canAutoUpgrade())
  71. {
  72. $upgradeModel = $common->loadModel('upgrade');
  73. $alterSQL = $upgradeModel->checkConsistency();
  74. if(!empty($alterSQL)) $upgradeModel->dao->query("SET @@sql_mode= '';" . $alterSQL);
  75. $config->set('default.method', 'execute');
  76. $app->session->set('upgrading', true);
  77. $app->session->set('step', '');
  78. $app->post->set('fromVersion', str_replace( '.', '_', strtolower($config->installedVersion)));
  79. }
  80. try
  81. {
  82. /* Run it. */
  83. $app->parseRequest();
  84. $app->loadModule();
  85. }
  86. catch (EndResponseException $endResponseException)
  87. {
  88. echo $endResponseException->getContent();
  89. }