Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the standalone form feed with the current user #138

Open
oriolroger opened this issue Jul 20, 2023 · 7 comments
Open

Run the standalone form feed with the current user #138

oriolroger opened this issue Jul 20, 2023 · 7 comments

Comments

@oriolroger
Copy link

One of the major changes in the latest Drupal 7 versions was that the imports are ran as the user 1, when using the standalone import form (see here).

We woder if there is any option to disable this, and run the import with the current user, like it was 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!

@argiepiano
Copy link
Contributor

argiepiano commented Jul 20, 2023

I may not be understanding your question, but can't you actually tell Feeds what Author to use when create the nodes (or other entities)? This is done in the Processor step in the UI

Screen Shot 2023-07-20 at 10 09 50 AM

EDIT: OK, reread your question, and read the attached article - I understand your question now and see that this was changed in D7 as well. I think it'd be good to allow that option to revert this change.

@oriolroger
Copy link
Author

oriolroger commented Jul 20, 2023

Sorry, that's my fault, the explaining was not very accurate. This has to be with the new FeedsAccountSwitcher class, that as far as I understand, it changes the current user to "root" (uid = 1), while the whole import process is running in the background. I see this in function switchTo($account), in the FeedsAccountSwitcher class.

I need to avoid this, because I have to store the current user uid in the database while the importing is running. Currently I'm patching the Feeds module, commenting the line $this->switchAccount() in FeedsSource.inc:

  protected function acquireLock() {
    if (!lock_acquire("feeds_source_{$this->id}_{$this->feed_nid}", 60.0)) {
      throw new FeedsLockException(t('Cannot acquire lock for source @id / @feed_nid.', array('@id' => $this->id, '@feed_nid' => $this->feed_nid)));
    }
    // Switch account.
    //$this->switchAccount();
  }

I'd like to know if there's an option to do this, without having to patch the module.

Many thanks again!

@argiepiano
Copy link
Contributor

Yes, I see that now. From what I can tell, that switch is hard-coded, so there is no current way to avoid the switch. But it looks like it may be possible to add a configuration option to the UI to skip this change - that shouldn't be too difficult, I think.

@MegaChriz
Copy link
Contributor

See also this issue on the Feeds issue queue on drupal.org: https://www.drupal.org/project/feeds/issues/3375914

I think that there is a workaround possible.

@argiepiano
Copy link
Contributor

Yes, that workaround should be possible, but it would affect all importers in your site. The D7 variable feeds_source_class is now stored in feeds.settings.json

@MegaChriz
Copy link
Contributor

Well, you could conditionally override $this->accountSwitcher. 🙂 You have access to the importer ID in the constructor of classes extending FeedsSource.

@oriolroger
Copy link
Author

Thank you both for your answers. I'll take a look and try to add a UI config option to disable the user switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants