Skip to content
Snippets Groups Projects
Commit 8ac646cc authored by Alex Barth's avatar Alex Barth
Browse files

#929058 alex_b: Report status of source on import and delete forms, track last...

#929058 alex_b: Report status of source on import and delete forms, track last updated time on a source level.
parent 24fb1a4c
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX
--------------------------------- ---------------------------------
- #929058 alex_b: Report status of source on import and delete forms, track
last updated time on a source level.
- #928836: Set progress floating point directly. Note: fetchers and parsers - #928836: Set progress floating point directly. Note: fetchers and parsers
must use $state->progress() for setting the batch progress now IF they support must use $state->progress() for setting the batch progress now IF they support
batching. batching.
......
...@@ -85,6 +85,13 @@ function feeds_schema() { ...@@ -85,6 +85,13 @@ function feeds_schema() {
'description' => 'Cache for fetcher result.', 'description' => 'Cache for fetcher result.',
'serialize' => TRUE, 'serialize' => TRUE,
), ),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
), ),
'primary key' => array('id', 'feed_nid'), 'primary key' => array('id', 'feed_nid'),
'indexes' => array( 'indexes' => array(
...@@ -264,3 +271,17 @@ function feeds_update_7100(&$sandbox) { ...@@ -264,3 +271,17 @@ function feeds_update_7100(&$sandbox) {
); );
db_add_field('feeds_source', 'fetcher_result', $spec); db_add_field('feeds_source', 'fetcher_result', $spec);
} }
/**
* Add imported timestamp to feeds_source table.
*/
function feeds_update_7201(&$sandbox) {
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
);
db_add_field('feeds_source', 'imported', $spec);
}
...@@ -255,6 +255,15 @@ function feeds_theme() { ...@@ -255,6 +255,15 @@ function feeds_theme() {
'file' => 'feeds.pages.inc', 'file' => 'feeds.pages.inc',
'render element' => 'element', 'render element' => 'element',
), ),
'feeds_source_status' => array(
'file' => 'feeds.pages.inc',
'variables' => array(
'progress_importing' => NULL,
'progress_clearing' => NULL,
'imported' => NULL,
'count' => NULL,
),
),
); );
} }
......
...@@ -50,8 +50,15 @@ function feeds_import_form($form, &$form_state, $importer_id) { ...@@ -50,8 +50,15 @@ function feeds_import_form($form, &$form_state, $importer_id) {
$form['#importer_id'] = $importer_id; $form['#importer_id'] = $importer_id;
// @todo Move this into fetcher? // @todo Move this into fetcher?
$form['#attributes']['enctype'] = 'multipart/form-data'; $form['#attributes']['enctype'] = 'multipart/form-data';
$form['source_status'] = array(
'#type' => 'fieldset',
'#title' => t('Status'),
'#tree' => TRUE,
'#value' => feeds_source_status($source),
);
$form['feeds'] = array( $form['feeds'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Import'),
'#tree' => TRUE, '#tree' => TRUE,
); );
$form['feeds'] += $source->configForm($form_state); $form['feeds'] += $source->configForm($form_state);
...@@ -95,12 +102,19 @@ function feeds_import_form_submit($form, &$form_state) { ...@@ -95,12 +102,19 @@ function feeds_import_form_submit($form, &$form_state) {
*/ */
function feeds_import_tab_form($form, &$form_state, $node) { function feeds_import_tab_form($form, &$form_state, $node) {
$importer_id = feeds_get_importer_id($node->type); $importer_id = feeds_get_importer_id($node->type);
$source = feeds_source($importer_id, $node->nid);
$form = array(); $form = array();
$form['#feed_nid'] = $node->nid; $form['#feed_nid'] = $node->nid;
$form['#importer_id'] = $importer_id; $form['#importer_id'] = $importer_id;
$form['#redirect'] = 'node/'. $node->nid; $form['#redirect'] = 'node/'. $node->nid;
return confirm_form($form, t('Import all content from feed?'), 'node/'. $node->nid, '', t('Import'), t('Cancel'), 'confirm feeds update'); $form['source_status'] = array(
'#type' => 'fieldset',
'#title' => t('Status'),
'#tree' => TRUE,
'#value' => feeds_source_status($source),
);
return confirm_form($form, t('Import all content from source?'), 'node/'. $node->nid, '', t('Import'), t('Cancel'), 'confirm feeds update');
} }
/** /**
...@@ -119,16 +133,24 @@ function feeds_import_tab_form_submit($form, &$form_state) { ...@@ -119,16 +133,24 @@ function feeds_import_tab_form_submit($form, &$form_state) {
*/ */
function feeds_delete_tab_form($form, &$form_state, $importer_id, $node = NULL) { function feeds_delete_tab_form($form, &$form_state, $importer_id, $node = NULL) {
if (empty($node)) { if (empty($node)) {
$form['#redirect'] = 'import/'. $importer_id; $source = feeds_source($importer_id);
$form['#redirect'] = 'import/' . $source->id;
} }
else { else {
$importer_id = feeds_get_importer_id($node->type); $importer_id = feeds_get_importer_id($node->type);
$form['#feed_nid'] = $node->nid; $source = feeds_source($importer_id, $node->nid);
$form['#redirect'] = 'node/'. $node->nid; $form['#redirect'] = 'node/' . $source->feed_nid;
} }
// Form cannot pass on feed object. // Form cannot pass on source object.
$form['#importer_id'] = $importer_id; $form['#importer_id'] = $source->id;
return confirm_form($form, t('Delete all items from feed?'), $form['#redirect'], '', t('Delete'), t('Cancel'), 'confirm feeds update'); $form['#feed_nid'] = $source->feed_nid;
$form['source_status'] = array(
'#type' => 'fieldset',
'#title' => t('Status'),
'#tree' => TRUE,
'#value' => feeds_source_status($source),
);
return confirm_form($form, t('Delete all items from source?'), $form['#redirect'], '', t('Delete'), t('Cancel'), 'confirm feeds update');
} }
/** /**
...@@ -161,6 +183,56 @@ function feeds_importer_template($importer) { ...@@ -161,6 +183,56 @@ function feeds_importer_template($importer) {
return drupal_not_found(); return drupal_not_found();
} }
/**
* Renders a status display for a source.
*/
function feeds_source_status($source) {
$progress_importing = $source->progressImporting();
$v = array();
if ($progress_importing != FEEDS_BATCH_COMPLETE) {
$v['progress_importing'] = $progress_importing;
}
$progress_clearing = $source->progressClearing();
if ($progress_clearing != FEEDS_BATCH_COMPLETE) {
$v['progress_clearing'] = $progress_clearing;
}
if (empty($v)) {
$v['imported'] = $source->imported;
$v['count'] = $source->itemCount();
}
if (!empty($v)) {
return theme('feeds_source_status', $v);
}
}
/**
* Themes a status display for a source.
*/
function theme_feeds_source_status($v) {
$output = '<div class="info-box feeds-source-status">';
$items = array();
if ($v['count']) {
if ($v['imported']) {
$items[] = t('Last import: @ago ago.', array('@ago' => format_interval(REQUEST_TIME - $v['imported'], 1)));
}
$items[] = t('@count imported items total.', array('@count' => $v['count']));
}
else {
$items[] = t('No imported items.');
}
if ($v['progress_importing']) {
$progress = number_format(100.0 * $v['progress_importing'], 0);
$items[] = t('Importing - @progress % complete.', array('@progress' => $progress));
}
if ($v['progress_clearing']) {
$progress = number_format(100.0 * $v['progress_clearing'], 0);
$items[] = t('Deleting items - @progress % complete.', array('@progress' => $progress));
}
$output .= theme('item_list', array('items' => $items));
$output .= '</div>';
return $output;
}
/** /**
* Theme upload widget. * Theme upload widget.
*/ */
......
...@@ -170,6 +170,9 @@ class FeedsSource extends FeedsConfigurable { ...@@ -170,6 +170,9 @@ class FeedsSource extends FeedsConfigurable {
// Fetcher result, used to cache fetcher result when batching. // Fetcher result, used to cache fetcher result when batching.
protected $fetcher_result; protected $fetcher_result;
// Timestamp when this source was imported the last time.
protected $imported;
/** /**
* Instantiate a unique object per class/id/feed_nid. Don't use * Instantiate a unique object per class/id/feed_nid. Don't use
* directly, use feeds_source() instead. * directly, use feeds_source() instead.
...@@ -239,6 +242,7 @@ class FeedsSource extends FeedsConfigurable { ...@@ -239,6 +242,7 @@ class FeedsSource extends FeedsConfigurable {
$result = $this->progressImporting(); $result = $this->progressImporting();
if ($result === FEEDS_BATCH_COMPLETE) { if ($result === FEEDS_BATCH_COMPLETE) {
module_invoke_all('feeds_after_import', $this); module_invoke_all('feeds_after_import', $this);
$this->imported = REQUEST_TIME;
unset($this->fetcher_result); unset($this->fetcher_result);
unset($this->state); unset($this->state);
} }
...@@ -363,6 +367,13 @@ class FeedsSource extends FeedsConfigurable { ...@@ -363,6 +367,13 @@ class FeedsSource extends FeedsConfigurable {
} }
} }
/**
* Count items imported by this source.
*/
public function itemCount() {
return $this->importer->processor->itemCount($this);
}
/** /**
* Save configuration. * Save configuration.
*/ */
...@@ -382,6 +393,7 @@ class FeedsSource extends FeedsConfigurable { ...@@ -382,6 +393,7 @@ class FeedsSource extends FeedsConfigurable {
$object = array( $object = array(
'id' => $this->id, 'id' => $this->id,
'feed_nid' => $this->feed_nid, 'feed_nid' => $this->feed_nid,
'imported' => $this->imported,
'config' => $config, 'config' => $config,
'source' => $source, 'source' => $source,
'state' => isset($this->state) ? $this->state : FALSE, 'state' => isset($this->state) ? $this->state : FALSE,
...@@ -401,11 +413,12 @@ class FeedsSource extends FeedsConfigurable { ...@@ -401,11 +413,12 @@ class FeedsSource extends FeedsConfigurable {
* @todo Patch CTools to move constants from export.inc to ctools.module. * @todo Patch CTools to move constants from export.inc to ctools.module.
*/ */
public function load() { public function load() {
if ($record = db_query("SELECT config, state, fetcher_result FROM {feeds_source} WHERE id = :id AND feed_nid = :nid", array(':id' => $this->id, ':nid' => $this->feed_nid))->fetch()) { if ($record = db_query("SELECT imported, config, state, fetcher_result FROM {feeds_source} WHERE id = :id AND feed_nid = :nid", array(':id' => $this->id, ':nid' => $this->feed_nid))->fetch()) {
// While FeedsSource cannot be exported, we still use CTool's export.inc // While FeedsSource cannot be exported, we still use CTool's export.inc
// export definitions. // export definitions.
ctools_include('export'); ctools_include('export');
$this->export_type = EXPORT_IN_DATABASE; $this->export_type = EXPORT_IN_DATABASE;
$this->imported = $record->imported;
$this->config = unserialize($record->config); $this->config = unserialize($record->config);
if (!empty($record->state)) { if (!empty($record->state)) {
$this->state = unserialize($record->state); $this->state = unserialize($record->state);
......
...@@ -139,6 +139,13 @@ class FeedsNodeProcessor extends FeedsProcessor { ...@@ -139,6 +139,13 @@ class FeedsNodeProcessor extends FeedsProcessor {
return $this->config['expire']; return $this->config['expire'];
} }
/**
* Return a count for the given items
*/
public function itemCount(FeedsSource $source) {
return db_query("SELECT count(*) FROM {feeds_node_item} WHERE feed_nid = :feed_nid", array(':feed_nid' => $source->feed_nid))->fetchField();
}
/** /**
* Override parent::configDefaults(). * Override parent::configDefaults().
*/ */
......
...@@ -76,6 +76,13 @@ abstract class FeedsProcessor extends FeedsPlugin { ...@@ -76,6 +76,13 @@ abstract class FeedsProcessor extends FeedsPlugin {
return FEEDS_BATCH_COMPLETE; return FEEDS_BATCH_COMPLETE;
} }
/**
* Return the number of items imported by this processor.
*/
public function itemCount(FeedsSource $source) {
return 0;
}
/** /**
* Execute mapping on an item. * Execute mapping on an item.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment