I dont see a problem with having your Model send the email, what I
would do though is put the mail code into a service, this way you keep
mail logic out of your Model. This way for testing you can replace
your mail service easily :)

Model->signup()
{
  ModelDbTable->startTransaction()
  try
  {
    ModelDbTable->insert()
    MailService->send();
    ModelDbTable->commit()
    return true
  }
  catch( Exception )
  {
    ModelDbTable->rollBack()
    return false
  }
}

2009/2/28  <[email protected]>:
> Hey all,
>
> I'm trying to determine how I can have my Model rollback a transaction it
> made on a DB table when the calling Controller fails to send a confirmation
> mail afterwards. What is good practice? Am I approaching this in the wrong
> way perhaps? Should I send the Mail from within the Model? That just doesn't
> feel right. I'ld love to read your suggestions. Thank you in advance.
>
> In short this is what happens now in pseudo code (please read the comments
> inside the first catch, where I try to convey my point):
>
> == Controller ==
> Controller->signup()
> {
>   if( true == Model->signup() )
>   {
>     try
>     {
>       Mail->send()
>     }
>     catch( Exception )
>     {
>      // seems stupid to have the Model roll back the transaction from here,
> no?
>     }
>   }
>   else
>   {
>     // do something when Model->signup() failed
>   }
> }
>
> == Model ==
> Model->signup()
> {
>   ModelDbTable->startTransaction()
>   try
>   {
>     ModelDbTable->insert()
>     ModelDbTable->commit()
>     return true
>   }
>   catch( Exception )
>   {
>     ModelDbTable->rollBack()
>     return false
>   }
> }
>
>
> Cheers
>
> ________________________________
> Twee keer zo leuk. Deel foto's terwijl je chat met de nieuwe Messenger



-- 
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

Reply via email to