Run the standalone form feed with the current user

Created on 20 July 2023, over 1 year ago

Problem/Motivation

One of the major changes in version 7.x-2.0-beta5 was that the Imports are ran as the user 1, when using the standalone import form ( see here ).

Is there any option to disable this, and run the import with the current user, like before? We're experiencing some problems, because we need the current user to store some data on the database, during the parse of the feed.

Thanks!

💬 Support request
Status

Active

Component

Code

Created by

🇪🇸Spain oriolroger

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @oriolroger
  • 🇳🇱Netherlands megachriz

    No, I think there isn't a way to disable it.

    One possible workaround is perhaps the following:

    1. Create a dummy class implementing FeedsAccountSwitcherInterface.
    2. Create a class extending FeedsSource. Override the constructor and set $this->accountSwitcher to an instance of your class that implements FeedsAccountSwitcherInterface.
    3. Set the variable "feeds_source_class" to the name of your class that extends FeedsSource.

    Note that the current user will then be anonymous during cron imports. That's why the account switch was implemented: to make importing through the UI consistent with importing through cron.

    An other way to solve your issue could perhaps be the following:

    1. Attach your importer to a content type.
    2. When saving the feed node, save the current user ID on a field of that node. You'll then should have access to that user ID when loading the feed node.
    3. Maybe you need to implement form alters for the import form that update the user ID on the feed node.
  • 🇳🇱Netherlands megachriz

    But I'm open to adding an option on the feeds importer to specify the user to switch to or to not switch at all. But the option to disable user switches should note that imports will run as user 0 on cron imports when using the standalone form.

Production build 0.71.5 2024