When you export a feed importer and then try to import it, if the content type doesn't exist on the site you are importing the feed importer to, it will simply create a completely blank feed importer. Is there a way we can make it smarter to alert the user that the content type and/or the fields are not correctly set in the content type?

Seems like a common mistake. Took me a bit to figure out. Thanks.

Members fund testing for the Drupal project. Drupal Association Learn more


MegaChriz’s picture

I can confirm that when importing an importer using admin/structure/feeds/import, there is no alert about a non-existing content type and that on the mapping page some of the targets say "missing". In my case, the created importer is not completely "blank". All the "settings" (basic settings, fetcher settings, etc.) are still there. It's just the mapping that can be qualified as "blank". I agree a warning message would be nice here.

Pravin Ajaaz’s picture

Priority: Normal » Critical
twistor’s picture

Version: 7.x-2.0-alpha8 » 7.x-2.x-dev
Priority: Critical » Normal
Issue tags: -import

We should do some validation.

Checking the content type would be a good start. I don't think we should validate that all of the fields exist, since the missing mapping is fine.

MegaChriz’s picture

Status: Active » Needs review
5.84 KB
FAILED: [[SimpleTest]]: [MySQL] 9,119 pass(es), 7 fail(s), and 2 exception(s). View

Here is a first step at this.

  • Two methods are added to FeedsConfigurable:
    • getConfigAllowedValues():
      This allows Feeds plugins to set the allowed values per config key. This is handy for the processor's bundle setting and - when #2529538: Generic entity language support. is done - for the processor's language setting.
    • validateConfig():
      This allows Feeds plugins to validate the config. Plugins implementing this method should return an array of error messages.
  • FeedsProcessor implements getConfigAllowedValues() to set allowed values for the bundle setting.
  • FeedsImporter implements validateConfig() to execute the same method on the fetcher, parser and processor that it contains.
  • The configuration is validated on every feeds_ui_edit_page() call, thus on every importer config page.
  • The configuration is validated when importing an importer.
  • The config form for FeedsProcessor is modified to always show the current bundle setting, even if that points to a non-existing bundle. When the current set bundle does not exists, the option label is prefixed with "Unknown bundle".

Caveats, further improvements

  • When a setting is validated on allowed values, the error message refers to the config key instead of the config label. The config key is not translatable.
  • There might be some overlap between the methods validateConfig() and configFormValidate().
  • The check for plugin availibity now happens only when importing an importer. Because it is part of validation, maybe it should be moved to validateConfig().
  • Automated tests.

Suggestions and feedback are welcome!

Status: Needs review » Needs work

The last submitted patch, 4: feeds-validate-config-2320781-4.patch, failed testing.

MegaChriz’s picture

Status: Needs work » Needs review
5.87 KB
PASSED: [[SimpleTest]]: [MySQL] 9,126 pass(es). View
595 bytes

Some of the test failures were caused by a bug in the test "FeedsUIUserInterfaceTestCase". I've fixed that in #2574789: Wrong processor settings set in FeedsUIUserInterfaceTestCase::testImporterImport().

Another bug in the patch from #4 was that all importers you were trying to import became invalid, because form_error() was called regardless if there were errors or not. This is fixed in the attached patch. Caveats noted in #4 still apply.

MegaChriz’s picture

Title: When importing a feed importer, if content type does not exist, it should not create a blank feed importer » Validate feed importer configuration: check for invalid bundle and invalid language
13.55 KB
12.93 KB

This patch does the following in addition of the previous patch:

  1. The method FeedsConfigurable::getConfigAllowedValues() is removed because the error message for an invalid config option would refer to the untranslatable config key instead of config label.
  2. The check for plugin availability is moved to FeedsImporter::validateConfig().
  3. Validation is added for the processor's language setting.
  4. Automated tests are added that check if warnings are displayed on the importer configuration pages in case of invalid configuration, and when importing an importer. The following cases have been covered for both the UI and importing an importer:
    • Invalid plugin.
    • Invalid bundle.
    • Invalid processor language.

All caveats reported in #4 are handled with the patch except the following (minor) one:

There might be some overlap between the methods validateConfig() and configFormValidate().

Status: Needs review » Needs work

The last submitted patch, 7: feeds-validate-config-2320781-7.patch, failed testing.

MegaChriz’s picture

Status: Needs work » Needs review
14.54 KB
655 bytes

Oops, accidently showed an error message of an unavailable plugin when the plugin class was *not* an instance of FeedsMissingPlugin. Should be the opposite, of course!

MegaChriz’s picture

Issue tags: +validation
MegaChriz’s picture

I hope that this will make it into the Feeds 7.x-2.0-beta4 release.

MegaChriz’s picture

MegaChriz’s picture

Noticed an issue with validating the selected language on the importer: every language was reported as invalid, even LANGUAGE_NONE! This issue is new though, it did not occur before the changes from #2788125: FeedsProcessor not respecting bundle i18n language settings.
Changed language validation to use the new languageOptions() method, introduced into that same issue.

Other then that, I think this is ready.

MegaChriz’s picture

Oops, noted a small mistake in last patch. Should have been catched by the tests though.

The last submitted patch, 13: feeds-validate-config-2320781-13.patch, failed testing.

MegaChriz’s picture

  • MegaChriz committed f9df9f0 on 7.x-2.x
    Issue #2320781 by MegaChriz: Added validation for feed importer...
MegaChriz’s picture

Status: Needs review » Fixed

Committed #16.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.