diff --git a/feeds.module b/feeds.module index cac8fc4..a38643a 100644 --- a/feeds.module +++ b/feeds.module @@ -407,9 +407,9 @@ function feeds_admin_paths() { * Menu loader callback. */ function feeds_importer_load($id) { - $feed = feeds_importer($id); - if ($feed->doesExist()) { - return $feed; + $importer = feeds_importer($id); + if ($importer->doesExist()) { + return $importer; } return FALSE; } diff --git a/feeds_ui/feeds_ui.test b/feeds_ui/feeds_ui.test index e0a56bd..2f79714 100644 --- a/feeds_ui/feeds_ui.test +++ b/feeds_ui/feeds_ui.test @@ -162,11 +162,11 @@ class FeedsUIUserInterfaceTestCase extends FeedsWebTestCase { } /** - * Edit an importer configuration + * Edits an importer configuration. * - * @param $name + * @param string $name * The natural name of the feed. - * @param $id + * @param string $id * The persistent id of the feed. */ protected function doEditFeedsConfiguration($name = 'Syndication', $id = 'syndication') { diff --git a/includes/FeedsConfigurable.inc b/includes/FeedsConfigurable.inc index 48e2494..c305f6a 100644 --- a/includes/FeedsConfigurable.inc +++ b/includes/FeedsConfigurable.inc @@ -91,6 +91,10 @@ abstract class FeedsConfigurable { /** * Determine whether this object is persistent. + * + * @return bool + * True if the object is persistent. + * False otherwise. */ public function doesExist() { return ($this->export_type == FEEDS_EXPORT_NONE) ? FALSE : TRUE; @@ -98,6 +102,10 @@ abstract class FeedsConfigurable { /** * Determine whether this object is enabled. + * + * @return bool + * True if the object is enabled. + * False otherwise. */ public function isEnabled() { return $this->disabled ? FALSE : TRUE; diff --git a/includes/FeedsSource.inc b/includes/FeedsSource.inc index 64a0be1..6305188 100644 --- a/includes/FeedsSource.inc +++ b/includes/FeedsSource.inc @@ -707,21 +707,52 @@ class FeedsSource extends FeedsConfigurable { } /** + * Checks whether or not the source configuration is valid. + * + * @return bool + * True if it is valid. + * False otherwise. + */ + public function hasValidConfiguration() { + // If there is no feed nid given, there must be no content type specified. + $standalone = empty($this->feed_nid) && empty($this->importer->config['content_type']); + + // If there is a feed nid given, there must be a content type specified. + $attached = !empty($this->feed_nid) && !empty($this->importer->config['content_type']); + + if ($standalone || $attached) { + return TRUE; + } + return FALSE; + } + + /** + * Overrides FeedsConfigurable::doesExist(). + * + * Checks the following: + * - If the importer is persistent (= defined in code or DB). + * - If the source is persistent (= defined in DB). + */ + public function doesExist() { + return $this->importer->doesExist() && parent::doesExist(); + } + + /** * Only return source if configuration is persistent and valid. * * @see FeedsConfigurable::existing(). */ public function existing() { - // If there is no feed nid given, there must be no content type specified. - // If there is a feed nid given, there must be a content type specified. - // Ensure that importer is persistent (= defined in code or DB). - // Ensure that source is persistent (= defined in DB). - if ((empty($this->feed_nid) && empty($this->importer->config['content_type'])) || - (!empty($this->feed_nid) && !empty($this->importer->config['content_type']))) { - $this->importer->existing(); - return parent::existing(); - } - throw new FeedsNotExistingException(t('Source configuration not valid.')); + // Ensure that the source configuration is valid. + if (!$this->hasValidConfiguration()) { + throw new FeedsNotExistingException(t('Source configuration not valid.')); + } + + // Ensure that the importer is persistent (= defined in code or DB). + $this->importer->existing(); + + // Ensure that the source is persistent (= defined in DB). + return parent::existing(); } /** diff --git a/tests/feeds_scheduler.test b/tests/feeds_scheduler.test index 01c4393..fb605a8 100644 --- a/tests/feeds_scheduler.test +++ b/tests/feeds_scheduler.test @@ -25,7 +25,7 @@ class FeedsSchedulerTestCase extends FeedsWebTestCase { // Initialize scheduling. $init = $this->initSyndication(); - // Disable syndication feed so cron doesn't import nodes + // Disable syndication feed so cron doesn't import nodes. $this->drupalLogin($this->admin_user); $edit = array( 'syndication' => FALSE,