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