View source
<?php
define('VIEWS_DATA_EXPORT_HEADER', 'header');
define('VIEWS_DATA_EXPORT_BODY', 'body');
define('VIEWS_DATA_EXPORT_FOOTER', 'footer');
define('VIEWS_DATA_EXPORT_FINISHED', 'finished');
define('VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX', 'views_data_export_index_');
function views_data_export_init() {
module_load_include('inc', 'views_data_export', 'theme/views_data_export.theme');
}
function views_data_export_views_api() {
return array(
'api' => 2,
);
}
function views_data_export_theme() {
module_load_include('inc', 'views_data_export', 'theme/views_data_export.theme');
$hooks = array();
$hooks['views_data_export_feed_icon'] = array(
'pattern' => 'views_data_export_feed_icon__',
'variables' => array(
'image_path' => NULL,
'url' => NULL,
'query' => '',
'text' => '',
),
'file' => 'theme/views_data_export.theme.inc',
);
$hooks['views_data_export_complete_page'] = array(
'variables' => array(
'file' => '',
'errors' => array(),
'return_url' => '',
),
'file' => 'theme/views_data_export.theme.inc',
);
$hooks['views_data_export_message'] = array(
'variables' => array(
'message' => '',
'type' => 'info',
),
'file' => 'theme/views_data_export.theme.inc',
);
return $hooks;
}
function views_data_export_cron() {
views_data_export_garbage_collect();
}
function views_data_export_garbage_collect($expires = NULL, $chunk = NULL) {
if (lock_acquire('views_data_export_gc')) {
if (!isset($expires)) {
$expires = variable_get('views_data_export_gc_expires', 604800);
}
if (!isset($chunk)) {
$chunk = variable_get('views_data_export_gc_chunk', 30);
}
if ($chunk == -1) {
$result = db_query("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", array(
':timestamp' => REQUEST_TIME - $expires,
));
}
else {
$result = db_query_range("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", 0, $chunk, array(
':timestamp' => REQUEST_TIME - $expires,
));
}
$eids_to_clear = array();
foreach ($result as $row) {
$eids_to_clear[] = $row->eid;
}
if (count($eids_to_clear)) {
foreach ($eids_to_clear as $eid) {
$table = VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX . $eid;
if (db_table_exists($table)) {
db_drop_table($table);
}
}
db_delete('views_data_export')
->condition('eid', $eids_to_clear, 'IN')
->execute();
views_data_export_view_clear($eids_to_clear);
}
lock_release('views_data_export_gc');
}
}
function _views_data_export_batch_process($export_id, $display_id, $exposed_input, &$context) {
if (module_exists('admin_menu')) {
module_invoke('admin_menu', 'suppress');
}
$view = views_data_export_view_retrieve($export_id);
$view
->set_display($display_id);
if (!empty($exposed_input)) {
$view
->set_exposed_input($exposed_input);
}
if (!isset($view->display_handler->batched_execution_state)) {
$view->display_handler->batched_execution_state = new stdClass();
}
$view->display_handler->batched_execution_state->eid = $export_id;
$view->display_handler->views_data_export_cached_view_loaded = TRUE;
$view
->execute_display($display_id);
$sandbox = $view->display_handler->batched_execution_state->sandbox;
$context['finished'] = $sandbox['finished'];
$context['message'] = $sandbox['message'];
views_data_export_view_store($export_id, $view);
}
function views_data_export_new($view_name, $view_display_id, $file) {
$record = (object) array(
'view_name' => $view_name,
'view_display_id' => $view_display_id,
'time_stamp' => REQUEST_TIME,
'fid' => $file,
'batch_state' => VIEWS_DATA_EXPORT_HEADER,
'sandbox' => array(),
);
drupal_write_record('views_data_export', $record);
return $record;
}
function views_data_export_update($state) {
drupal_write_record('views_data_export', $state, 'eid');
}
function views_data_export_get($export_id) {
$object = db_query("SELECT * FROM {views_data_export} WHERE eid = :eid", array(
':eid' => (int) $export_id,
))
->fetch();
if ($object) {
$object->sandbox = unserialize($object->sandbox);
}
return $object;
}
function views_data_export_clear($export_id) {
db_delete('views_data_export')
->condition('eid', $export_id)
->execute();
views_data_export_view_clear($export_id);
}
function views_data_export_view_store($export_id, $view) {
$_view = $view
->clone_view();
views_data_export_view_clear($export_id);
$record = array(
'eid' => $export_id,
'data' => $_view,
'updated' => REQUEST_TIME,
);
drupal_write_record('views_data_export_object_cache', $record);
}
function views_data_export_view_retrieve($export_id) {
views_include('view');
$data = db_query("SELECT * FROM {views_data_export_object_cache} WHERE eid = :eid", array(
':eid' => $export_id,
))
->fetch();
if ($data) {
$view = unserialize($data->data);
}
return $view;
}
function views_data_export_view_clear($export_id) {
db_delete('views_data_export_object_cache')
->condition('eid', $export_id)
->execute();
}
function views_data_export_file_presave($file) {
if (strpos($file->filename, 'views_data_export') === 0) {
$file->status = 0;
}
}