Revision 56aebcb7
Added by Assos Assos about 8 years ago
drupal7/sites/all/modules/views_data_export/plugins/views_data_export_plugin_display_export.inc | ||
---|---|---|
238 | 238 |
} |
239 | 239 |
|
240 | 240 |
// Try and get a batch context if possible. |
241 |
$eid = !empty($_GET['eid']) ? $_GET['eid'] : |
|
242 |
(!empty($this->batched_execution_state->eid) ? $this->batched_execution_state->eid : FALSE); |
|
241 |
|
|
242 |
if (!empty($_GET['eid']) && !empty($_GET['token']) && drupal_valid_token($_GET['token'], 'views_data_export/' . $_GET['eid'])) { |
|
243 |
$eid = $_GET['eid']; |
|
244 |
} |
|
245 |
elseif (!empty($this->batched_execution_state->eid)) { |
|
246 |
$eid = $this->batched_execution_state->eid; |
|
247 |
} |
|
248 |
else { |
|
249 |
$eid = FALSE; |
|
250 |
} |
|
251 |
|
|
243 | 252 |
if ($eid) { |
244 | 253 |
$this->batched_execution_state = views_data_export_get($eid); |
245 | 254 |
} |
... | ... | |
293 | 302 |
$this->batched_execution_state = views_data_export_new($this->view->name, $this->view->current_display, $this->outputfile_create()); |
294 | 303 |
views_data_export_view_store($this->batched_execution_state->eid, $this->view); |
295 | 304 |
|
305 |
// Record a usage of our file, so we can identify our exports later. |
|
306 |
file_usage_add(file_load($this->batched_execution_state->fid), 'views_data_export', 'eid', $this->batched_execution_state->eid); |
|
307 |
|
|
296 | 308 |
// We need to build the index right now, before we lose $_GET etc. |
297 | 309 |
$this->initialize_index(); |
298 | 310 |
//$this->batched_execution_state->fid = $this->outputfile_create(); |
299 | 311 |
|
300 |
// Initialize the progress counter |
|
301 |
$this->batched_execution_state->sandbox['max'] = db_query('SELECT COUNT(*) FROM {' . $this->index_tablename() . '}')->fetchField(); |
|
312 |
// Initialize the progress counter. |
|
313 |
if (db_table_exists($this->index_tablename())) { |
|
314 |
$this->batched_execution_state->sandbox['max'] = db_query('SELECT COUNT(*) FROM {' . $this->index_tablename() . '}')->fetchField(); |
|
315 |
} |
|
316 |
|
|
302 | 317 |
// Record the time we started. |
303 | 318 |
list($usec, $sec) = explode(' ', microtime()); |
304 | 319 |
$this->batched_execution_state->sandbox['started'] = (float) $usec + (float) $sec; |
305 | 320 |
|
321 |
// Pop something into the session to ensure it stays aorund. |
|
322 |
$_SESSION['views_data_export'][$this->batched_execution_state->eid] = TRUE; |
|
323 |
|
|
306 | 324 |
// Build up our querystring for the final page callback. |
307 | 325 |
$querystring = array( |
308 | 326 |
'eid' => $this->batched_execution_state->eid, |
327 |
'token' => drupal_get_token('views_data_export/' . $this->batched_execution_state->eid), |
|
309 | 328 |
'return-url' => NULL, |
310 | 329 |
); |
311 | 330 |
|
... | ... | |
401 | 420 |
break; |
402 | 421 |
|
403 | 422 |
case VIEWS_DATA_EXPORT_FOOTER: |
423 |
// Update the temporary file size, otherwise we would get a problematic |
|
424 |
// "Content-Length: 0" HTTP header, that may break the export download. |
|
425 |
$this->outputfile_update_size(); |
|
404 | 426 |
$sandbox['finished'] = 1; |
405 | 427 |
$state->batch_state = VIEWS_DATA_EXPORT_FINISHED; |
406 | 428 |
break; |
... | ... | |
418 | 440 |
function execute_final() { |
419 | 441 |
// Should we download the file. |
420 | 442 |
if (!empty($_GET['download'])) { |
443 |
// Clean up our session, if we need to. |
|
444 |
if (isset($_SESSION)) { |
|
445 |
unset($_SESSION['views_data_export'][$this->batched_execution_state->eid]); |
|
446 |
if (empty($_SESSION['views_data_export'])) { |
|
447 |
unset($_SESSION['views_data_export']); |
|
448 |
} |
|
449 |
} |
|
421 | 450 |
// This next method will exit. |
422 | 451 |
$this->transfer_file(); |
423 | 452 |
} |
... | ... | |
526 | 555 |
$query = array( |
527 | 556 |
'download' => 1, |
528 | 557 |
'eid' => $this->batched_execution_state->eid, |
558 |
'token' => drupal_get_token('views_data_export/' . $this->batched_execution_state->eid), |
|
529 | 559 |
); |
530 | 560 |
|
531 | 561 |
return theme('views_data_export_complete_page', array( |
... | ... | |
573 | 603 |
} |
574 | 604 |
// Set the headers. |
575 | 605 |
$this->add_http_headers(); |
576 |
file_transfer($this->outputfile_path(), array()); |
|
606 |
$headers = array( |
|
607 |
'Content-Length' => $this->outputfile_entity()->filesize, |
|
608 |
); |
|
609 |
file_transfer($this->outputfile_path(), $headers); |
|
577 | 610 |
} |
578 | 611 |
|
579 | 612 |
/** |
... | ... | |
666 | 699 |
} |
667 | 700 |
|
668 | 701 |
/** |
669 |
* Get the output file path.
|
|
702 |
* Get the output file entity.
|
|
670 | 703 |
*/ |
671 |
function outputfile_path() {
|
|
704 |
public function outputfile_entity() {
|
|
672 | 705 |
if (empty($this->_output_file)) { |
673 | 706 |
if (!empty($this->batched_execution_state->fid)) { |
674 | 707 |
// Return the filename associated with this file. |
... | ... | |
678 | 711 |
return NULL; |
679 | 712 |
} |
680 | 713 |
} |
681 |
return $this->_output_file->uri; |
|
714 |
return $this->_output_file; |
|
715 |
} |
|
716 |
|
|
717 |
/** |
|
718 |
* Get the output file path. |
|
719 |
*/ |
|
720 |
public function outputfile_path() { |
|
721 |
if ($file = $this->outputfile_entity()) { |
|
722 |
return $file->uri; |
|
723 |
} |
|
682 | 724 |
} |
683 | 725 |
|
684 | 726 |
/** |
... | ... | |
700 | 742 |
// Save the file into the DB. |
701 | 743 |
$file = $this->file_save_file($path); |
702 | 744 |
|
745 |
// Make sure the file is marked as temporary. |
|
746 |
// There is no FILE_STATUS_TEMPORARY constant. |
|
747 |
$file->status = 0; |
|
748 |
file_save($file); |
|
749 |
|
|
703 | 750 |
return $file->fid; |
704 | 751 |
} |
705 | 752 |
|
... | ... | |
713 | 760 |
} |
714 | 761 |
} |
715 | 762 |
|
763 |
/** |
|
764 |
* Updates the file size in the file entity. |
|
765 |
*/ |
|
766 |
protected function outputfile_update_size() { |
|
767 |
if ($file = $this->outputfile_entity()) { |
|
768 |
$file->filesize = filesize($file->uri); |
|
769 |
file_save($file); |
|
770 |
} |
|
771 |
} |
|
772 |
|
|
716 | 773 |
function abort_export($errors) { |
717 | 774 |
// Just cause the next batch to do the clean-up |
718 | 775 |
if (!is_array($errors)) { |
Also available in: Unified diff
Weekly update of contrib modules