1

I have made a custom module that allows a user to upload a CSV and import it using a FeedMe feed. This all works fine, however I want to send an e-mail to the user when the import has completed.

I have this so far, but realised it doesn't work because the event doesn't have access to the user session:

Event::on(Process::class, Process::EVENT_AFTER_PROCESS_FEED, function(FeedProcessEvent $event) {                
    $email = Craft::$app->getUser()->getIdentity()->email;
    if ($event->feed->id === getenv('USER_FEED_ID')) {
        $message = new Message();
        $message->setTo($email);
        $message->setSubject("Import complete");
        $message->setHtmlBody('Data has been imported successfully');
        $message->send();
    }         
});

I've been scratching my furry head but can't think of a solution, is there any way to do this?

| improve this question | | | | |
2

As long as you have control of the CSV on upload, you could change its name to filename_test@test.test.csv (or some other properly escaped filename with the current user's email address in it). Then get the filename from the feed (must be in there somewhere) and extract the email address.

Bit of a workaround, but if it works, it works.

| improve this answer | | | | |
  • This is very creative I like it! However there may be times that another user selects a pre-uploaded CSV from another user so I'm not sure this will work for me. I will sit on it a little bit, but if it turns out this is the only way (which it seems it may be) I will give you that green tick! – user3788089 Feb 20 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.