Hi,
I have been fiddling around with these hooks all day and night!
I am trying to add a simple hooks to outgoing and incoming e-mails. My main concern right now are the outgoing hooks. Basically what I want to do is alter the Body of the e-mail when a user clicks "Compose" in the Emails section and then writes the email and clicks "Send". My understanding is that Send is kind of like the "Save" event and somewhere in there the e-mail is queued up with the email manager.
Emails are currently sending just fine, but I cannot for the life of me figure out how to change the text before the email is sent. Here is my hook code (custome/modules/Emails/logic_hooks.php):
In my translate include, I am simply trying to change the body of the e-mail at this point. I am using $bean->description. I have discovered that the entry is inserted in to the emails_text table BEFORE the "before_save" event is called! This breaks the paradigm and needs to be fixed, but there are clearly other issues as well. Here is my translate code:PHP Code:<?php
$hook_array = array();
$hook_array['before_save'] = array();
$hook_array['before_save'][] = array(
1, // version
'Translate emails!', // hook label
'custom/include/language/Translate.php', // include file
'TranslateEmail', // class
'translate' // function to call
);
This code successfully updates the database (which also proves that inserting to emails_text breaks paradigm)! Yay! However, it does not change the text of the e-mail before it is sent, or before it is shows up in my Sent Mail folder. The e-mail still contains the original text, instead of what it should contain, "changed text". The expected result is this:PHP Code:<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class TranslateEmail
{
function translate(&$bean, $event, $arguments)
{
// update the database because sugar already submits the email text
$result = $bean->db->query('UPDATE emails_text SET description="' . addslashes('changed text') . '" WHERE email_id="' . $bean->id . '"');
$GLOBALS['log']->fatal(print_r($result, true));
$bean->name .= 'changed name';
$bean->description = 'a second change';
$bean->description_html = 'a second change';
}
}
1. The table emails_text contains the entry text "a second change"
2. The addresses listed in the "TO" section receive an e-mail that says "a second change"
Neither of the 2 conditions above are met. However, I can successfully change the subject line that is displayed in the sugar "Sent Items" folder, it is not received with the updates subject line.
Based on hours spend searching the Internet for any insight, I would like to add a few notes:
1. All help is appreciated, HOWEVER
2. Responding with a 1-liner that links to a project that does this, or "this doesn't work in CE" is not going to help me gain a deeper understanding of SugarCRM
3. If there are multiple unintended bugs here, I would be happy to assist someone in opening bug reports for each of them
4. After this issue is resolved I would like to contribute my translation text which can easily be applied to any module
5. YES, I am aware that there is a translation extension, but to my knowledge is doesn't do this, and mine will eventually use Google Translate (already written) and it supports any HTML input
Thanks
Brian Cullinan


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks