Sorry I couldnāt really understand how these local things work.
So, if Iām correct, I need to put SendEmail_Local.pm somewhere (local/lib -
??? directory) so that the parts of the code inside SendEmail_Local.pm
overrides corresponding code from the āoriginalā lib directory.
But what about the name of the subroutine TemplateObj??? How does this work?
Does RT try to override subroutine with the same name??
Thanks,
DimitryFrom: Ruslan U. Zakirov [mailto:cubic@acronis.ru]
Sent: Tuesday, May 11, 2004 8:14 AM
To: Dimitry Faynerman
Cc: rt-users@lists.fsck.com
Subject: Re: FW: [rt-users] choosing template on the fly
I like your idea and solution, but I refactored it a little into _Local
overlay file which doesnāt touch Prepare sub. It use TemplateObj sub
cause it simple and right places to do such override.
Iāve done only use_ok test. Could you test it? Then I or you can fill it
in wiki page.
Comment about strange code below.
Best regards. Ruslan.
Dimitry Faynerman wrote:
[snip]
Hereās the code:
sub Prepare {
my $self = shift;
# This actually populates the MIME::Entity fields in the Template
Object
unless ( $self->TemplateObj ) {
$RT::Logger->warning("No template object handed to $self\n");
}
# my changes start here
# Use japanese template (if exists) if user's language is japanese
my $UserObj = RT::User->new( $RT::SystemUser );
$UserObj->Load($self->TicketObj->Requestors->UserMembersObj->First->Id);
if (($self->TemplateObj) &&
((!$UserObj->Lang) || ($UserObj->Lang ne 'en'))) {
This āif conditionā will be true if $UserObj->Lang is not defined or
empty string. Refactored code has slightly different condtion.
my $rememberEnglishId = $self->TemplateObj->Id;
$self->TemplateObj->Load(
$self->TemplateObj->Name . " (" . $UserObj->Lang . ")");
if (! $self->TemplateObj->Id) {
$self->TemplateObj->Load($rememberEnglishId);
}
}
# my changes end here ===============================================
[snip]
-Dimitry