[rt-devel] use utf8 in scrip action

Emmanuel Lacour elacour at easter-eggs.com
Thu Jan 15 10:40:58 EST 2015


Maybe something I'm doing badly. I have a scrip action Foo.pm which will
work on some CF with non-ascii names.


Here is part of the code:


--------------------snip-----------------------
package RT::Action::StartNextAction;

use strict;
use warnings;
use base qw(RT::Action);
use utf8;

sub Commit {
    my $self = shift;

    ...

    my $next_phone = ...;

    my $cf_clones;
    my $ActionCFs = $Ticket->CustomFields;
    while ( my $CustomField = $ActionCFs->Next ) {
        my $values = $Ticket->CustomFieldValues($CustomField->id);
        next unless ( $values && $values->Count );
        $cf_clones->{$CustomField->Name} = $values->First->Content;
    }

    if ($next_phone && $next_phone ne $cf_clones->{'Numéro de
télephone'} ) {
        $cf_clones->{'Numéro de télephone'} = $next_phone;
        $cf_clones->{'Nom'} = '';
        $cf_clones->{'Adresse email'} = '';
    }

   my $NewAction = RT::Ticket->new( $self->CurrentUser );
   $NewAction->Create ( ...);

   foreach my $field_name (keys %{$cf_clones} ) {
        $NewAction->AddCustomFieldValue( Field => $field_name, Value =>
$cf_clones->{$field_name} );
    }
-----------------------snip--------------


The ->AddCustomFieldValue breaks when $field_name = 'Numéro de
télephone'; (PostgreSQL does not see here UTF-8 in the produced select)


If I replace this foreach by:

    foreach my $field_name (keys %{$cf_clones} ) {
        next if ( $field_name eq 'Numéro de télephone' );
        $NewAction->AddCustomFieldValue( Field => $field_name, Value =>
$cf_clones->{$field_name} );
    }
    $NewAction->AddCustomFieldValue( Field => 'Numéro de télephone',
Value => $cf_clones->{'Numéro de télephone'} );


it works !!!

any perl utf8 lover can explain the right way to do this?


If of any use (a bug?) here is the PG error:

DBD::Pg::st execute failed: ERROR:  invalid byte sequence for encoding
"UTF8": 0xe9726f at /usr/share/perl5/DBIx/SearchBuilder/Handle.pm line 586.
RT::Handle=HASH(0x793ee88) couldn't execute the query 'SELECT main.*
FROM CustomFields main JOIN ObjectCustomFields ObjectCustomFields_1  ON
( ObjectCustomFields_1.CustomField = main.id )  WHERE
(ObjectCustomFields_1.ObjectId IN ('6', '0')) AND (main.LookupType IN
('RT::Queue-RT::Ticket')) AND (LOWER(main.Name) = 'numéro de télephone')
 ORDER BY main.Disabled ASC, ObjectCustomFields_1.ObjectId DESC,
main.SortOrder ASC, main.id ASC  LIMIT 1' at
/usr/share/perl5/DBIx/SearchBuilder/Handle.pm line
599#012#011DBIx::SearchBuilder::Handle::SimpleQuery('RT::Handle=HASH(0x793ee88)',
'SELECT main.* FROM CustomFields main JOIN ObjectCustomFields ...')
called at /usr/share/perl5/DBIx/SearchBuilder.pm line
239#012#011DBIx::SearchBuilder::_DoSearch('RT::CustomFields=HASH(0x7f64c68)')
called at /srv/rt/rt/sbin/../lib/RT/SearchBuilder.pm line
985#012#011RT::SearchBuilder::_DoSearch('RT::CustomFields=HASH(0x7f64c68)')
called at /usr/share/perl5/DBIx/SearchBuilder.pm line
507#012#011DBIx::SearchBuilder::Next('RT::CustomFields=HASH(0x7f64c68)')
called at /srv/rt/rt/sbin/../lib/RT/CustomFields.pm line
393#012#011RT::CustomFields::Next('RT::CustomFields=HASH(0x7f64c68)')
called at /usr/share/perl5/DBIx/SearchBuilder.pm line
568#012#011DBIx::SearchBuilder::First('RT::CustomFields=HASH(0x7f64c68)') called
at /srv/rt/rt/sbin/../lib/RT/CustomField.pm line
579#012#011RT::CustomField::LoadByName('RT::CustomField=HASH(0x7b35160)', 'Name',
'Num\x{e9}ro de t\x{e9}lephone', 'LookupType', 'RT::Queue-RT::Ticket',
'ObjectId', 6, 'IncludeGlobal', 1, ...) called at
/srv/rt/rt/sbin/../lib/RT/Ticket.pm line
2986#012#011RT::Ticket::LoadCustomFieldByIdentifier('RT::Ticket=HASH(0x7b9cf30)',
'Num\x{e9}ro de t\x{e9}lephone') called at
/srv/rt/rt/sbin/../lib/RT/Record.pm line
1966#012#011RT::Record::_AddCustomFieldValue('RT::Ticket=HASH(0x7b9cf30)',
'Field', 'Num\x{e9}ro de t\x{e9}lephone', 'Value', 0613260760) called at
/srv/rt/rt/sbin/../lib/RT/Record.pm line
1952#012#011RT::Record::AddCustomFieldValue('RT::Ticket=HASH



-- 
Easter-eggs                              Spécialiste GNU/Linux
44-46 rue de l'Ouest  -  75014 Paris  -  France -  Métro Gaité
Phone: +33 (0) 1 43 35 00 37    -   Fax: +33 (0) 1 43 35 00 76
mailto:elacour at easter-eggs.com  -   http://www.easter-eggs.com


More information about the rt-devel mailing list