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_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__',
'arguments' => array(
'image_path' => NULL,
'url' => NULL,
'query' => '',
'text' => '',
),
'file' => 'theme/views_data_export.theme.inc',
);
$hooks['views_data_export_complete_page'] = array(
'arguments' => array(
'file' => '',
'errors' => array(),
'return_url' => '',
),
'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 (!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) {
$qry = db_query("SELECT eid FROM {views_data_export} WHERE time_stamp <= %d ORDER BY time_stamp ASC", time() - $expires);
}
else {
$qry = db_query_range("SELECT eid FROM {views_data_export} WHERE time_stamp <= %d ORDER BY time_stamp ASC", time() - $expires, 0, $chunk);
}
$eids_to_clear = array();
while ($row = db_fetch_array($qry)) {
$eids_to_clear[] = $row['eid'];
}
if (count($eids_to_clear)) {
$ret = array();
foreach ($eids_to_clear as $eid) {
$table = VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX . $eid;
if (db_table_exists($table)) {
db_drop_table($ret, $table);
}
}
db_query("DELETE FROM {views_data_export} WHERE eid IN (" . db_placeholders($eids_to_clear) . ")", $eids_to_clear);
views_data_export_view_clear($eids_to_clear);
}
}
function _views_data_export_batch_process($export_id, $display_id, &$context) {
$view = views_data_export_view_retrieve($export_id);
$view
->set_display($display_id);
$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' => 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) {
$qry = db_query("SELECT * FROM {views_data_export} WHERE eid = %d", (int) $export_id);
$object = db_fetch_object($qry);
if ($object) {
$object->sandbox = unserialize($object->sandbox);
}
return $object;
}
function views_data_export_clear($export_id) {
db_query("DELETE FROM {views_data_export} WHERE eid = %d", $export_id);
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' => time(),
);
drupal_write_record('views_data_export_object_cache', $record);
}
function views_data_export_view_retrieve($export_id) {
views_include('view');
$data = db_fetch_object(db_query("SELECT * FROM {views_data_export_object_cache} WHERE eid = '%s'", $export_id));
if ($data) {
$view = unserialize($data->data);
}
return $view;
}
function views_data_export_view_clear($export_id) {
if (is_array($export_id)) {
db_query("DELETE FROM {views_data_export_object_cache} WHERE eid IN (" . db_placeholders($export_id) . ")", $export_id);
}
else {
db_query("DELETE FROM {views_data_export_object_cache} WHERE eid = '%s'", $export_id);
}
}