upgrade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Elgg upgrade script.
  4. *
  5. * This script triggers any necessary upgrades. If the site has been upgraded
  6. * to the most recent version of the code, no upgrades are run and the caches
  7. * are flushed. If you would prefer that this script is not accessible to others
  8. * after an upgrade, you can delete it. Future versions of Elgg will include a
  9. * new version of the script. Deleting the script is not a requirement and
  10. * leaving it behind does not affect the security of the site.
  11. *
  12. * Upgrades use a table {db_prefix}upgrade_lock as a mutex to prevent concurrent upgrades.
  13. *
  14. * The URL to forward to after upgrades are complete can be specified by setting $_GET['forward']
  15. * to a relative URL.
  16. *
  17. * @package Elgg.Core
  18. * @subpackage Upgrade
  19. */
  20. // we want to know if an error occurs
  21. ini_set('display_errors', 1);
  22. define('UPGRADING', 'upgrading');
  23. require_once(dirname(__FILE__) . "/engine/start.php");
  24. $site_url = elgg_get_config('url');
  25. $site_host = parse_url($site_url, PHP_URL_HOST) . '/';
  26. // turn any full in-site URLs into absolute paths
  27. $forward_url = get_input('forward', '/admin', false);
  28. $forward_url = str_replace(array($site_url, $site_host), '/', $forward_url);
  29. if (strpos($forward_url, '/') !== 0) {
  30. $forward_url = '/' . $forward_url;
  31. }
  32. if (get_input('upgrade') == 'upgrade') {
  33. $upgrader = new \Elgg\UpgradeService();
  34. $result = $upgrader->run();
  35. if ($result['failure'] == true) {
  36. register_error($result['reason']);
  37. forward($forward_url);
  38. }
  39. } else {
  40. // test the URL rewrite rules
  41. if (!class_exists('ElggRewriteTester')) {
  42. require dirname(__FILE__) . '/install/ElggRewriteTester.php';
  43. }
  44. $rewriteTester = new \ElggRewriteTester();
  45. $url = elgg_get_site_url() . "__testing_rewrite?__testing_rewrite=1";
  46. if (!$rewriteTester->runRewriteTest($url)) {
  47. // see if there is a problem accessing the site at all
  48. // due to ip restrictions for example
  49. if (!$rewriteTester->runLocalhostAccessTest()) {
  50. // note: translation may not be available until after upgrade
  51. $msg = elgg_echo("installation:htaccess:localhost:connectionfailed");
  52. if ($msg === "installation:htaccess:localhost:connectionfailed") {
  53. $msg = "Elgg cannot connect to itself to test rewrite rules properly. Check "
  54. . "that curl is working and there are no IP restrictions preventing "
  55. . "localhost connections.";
  56. }
  57. echo $msg;
  58. exit;
  59. }
  60. // note: translation may not be available until after upgrade
  61. $msg = elgg_echo("installation:htaccess:needs_upgrade");
  62. if ($msg === "installation:htaccess:needs_upgrade") {
  63. $msg = "You must update your .htaccess file so that the path is injected "
  64. . "into the GET parameter __elgg_uri (you can use install/config/htaccess.dist as a guide).";
  65. }
  66. echo $msg;
  67. exit;
  68. }
  69. // if upgrading from < 1.8.0, check for the core view 'welcome' and bail if it's found.
  70. // see https://github.com/elgg/elgg/issues/3064
  71. // we're not checking the view itself because it's likely themes will override this view.
  72. // we're only concerned with core files.
  73. $welcome = dirname(__FILE__) . '/views/default/welcome.php';
  74. if (file_exists($welcome)) {
  75. elgg_set_viewtype('failsafe');
  76. // can't have pretty messages because we don't know the state of the views.
  77. $content = elgg_echo('upgrade:unable_to_upgrade_info');
  78. $title = elgg_echo('upgrade:unable_to_upgrade');
  79. echo elgg_view_page($title, $content);
  80. exit;
  81. }
  82. $vars = array(
  83. 'forward' => $forward_url
  84. );
  85. // reset cache to have latest translations available during upgrade
  86. elgg_reset_system_cache();
  87. echo elgg_view_page(elgg_echo('upgrading'), '', 'upgrade', $vars);
  88. exit;
  89. }
  90. forward($forward_url);