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

#928728: Track source states by stage, not by plugin.

parent a0fba5cb
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
Feeds 7.x 2.0 XXXXXXXXXXXXXXXXXXX
---------------------------------
- #928728: Track source states by stage, not by plugin. Note: call signature of
FeedsSource::state() has changed.
- #923318: Fix Fatal error: Call to a member function import() on a non-object
occuring on cron.
- Clean up basic settings form.
......
......@@ -6,6 +6,14 @@
* Definition of FeedsSourceInterface and FeedsSource class.
*/
/**
* Denote a import or clearing stage. Used for multi page processing.
*/
define('FEEDS_FETCH', 'fetch');
define('FEEDS_PARSE', 'parse');
define('FEEDS_PROCESS', 'process');
define('FEEDS_PROCESS_CLEAR', 'process_clear');
/**
* Declares an interface for a class that defines default values and form
* descriptions for a FeedSource.
......@@ -198,7 +206,7 @@ class FeedsSource extends FeedsConfigurable {
if (empty($this->fetcher_result) || FEEDS_BATCH_COMPLETE == $this->progressParsing()) {
$this->fetcher_result = $this->importer->fetcher->fetch($this);
// Clean the parser's state, we are parsing an entirely new file.
unset($this->state[get_class($this->importer->parser)]);
unset($this->state[FEEDS_PARSE]);
}
// Parse.
......@@ -260,15 +268,15 @@ class FeedsSource extends FeedsConfigurable {
* Report progress as float between 0 and 1. 1 = FEEDS_BATCH_COMPLETE.
*/
public function progressParsing() {
return $this->state($this->importer->parser)->progress();
return $this->state(FEEDS_PARSE)->progress();
}
/**
* Report progress as float between 0 and 1. 1 = FEEDS_BATCH_COMPLETE.
*/
public function progressImporting() {
$fetcher = $this->state($this->importer->fetcher);
$parser = $this->state($this->importer->parser);
$fetcher = $this->state(FEEDS_FETCH);
$parser = $this->state(FEEDS_PARSE);
if ($fetcher->progress() == FEEDS_BATCH_COMPLETE && $parser->progress() == FEEDS_BATCH_COMPLETE) {
return FEEDS_BATCH_COMPLETE;
}
......@@ -281,30 +289,28 @@ class FeedsSource extends FeedsConfigurable {
* Report progress on clearing.
*/
public function progressClearing() {
return $this->state($this->importer->processor)->progress();
return $this->state(FEEDS_PROCESS_CLEAR)->progress();
}
/**
* Return a state object for a given object. Lazy instantiates new states.
* Return a state object for a given stage. Lazy instantiates new states.
*
* @todo Rename getConfigFor() accordingly to config().
*
* @param FeedsSourceInterface $client
* An object that implements the FeedsSourceInterface, usually a fetcher,
* parser or processor plugin.
* @param $stage
* One of FEEDS_FETCH, FEEDS_PARSE, FEEDS_PROCESS or FEEDS_PROCESS_CLEAR.
*
* @return
* The FeedsState object for the given client.
* The FeedsState object for the given stage.
*/
public function state(FeedsSourceInterface $client) {
$class = get_class($client);
public function state($stage) {
if (!is_array($this->state)) {
$this->state = array();
}
if (!isset($this->state[$class])) {
$this->state[$class] = new FeedsState();
if (!isset($this->state[$stage])) {
$this->state[$stage] = new FeedsState();
}
return $this->state[$class];
return $this->state[$stage];
}
/**
......
......@@ -11,7 +11,7 @@ class FeedsCSVParser extends FeedsParser {
*/
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$source_config = $source->getConfigFor($this);
$state = $source->state($this);
$state = $source->state(FEEDS_PARSE);
// Load and configure parser.
feeds_include_library('ParserCSV.inc', 'ParserCSV');
......
......@@ -16,7 +16,7 @@ class FeedsFeedNodeProcessor extends FeedsProcessor {
* Implements FeedsProcessor::process().
*/
public function process(FeedsSource $source, FeedsParserResult $parser_result) {
$state = $source->state($this);
$state = $source->state(FEEDS_PROCESS);
while ($item = $parser_result->shiftItem()) {
// If the target item does not exist OR if update_existing is enabled,
......
......@@ -54,7 +54,7 @@ class FeedsFileFetcher extends FeedsFetcher {
}
// Batch if this is a directory.
$state = $source->state($this);
$state = $source->state(FEEDS_FETCH);
$files = array();
if (!isset($state->files)) {
$state->files = $this->listFiles($source_config['source']);
......
......@@ -23,7 +23,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
* Implements FeedsProcessor::process().
*/
public function process(FeedsSource $source, FeedsParserResult $parser_result) {
$state = $source->state($this);
$state = $source->state(FEEDS_PROCESS);
while ($item = $parser_result->shiftItem()) {
if (!($nid = $this->existingItemId($source, $parser_result)) ||
......@@ -74,7 +74,7 @@ class FeedsNodeProcessor extends FeedsProcessor {
* Implements FeedsProcessor::clear().
*/
public function clear(FeedsSource $source) {
$state = $source->state($this);
$state = $source->state(FEEDS_PROCESS_CLEAR);
if (empty($state->total)) {
$state->total = db_query("SELECT COUNT(n.nid) FROM {node} n JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE fn.id = :id AND fn.feed_nid = :nid", array(':id' => $source->id, ':nid' => $source->feed_nid))->fetchField();
}
......
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