solspace / craft-calendar

Calendar for Craft: The most reliable and powerful event management plugin for Craft.
http://docs.solspace.com/craft/calendar/v5
Other
15 stars 16 forks source link

Event Save events are not fired during FeedMe import #38

Closed rtgoodwin closed 3 years ago

rtgoodwin commented 3 years ago

I wrote a small module to hook into Event save events, which works fine when using the CP, but does not seem to fire/activate EVENT_AFTER_SAVE when FeedMe creates/updates an element. My goal is to be able to detect the same action (and isNew) in both cases.

Steps to reproduce

  1. Hook the EVENT_AFTER_SAVE in module/plugin
  2. Save an event manually; event is captured.
  3. Import an event through FeedMe, event is not captured. The FeedMe STEP event for save does not make the same element details available (including isNew) it seems either.

Expected behavior

Able to catch event save/update in the same fashion both ways.

Craft & Plugin Info (please complete the following information):

Additional context

rtgoodwin commented 3 years ago

If this is as intended, I wonder if there is a good way to grab the element data and do the same query FeedMe does to detect the duplicate entry (given I know the criteria). Thanks!

gustavs-gutmanis commented 3 years ago

I think that for this to work with FeedMe you need to use the Element service after-save event. Be sure to check that the saved element is an instance of Submission before doing what you're doing.

rtgoodwin commented 3 years ago

Wouldn't the element be a (Solspace) Calendar Event element? In my messing around I couldn't quite tell what the element attached to the FeedMe event was, but I think it was one. (Though perhaps with the core Element event save it would be different?). My flow is:

@@startuml • Untitled-10 — Untitled (Workspace) 2021-05-13 10-30-08

gustavs-gutmanis commented 3 years ago

Yes, sorry, I thought this was in the freeform repo 😬

gustavs-gutmanis commented 3 years ago

I wanted to also mention that if you were to use Freeform, you could create Calendar events automatically with a simple form element connection configuration.

rtgoodwin commented 3 years ago

@gustavs-gutmanis Noted :) I have paid for Sprout Forms, then Formie which had some features I really liked, and so moving to Freeform would be yet another move (although as you point out, would make this particular thing much easier :) ). I can consider it though! What I'm trying to do is let users submit an event, without directly writing to the Calendar. The form of course is a means to do that, though I looked at Front End editing/submission and thought perhaps I could make a "secure enough" way for guests to do that...perhaps not :)

Ultimately this particular plugin was simply to send a mail to the submitter if their form submission made it to an actual new enabled Event (Event isNew and Event->enabled), because I have FeedMe set to Enable the Event if certain criteria are met (which I manage through a transform in Element API between the Entry and FeedMe). Does that make sense? And we can close this issue if needed, though I would like to verify the event you mention above first.

rtgoodwin commented 3 years ago

Actually installed FreeForm and looked and see that you CAN hook the submission before save and change it, but saw the note about limitations of using the Submission->Event integration (specifically no recurring events).

If I hook the Submission before save (thus before the Event creation) could I (at my own risk!) parse and insert a recurrence rule to the Event? The source code for the Connection doesn't seem to allow it currently, but maybe there's another way?

I'm trying to not have to query and edit the Event entry if possible (and deal with queuing etc); I just don't know if Freeform->Calendar pipeline would prevent me doing that in a meaningful way.

gustavs-gutmanis commented 3 years ago

Glad you tried it @rtgoodwin,

There is an event which happens right before an element connection is made, here's the documentation link.

You could hook into that and do your adjustments to the Event element there and it will get saved right after with your changes applied.

rtgoodwin commented 3 years ago

Closing as answer was provided :)