Can a 'before' logic hook stop processing a bean

Hi,

I'm writing a logic hook to pre-process emails being imported via the SNIP email archiving feature.

I'm using the before_email_import logic hook but I've also tested it for the more generic before_save logic hook in the emails module.

Basically, I have a condition in the hook to check emails before they are imported and if certain conditions are met, to not import the email. The thing is, I don't want to return an error - I just want it to accept the email and not perform the import into the database.

If I throw an API exception or even just use die(), then sugar's SNIP server receives a non-successful message (I assume from it's behaviour) and retries a few times before giving up. 

Due to the amount of emails being processed, I want to avoid importing the emails and having to clean them up afterwards using something like a scheduler. Also, I can't alter what is being sent into the SNIP server and so filter beforehand.

Any suggestions welcome.

Steve

Parents
  • Hey,

    What I understood you are looking for is to skip importing of few emails based upon few conditions.

    eventually, before_save can't stop saving anyway, until you make a die and your die will throw an error.

    The only way, i can see put your code in this way.

    1) Create an after save hook rather than before save.

    2) On basis of all of your conditions, you can delete this recently import email via mark_deleted function, so ideally it is going to save your time to delete by yourself, this process will be internally managed by Sugar itself this way.

    Hope that helps.

Reply
  • Hey,

    What I understood you are looking for is to skip importing of few emails based upon few conditions.

    eventually, before_save can't stop saving anyway, until you make a die and your die will throw an error.

    The only way, i can see put your code in this way.

    1) Create an after save hook rather than before save.

    2) On basis of all of your conditions, you can delete this recently import email via mark_deleted function, so ideally it is going to save your time to delete by yourself, this process will be internally managed by Sugar itself this way.

    Hope that helps.

Children