index.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © 2013-2017 Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. require_once __DIR__ . '/app/bootstrap.php';
  7. if (PHP_SAPI != 'cli') {
  8. header('X-Frame-Options: SAMEORIGIN');
  9. header('X-Content-Type-Options: nosniff');
  10. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8') === false) {
  11. $xssHeaderValue = '1; mode=block';
  12. } else {
  13. $xssHeaderValue = '0';
  14. }
  15. header('X-XSS-Protection: ' . $xssHeaderValue);
  16. }
  17. $status = new \Magento\Update\Status();
  18. $isUpdateInProgress = $status->isUpdateInProgress();
  19. $statusMessage = '';
  20. $statusMessage .= $status->get();
  21. $statusMessage = str_replace("\n", "<br />", $statusMessage);
  22. $queue = new \Magento\Update\Queue();
  23. $pending = !$status->isUpdateInProgress() && !$queue->isEmpty() && !$status->isUpdateError();
  24. if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
  25. if($_SERVER['PATH_INFO'] === '/rollback' && file_exists(MAGENTO_BP . '/var/.update_error.flag')) {
  26. try {
  27. $queue->clear();
  28. $backupInfo = new \Magento\Update\Backup\BackupInfo();
  29. $backupPaths = $backupInfo->getBackupFilePaths();
  30. if (isset($backupPaths['error'])) {
  31. $status->add('WARNING: There is a problem with backup files! Performing rollback from these'
  32. . ' files may cause the Magento application to be unstable', \Psr\Log\LogLevel::WARNING);
  33. foreach ($backupPaths['error'] as $error) {
  34. $status->add($error, \Psr\Log\LogLevel::WARNING);
  35. }
  36. unset($backupPaths['error']);
  37. }
  38. foreach (array_values($backupPaths) as $backupPath) {
  39. $queue->addJobs(
  40. ['jobs' =>
  41. [
  42. 'name' => $backupPath['type'],
  43. 'params'=> ['backup_file_name' => $backupPath['filename']]
  44. ]
  45. ]
  46. );
  47. }
  48. $status->setUpdateError(false);
  49. } catch (\Exception $e) {
  50. $status->setUpdateError(true);
  51. $status->add('Error in Rollback:' . $e->getMessage(), \Psr\Log\LogLevel::ERROR);
  52. }
  53. } elseif ($_SERVER['PATH_INFO'] === '/status') {
  54. $complete = !$status->isUpdateInProgress() && $queue->isEmpty() && !$status->isUpdateError();
  55. if ($complete) {
  56. $status->clear();
  57. }
  58. echo json_encode(
  59. [
  60. 'statusMessage' => $statusMessage,
  61. 'isUpdateInProgress' => $isUpdateInProgress,
  62. 'complete' => $complete,
  63. 'error' => $status->isUpdateError(),
  64. 'pending' => $pending,
  65. ]
  66. );
  67. }
  68. } else {
  69. if (!file_exists(MAGENTO_BP . '/app/etc/config.php') || !file_exists(MAGENTO_BP . '/app/etc/env.php')) {
  70. header('Location: ../setup');
  71. die();
  72. }
  73. $type = 'default';
  74. $titles = [];
  75. $defaultHeaderTitle = 'Magento Updater';
  76. if (file_exists(MAGENTO_BP . '/var/.type.json')) {
  77. $typeFlag = json_decode(file_get_contents(MAGENTO_BP . '/var/.type.json'), true);
  78. $headerTitle = isset($typeFlag['headerTitle']) ? $typeFlag['headerTitle'] : $defaultHeaderTitle;
  79. $titles = $typeFlag['titles'];
  80. } else {
  81. $headerTitle = $defaultHeaderTitle;
  82. }
  83. include __DIR__ . '/app/code/Magento/Update/view/templates/status.phtml';
  84. }