import_status.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. session_name('phpMyAdmin');
  42. session_id($_COOKIE['phpMyAdmin']);
  43. }
  44. */
  45. define('PMA_MINIMUM_COMMON', 1);
  46. require_once 'libraries/common.inc.php';
  47. list(
  48. $SESSION_KEY,
  49. $upload_id,
  50. $plugins
  51. ) = ImportAjax::uploadProgressSetup();
  52. /*
  53. if (defined('SESSIONUPLOAD')) {
  54. // write sessionupload back into the loaded PMA session
  55. $sessionupload = unserialize(SESSIONUPLOAD);
  56. foreach ($sessionupload as $key => $value) {
  57. $_SESSION[$key] = $value;
  58. }
  59. // remove session upload data that are not set anymore
  60. foreach ($_SESSION as $key => $value) {
  61. if (substr($key, 0, strlen(UPLOAD_PREFIX))
  62. == UPLOAD_PREFIX
  63. && ! isset($sessionupload[$key])
  64. ) {
  65. unset($_SESSION[$key]);
  66. }
  67. }
  68. }
  69. */
  70. // $_GET["message"] is used for asking for an import message
  71. if (isset($_GET["message"]) && $_GET["message"]) {
  72. // AJAX requests can't be cached!
  73. Core::noCacheHeader();
  74. header('Content-type: text/html');
  75. // wait 0.3 sec before we check for $_SESSION variable,
  76. // which is set inside import.php
  77. usleep(300000);
  78. $maximumTime = ini_get('max_execution_time');
  79. $timestamp = time();
  80. // wait until message is available
  81. while ($_SESSION['Import_message']['message'] == null) {
  82. // close session before sleeping
  83. session_write_close();
  84. // sleep
  85. usleep(250000); // 0.25 sec
  86. // reopen session
  87. session_start();
  88. if ((time() - $timestamp) > $maximumTime) {
  89. $_SESSION['Import_message']['message'] = PhpMyAdmin\Message::error(
  90. __('Could not load the progress of the import.')
  91. )->getDisplay();
  92. break;
  93. }
  94. }
  95. echo $_SESSION['Import_message']['message'];
  96. echo '<fieldset class="tblFooters">' , "\n";
  97. echo ' [ <a href="' , $_SESSION['Import_message']['go_back_url']
  98. . '">' , __('Back') , '</a> ]' , "\n";
  99. echo '</fieldset>' , "\n";
  100. } else {
  101. ImportAjax::status($_GET["id"]);
  102. }