import_status.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Import progress bar backend
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Core;
  9. use PhpMyAdmin\Display\ImportAjax;
  10. /* PHP 5.4 stores upload progress data only in the default session.
  11. * After calling session_name(), we won't find the progress data anymore.
  12. *
  13. * https://bugs.php.net/bug.php?id=64075
  14. *
  15. * The bug should be somewhere in
  16. * https://github.com/php/php-src/blob/master/ext/session/session.c#L2342
  17. *
  18. * Until this is fixed, we need to load the default session to load the data,
  19. * export the upload progress information from there,
  20. * and re-import after switching to our session.
  21. *
  22. * However, since https://github.com/phpmyadmin/phpmyadmin/commit/063a2d99
  23. * we have deactivated this feature, so the corresponding code is now
  24. * commented out.
  25. */
  26. /*
  27. if (ini_get('session.upload_progress.enabled')) {
  28. $sessionupload = array();
  29. define('UPLOAD_PREFIX', ini_get('session.upload_progress.prefix'));
  30. session_start();
  31. foreach ($_SESSION as $key => $value) {
  32. // only copy session-prefixed data
  33. if (substr($key, 0, strlen(UPLOAD_PREFIX))
  34. == UPLOAD_PREFIX) {
  35. $sessionupload[$key] = $value;
  36. }
  37. }
  38. // PMA will kill all variables, so let's use a constant
  39. define('SESSIONUPLOAD', serialize($sessionupload));
  40. session_write_close();
  41. // The cookie name is not good anymore since PR #15273
  42. session_name('phpMyAdmin');
  43. session_id($_COOKIE['phpMyAdmin']);
  44. }
  45. */
  46. define('PMA_MINIMUM_COMMON', 1);
  47. require_once 'libraries/common.inc.php';
  48. list(
  49. $SESSION_KEY,
  50. $upload_id,
  51. $plugins
  52. ) = ImportAjax::uploadProgressSetup();
  53. /*
  54. if (defined('SESSIONUPLOAD')) {
  55. // write sessionupload back into the loaded PMA session
  56. $sessionupload = unserialize(SESSIONUPLOAD);
  57. foreach ($sessionupload as $key => $value) {
  58. $_SESSION[$key] = $value;
  59. }
  60. // remove session upload data that are not set anymore
  61. foreach ($_SESSION as $key => $value) {
  62. if (substr($key, 0, strlen(UPLOAD_PREFIX))
  63. == UPLOAD_PREFIX
  64. && ! isset($sessionupload[$key])
  65. ) {
  66. unset($_SESSION[$key]);
  67. }
  68. }
  69. }
  70. */
  71. // $_GET["message"] is used for asking for an import message
  72. if (isset($_GET["message"]) && $_GET["message"]) {
  73. // AJAX requests can't be cached!
  74. Core::noCacheHeader();
  75. header('Content-type: text/html');
  76. // wait 0.3 sec before we check for $_SESSION variable,
  77. // which is set inside import.php
  78. usleep(300000);
  79. $maximumTime = ini_get('max_execution_time');
  80. $timestamp = time();
  81. // wait until message is available
  82. while ($_SESSION['Import_message']['message'] == null) {
  83. // close session before sleeping
  84. session_write_close();
  85. // sleep
  86. usleep(250000); // 0.25 sec
  87. // reopen session
  88. session_start();
  89. if ((time() - $timestamp) > $maximumTime) {
  90. $_SESSION['Import_message']['message'] = PhpMyAdmin\Message::error(
  91. __('Could not load the progress of the import.')
  92. )->getDisplay();
  93. break;
  94. }
  95. }
  96. echo $_SESSION['Import_message']['message'];
  97. echo '<fieldset class="tblFooters">' , "\n";
  98. echo ' [ <a href="' , $_SESSION['Import_message']['go_back_url']
  99. . '">' , __('Back') , '</a> ]' , "\n";
  100. echo '</fieldset>' , "\n";
  101. } else {
  102. ImportAjax::status($_GET["id"]);
  103. }