[Rt-commit] r10665 - in rt/branches/3.999-DANGEROUS: . lib lib/RT lib/RT/Interface lib/RT/Model

jesse at bestpractical.com jesse at bestpractical.com
Sat Feb 2 00:08:17 EST 2008


Author: jesse
Date: Sat Feb  2 00:08:17 2008
New Revision: 10665

Modified:
   rt/branches/3.999-DANGEROUS/   (props changed)
   rt/branches/3.999-DANGEROUS/lib/RT.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Bootstrap.pm
   rt/branches/3.999-DANGEROUS/lib/RT/CurrentUser.pm
   rt/branches/3.999-DANGEROUS/lib/RT/EmailParser.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Interface/CLI.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Interface/Web/Handler.pm
   rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm

Log:
 r76081 at pinglin:  jesse | 2008-02-02 00:07:25 -0500
 * 800 loc deleted. no loss of functionality


Modified: rt/branches/3.999-DANGEROUS/lib/RT.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT.pm	Sat Feb  2 00:08:17 2008
@@ -171,15 +171,6 @@
 
 =cut
 
-=head2 DatabaseHandle
-
-Returns the current L<database handle object RT::Handle>.
-
-
-=cut
-
-sub database_handle { return $Handle }
-
 =head2 System
 
 Returns the current L<system object RT::System>. See also

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Bootstrap.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Bootstrap.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Bootstrap.pm	Sat Feb  2 00:08:17 2008
@@ -11,105 +11,10 @@
     $self->insert_data( $RT::EtcPath . "/initialdata" );
 }
 
-=head1 METHODS
 
 
 use File::Spec;
 
-=head2 Database maintanance
-
-=head2 create_database $DBH
-
-Creates a new database. This method can be used as class method.
-
-Takes DBI handle. Many database systems require special handle to
-allow you to create a new database, so you have to use L<system_dsn>
-method during connection.
-
-Fetches type and name of the DB from the config.
-
-=cut
-
-sub create_database {
-    my $self    = shift;
-    my $dbh     = shift || die "No DBI handle provided";
-    my $db_type = RT->config->get('DatabaseType');
-    my $db_name = RT->config->get('Databasename');
-
-    #print "Creating $db_type database $db_name.\n";
-    if ( $db_type eq 'SQLite' ) {
-        return;
-    } elsif ( $db_type eq 'Pg' ) {
-
-       # XXX: as we get external DBH we don't know if RaiseError or PrintError
-       # are enabled, so we have to setup it here and restore them back
-        $dbh->do("CREATE DATABASE $db_name WITH ENCODING='UNICODE'");
-        if ($DBI::errstr) {
-            $dbh->do("CREATE DATABASE $db_name") || die $DBI::errstr;
-        }
-    } elsif ( $db_type eq 'Informix' ) {
-        local $ENV{'DB_LOCALE'} = 'en_us.utf8';
-        $dbh->do("CREATE DATABASE $db_name WITH BUFFERED LOG");
-    } else {
-        $dbh->do("CREATE DATABASE $db_name") or die $DBI::errstr;
-    }
-}
-
-=head3 drop_database $DBH [Force => 0]
-
-Drops RT's database. This method can be used as class method.
-
-Takes DBI handle as first argument. Many database systems require
-special handle to allow you to create a new database, so you have
-to use L<system_dsn> method during connection.
-
-Takes as well optional named argument C<Force>, if it's true than
-no questions would be asked.
-
-Fetches type and name of the DB from the config.
-
-=cut
-
-sub drop_database {
-    my $self = shift;
-    my $dbh  = shift || die "No DBI handle provided";
-    my %args = ( Force => 0, @_ );
-
-    my $db_type = RT->config->get('DatabaseType');
-    my $db_name = RT->config->get('Databasename');
-    my $db_host = RT->config->get('DatabaseHost');
-
-    if ( $db_type eq 'Oracle' ) {
-        print <<END;
-
-To delete the tables and sequences of the RT Oracle database by running
-    \@etc/drop.Oracle
-through SQLPlus.
-
-END
-        return;
-    }
-    unless ( $args{'Force'} ) {
-        print <<END;
-
-About to drop $db_type database $db_name on $db_host.
-WARNING: This will erase all data in $db_name.
-
-END
-        return unless _yesno();
-
-    }
-
-    #print "Dropping $db_type database $db_name.\n";
-
-    if ( $db_type eq 'SQLite' ) {
-        my $path = $db_name;
-        $path = "$RT::VarPath/$path" unless substr( $path, 0, 1 ) eq '/';
-        unlink $path or warn $!;
-        return;
-    }
-    $dbh->do( "DROP DATABASE " . $db_name ) or warn $DBI::errstr;
-}
 
 sub _yesno {
 
@@ -120,109 +25,6 @@
 
 sub insert_acl { }
 
-=head2 insert_schema
-
-=cut
-
-sub insert_schema {
-    my $self      = shift;
-    my $dbh       = shift || $self->dbh;
-    my $base_path = ( shift || $RT::EtcPath );
-    my $db_type   = RT->config->get('DatabaseType');
-
-    my $file = get_version_file( $base_path . "/schema." . $db_type );
-    unless ($file) {
-        die "Couldn't find schema file in '$base_path' dir";
-    }
-    unless ( -f $file || -r $file ) {
-        die "File '$file' doesn't exist or couldn't be read";
-    }
-
-    my (@schema);
-
-    #print "Creating database schema.\n";
-
-    open my $fh_schema, "<$file";
-
-    my $has_local = 0;
-    open my $fh_schema_local,
-        "<" . get_version_file( $RT::LocalEtcPath . "/schema." . $db_type )
-        and $has_local = 1;
-
-    my $statement = "";
-    foreach my $line ( <$fh_schema>, ( $_ = ';;' ),
-        $has_local ? <$fh_schema_local> : () )
-    {
-        $line =~ s/\#.*//g;
-        $line =~ s/--.*//g;
-        $statement .= $line;
-        if ( $line =~ /;(\s*)$/ ) {
-            $statement =~ s/;(\s*)$//g;
-            push @schema, $statement;
-            $statement = "";
-        }
-    }
-    close $fh_schema;
-    close $fh_schema_local;
-
-    local $SIG{__WARN__} = sub { };
-    my $is_local = 0;    # local/etc/schema needs to be nonfatal.
-    $dbh->begin_work or die $dbh->errstr;
-    foreach my $statement (@schema) {
-        if ( $statement =~ /^\s*;$/ ) { $is_local = 1; next; }
-
-     #        #print "Executing SQL:\n$statement\n" if defined $args{'debug'};
-        my $sth = $dbh->prepare($statement) or die $dbh->errstr;
-        unless ( $sth->execute or $is_local ) {
-            die "Problem with statement:\n$statement\n" . $sth->errstr;
-        }
-    }
-    $dbh->commit or die $dbh->errstr;
-
-    #print "Done setting up database schema.\n";
-}
-
-=head1 get_version_file
-
-Takes base name of the file as argument, scans for <base name>-<version> named
-files and returns file name with closest version to the version of the RT DB.
-
-=cut
-
-sub get_version_file {
-    my $base_name = shift;
-
-    require File::Glob;
-    my @files = File::Glob::bsd_glob("$base_name*");
-    return '' unless @files;
-
-    my %version = map { $_ =~ /\.\w+-([-\w\.]+)$/; ( $1 || 0 ) => $_ } @files;
-    my $db_version = Jifty->handle->database_version;
-
-    #print "Server version $db_version\n";
-    my $version;
-    foreach ( reverse sort cmp_version keys %version ) {
-        if ( cmp_version( $db_version, $_ ) >= 0 ) {
-            $version = $_;
-            last;
-        }
-    }
-
-    return defined $version ? $version{$version} : undef;
-}
-
-sub cmp_version($$) {
-    my ( $a, $b ) = (@_);
-    my @a = split /[^0-9]+/, $a;
-    my @b = split /[^0-9]+/, $b;
-    for ( my $i = 0; $i < @a; $i++ ) {
-        return 1 unless defined $b[$i];
-        return $a[$i] <=> $b[$i] if $a[$i] <=> $b[$i];
-    }
-    return 0 if @a == @b;
-    return -1;
-}
-
 =head2 insert_initial_data
 
 =cut

Modified: rt/branches/3.999-DANGEROUS/lib/RT/CurrentUser.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/CurrentUser.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/CurrentUser.pm	Sat Feb  2 00:08:17 2008
@@ -159,47 +159,6 @@
 
 }
 
-=head2 Authenticate
-
-Takes $password, $Created and $nonce, and returns a boolean value
-representing whether the authentication succeeded.
-
-If both $nonce and $Created are specified, validate $password against:
-
-    encode_base64(sha1(
-        $nonce .
-        $Created .
-        sha1_hex( "$username:$realm:$server_pass" )
-    ))
-
-where $server_pass is the md5_hex(password) digest stored in the
-database, $Created is in ISO time format, and $nonce is a random
-string no longer than 32 bytes.
-
-=cut
-
-sub authenticate {
-    my ( $self, $password, $Created, $nonce, $realm ) = @_;
-
-    require Digest::MD5;
-    require Digest::SHA1;
-    require MIME::Base64;
-
-    my $username    = $self->user_object->name                or return;
-    my $server_pass = $self->user_object->__value('password') or return;
-    my $auth_digest = MIME::Base64::encode_base64(
-        Digest::SHA1::sha1(
-                  $nonce 
-                . $Created
-                . Digest::MD5::md5_hex("$username:$realm:$server_pass")
-        )
-    );
-
-    chomp($password);
-    chomp($auth_digest);
-
-    return ( $password eq $auth_digest );
-}
 
 sub has_right {
     my $self = shift;

Modified: rt/branches/3.999-DANGEROUS/lib/RT/EmailParser.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/EmailParser.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/EmailParser.pm	Sat Feb  2 00:08:17 2008
@@ -281,114 +281,6 @@
     RT::I18N::set_mime_entity_to_encoding( $self->{'entity'}, 'utf-8' );
 }
 
-=head2 ParseCcAddressesFromHead HASHREF
-
-Takes a hashref object containing queue_obj, Head and current_user objects.
-Returns a list of all email addresses in the To and Cc 
-headers b<except> the current Queue\'s email addresses, the CurrentUser\'s 
-email address and anything that the RT->config->get('RTAddressRegexp') matches.
-
-=cut
-
-sub parse_cc_addresses_from_head {
-
-    my $self = shift;
-
-    my %args = (
-        queue_obj   => undef,
-        current_user => undef,
-        @_
-    );
-
-    my (@Addresses);
-
-    my @ToObjs = Mail::Address->parse( $self->head->get('To') );
-    my @CcObjs = Mail::Address->parse( $self->head->get('Cc') );
-
-    foreach my $AddrObj ( @ToObjs, @CcObjs ) {
-        my $Address = $AddrObj->address;
-        my $user = RT::Model::User->new( current_user => RT->system_user );
-        $Address = $user->canonicalize_email($Address);
-        next if ( lc $args{'CurrentUser'}->email            eq lc $Address );
-        next if ( lc $args{'queue_obj'}->correspond_address eq lc $Address );
-        next if ( lc $args{'queue_obj'}->comment_address    eq lc $Address );
-        next if ( $self->is_rt_address($Address) );
-
-        push( @Addresses, $Address );
-    }
-    return (@Addresses);
-}
-
-=head2 parse_sender_address_from_head
-
-Takes a MIME::Header object. Returns a tuple: (user at host, friendly name) 
-of the From (evaluated in order of Reply-To:, From:, Sender)
-
-=cut
-
-sub parse_sender_address_from_head {
-    my $self = shift;
-
-    #Figure out who's sending this message.
-    my $From = $self->head->get('Reply-To')
-        || $self->head->get('From')
-        || $self->head->get('Sender');
-    return ( $self->parse_address_from_header($From) );
-}
-
-=head2 parse_errors_to_address_from_head
-
-Takes a MIME::Header object. Return a single value : user at host
-of the From (evaluated in order of Errors-To:,Reply-To:, From:, Sender)
-
-=cut
-
-sub parse_errors_to_address_from_head {
-    my $self = shift;
-
-    #Figure out who's sending this message.
-
-    foreach my $header ( 'Errors-To', 'Reply-To', 'From', 'Sender' ) {
-
-        # If there's a header of that name
-        my $headerobj = $self->head->get($header);
-        if ($headerobj) {
-            my ( $addr, $name )
-                = $self->parse_address_from_header($headerobj);
-
-            # If it's got actual useful content...
-            return ($addr) if ($addr);
-        }
-    }
-}
-
-=head2 parse_address_from_header ADDRESS
-
-Takes an address from $self->head->get('Line') and returns a tuple: user at host, friendly name
-
-=cut
-
-sub parse_address_from_header {
-    my $self = shift;
-    my $Addr = shift;
-
-    # Perl 5.8.0 breaks when doing regex matches on utf8
-    Encode::_utf8_off($Addr) if $] == 5.008;
-    my @Addresses = Mail::Address->parse($Addr);
-
-    my $AddrObj = $Addresses[0];
-
-    unless ( ref($AddrObj) ) {
-        return ( undef, undef );
-    }
-
-    my $name = ( $AddrObj->phrase || $AddrObj->comment || $AddrObj->address );
-
-    #Lets take the from and load a user object.
-    my $Address = $AddrObj->address;
-
-    return ( $Address, $name );
-}
 
 =head2 IsRTaddress ADDRESS
 
@@ -565,9 +457,4 @@
     File::Path::rmtree( [ @{ $self->{'AttachmentDirs'} } ], 0, 1 );
 }
 
-eval "require RT::EmailParser_Vendor";
-die $@ if ( $@ && $@ !~ qr{^Can't locate RT/EmailParser_Vendor.pm} );
-eval "require RT::EmailParser_Local";
-die $@ if ( $@ && $@ !~ qr{^Can't locate RT/EmailParser_Local.pm} );
-
 1;

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Interface/CLI.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Interface/CLI.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Interface/CLI.pm	Sat Feb  2 00:08:17 2008
@@ -154,111 +154,7 @@
 
     # }}}
 
-    # {{{ sub loc
-
-=head2 loc
-
-  Synonym of $CurrentUser->_().
-
-=cut
-
-    sub loc {
-        die "No current user yet"
-            unless $CurrentUser ||= RT::CurrentUser->new;
-        return $CurrentUser->_(@_);
-    }
-
-    # }}}
 
 }
 
-# {{{ sub GetMessageContent
-
-=head2 GetMessageContent
-
-Takes two arguments a source file and a boolean "edit".  If the source file
-is undef or "", assumes an empty file.  Returns an edited file as an 
-array of lines.
-
-=cut
-
-sub get_message_content {
-    my %args = (
-        Source      => undef,
-        Content     => undef,
-        Edit        => undef,
-        current_user => undef,
-        @_
-    );
-    my $source = $args{'Source'};
-
-    my $edit = $args{'Edit'};
-
-    my $currentuser = $args{'CurrentUser'};
-    my @lines;
-
-    use File::Temp qw/ tempfile/;
-
-    #Load the sourcefile, if it's been handed to us
-    if ($source) {
-        open( SOURCE, "<$source" );
-        @lines = (<SOURCE>);
-        close(SOURCE);
-    } elsif ( $args{'Content'} ) {
-        @lines = split( '\n', $args{'Content'} );
-    }
-
-    #get us a tempfile.
-    my ( $fh, $filename ) = tempfile();
-
-    #write to a tmpfile
-    for (@lines) {
-        print $fh $_;
-    }
-    close($fh);
-
-    #Edit the file if we need to
-    if ($edit) {
-
-        unless ( $ENV{'EDITOR'} ) {
-            Jifty->log->fatal( 'No $EDITOR variable defined' . "\n" );
-            return undef;
-        }
-        system( $ENV{'EDITOR'}, $filename );
-    }
-
-    open( READ, "<$filename" );
-    my @newlines = (<READ>);
-    close(READ);
-
-    unlink($filename) unless ( debug() );
-    return ( \@newlines );
-
-}
-
-# }}}
-
-# {{{ sub debug
-
-sub debug {
-    my $val = shift;
-    my ($debug);
-    if ($val) {
-        Jifty->log->debug( $val . "\n" );
-        if ($debug) {
-            print STDERR "$val\n";
-        }
-    }
-    if ($debug) {
-        return (1);
-    }
-}
-
-# }}}
-
-eval "require RT::Interface::CLI_Vendor";
-die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Interface/CLI_Vendor.pm} );
-eval "require RT::Interface::CLI_Local";
-die $@ if ( $@ && $@ !~ qr{^Can't locate RT/Interface/CLI_Local.pm} );
-
 1;

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Interface/Email.pm	Sat Feb  2 00:08:17 2008
@@ -190,36 +190,6 @@
     return ( $ReturnPath =~ /<>/ );
 }
 
-=head2 is_rt_address ADDRESS
-
-Takes a single parameter, an email address.
-Returns true if that address matches the C<RTAddressRegexp> config option.
-Returns false, otherwise.
-
-=cut
-
-sub is_rt_address {
-    my $address = shift || '';
-
-    # Example: the following rule would tell RT not to Cc
-    #   "tickets at noc.example.com"
-    my $re_address = RT->config->get('RTAddressRegexp');
-    if ( $re_address && $address =~ /$re_address/i ) {
-        return 1;
-    }
-    return undef;
-}
-
-=head2 cull_rt_addresses ARRAY
-
-Takes a single argument, an array of email addresses.
-Returns the same array with any is_rt_address()es weeded out.
-
-=cut
-
-sub cull_rt_addresses {
-    return grep !is_rt_address($_), @_;
-}
 
 =head2 mail_error PARAM HASH
 
@@ -887,7 +857,7 @@
         next if lc $args{'CurrentUser'}->email            eq $address;
         next if lc $args{'queue_obj'}->correspond_address eq $address;
         next if lc $args{'queue_obj'}->comment_address    eq $address;
-        next if is_rt_address($address);
+        next if RT::EmailParser->is_rt_address($address);
 
         push @res, $address;
     }

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Interface/Web/Handler.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Interface/Web/Handler.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Interface/Web/Handler.pm	Sat Feb  2 00:08:17 2008
@@ -69,14 +69,6 @@
             ),
             [ standard => $RT::MasonComponentRoot ]
         ],
-        default_escape_flags => 'h',
-        data_dir             => "$RT::MasonDataDir",
-        allow_globals        => [qw(%session)],
-
-        # Turn off static source if we're in developer mode.
-        static_source    => ( RT->config->get('DevelMode') ? '0' : '1' ),
-        use_object_files => ( RT->config->get('DevelMode') ? '0' : '1' ),
-        autoflush        => 0,
         error_format => ( RT->config->get('DevelMode') ? 'html' : 'brief' ),
         request_class => 'RT::Interface::Web::Request',
     );
@@ -93,80 +85,11 @@
 
 sub new {
     my $class = shift;
-    $class->init_session_dir;
-
-    if ( ( $mod_perl::VERSION && $mod_perl::VERSION >= 1.9908 ) || $CGI::MOD_PERL ) {
-        goto &NewApacheHandler;
-    } else {
-        goto &NewCGIHandler;
-    }
-}
-
-sub init_session_dir {
-
-    # Activate the following if running httpd as root (the normal case).
-    # Resets ownership of all files Created by Mason at startup.
-    # Note that mysql uses DB for sessions, so there's no need to do this.
-    unless ( RT->config->get('DatabaseType') =~ /(?:mysql|Pg)/ ) {
-
-        # Clean up our umask to protect session files
-        umask(0077);
-
-        if ( $CGI::MOD_PERL and $CGI::MOD_PERL < 1.9908 ) {
-
-            chown( Apache->server->uid, Apache->server->gid,
-                $RT::MasonSessionDir )
-                if Apache->server->can('uid');
-        }
-
-        # Die if WebSessionDir doesn't exist or we can't write to it
-        stat($RT::MasonSessionDir);
-        die "Can't read and write $RT::MasonSessionDir"
-            unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
-    }
-
-}
-
-# }}}
-
-# {{{ sub NewApacheHandler
-
-=head2 NewApacheHandler
-
-  Takes extra options to pass to HTML::Mason::ApacheHandler->new
-  Returns a new Mason::ApacheHandler object
-
-=cut
-
-sub new_apache_handler {
-    require HTML::Mason::ApacheHandler;
-    return NewHandler( 'HTML::Mason::ApacheHandler', args_method => "CGI",
-        @_ );
-}
-
-# }}}
-
-# {{{ sub NewCGIHandler
-
-=head2 NewCGIHandler
-
-  Returns a new Mason::CGIHandler object
-
-=cut
-
-sub new_cgi_handler {
-    require HTML::Mason::CGIHandler;
-    return NewHandler( 'HTML::Mason::CGIHandler', @_ );
+    my $self = {};
+    bless $self, $class;
+    return $self;
 }
 
-sub new_handler {
-    my $class = shift;
-    my $handler = $class->new( DefaultHandlerArgs(), @_ );
-
-    $handler->interp->set_escape( h => \&RT::Interface::Web::escape_utf8 );
-    $handler->interp->set_escape( u => \&RT::Interface::Web::escape_uri );
-    return ($handler);
-}
 
 =head2 CleanupRequest
 

Modified: rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm	(original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Model/Ticket.pm	Sat Feb  2 00:08:17 2008
@@ -794,261 +794,7 @@
 
 # }}}
 
-# {{{ _Parse822headersForAttributes Content
 
-=head2 _Parse822headersForAttributes Content
-
-Takes an RFC822 style message and parses its attributes into a hash.
-
-=cut
-
-sub _parse822_headers_for_attributes {
-    my $self    = shift;
-    my $content = shift;
-    my %args;
-
-    my @lines = ( split( /\n/, $content ) );
-    while ( defined( my $line = shift @lines ) ) {
-        if ( $line =~ /^(.*?):(?:\s+(.*))?$/ ) {
-            my $value = $2;
-            my $tag   = lc($1);
-
-            $tag =~ s/-//g;
-            if ( defined( $args{$tag} ) )
-            {    #if we're about to get a second value, make it an array
-                $args{$tag} = [ $args{$tag} ];
-            }
-            if ( ref( $args{$tag} ) )
-            {    #If it's an array, we want to push the value
-                push @{ $args{$tag} }, $value;
-            } else {    #if there's nothing there, just set the value
-                $args{$tag} = $value;
-            }
-        } elsif ( $line =~ /^$/ ) {
-
-            #TODO: this won't work, since "" isn't of the form "foo:value"
-
-            while ( defined( my $l = shift @lines ) ) {
-                push @{ $args{'content'} }, $l;
-            }
-        }
-
-    }
-
-    foreach my $date qw(due starts started resolved) {
-        my $dateobj = RT::Date->new( current_user => RT->system_user );
-        if ( defined( $args{$date} ) and $args{$date} =~ /^\d+$/ ) {
-            $dateobj->set( format => 'unix', value => $args{$date} );
-        } else {
-            $dateobj->set( format => 'unknown', value => $args{$date} );
-        }
-        $args{$date} = $dateobj->iso;
-    }
-    $args{'mime_obj'} = MIME::Entity->new();
-    $args{'mime_obj'}->build(
-        Type => ( $args{'contenttype'} || 'text/plain' ),
-        Data => ( $args{'content'}     || '' )
-    );
-
-    return (%args);
-}
-
-# }}}
-
-# {{{ sub Import
-
-=head2 Import PARAMHASH
-
-Import a ticket. 
-Doesn\'t create a transaction. 
-Doesn\'t supply queue defaults, etc.
-
-Returns: TICKETID
-
-=cut
-
-sub __import {
-    my $self = shift;
-    my ( $ErrStr, $queue_obj, $owner );
-
-    my %args = (
-        id               => undef,
-        effective_id      => undef,
-        queue            => undef,
-        Requestor        => undef,
-        type             => 'ticket',
-        owner            => RT->nobody->id,
-        subject          => '[no subject]',
-        initial_priority => undef,
-        final_priority   => undef,
-        status           => 'new',
-        time_worked      => "0",
-        due              => undef,
-        created          => undef,
-        Updated          => undef,
-        resolved         => undef,
-        told             => undef,
-        @_
-    );
-
-    if ( ( defined( $args{'queue'} ) ) && ( !ref( $args{'queue'} ) ) ) {
-        $queue_obj = RT::Model::Queue->new( current_user => RT->system_user );
-        $queue_obj->load( $args{'queue'} );
-    } elsif ( ref( $args{'queue'} ) eq 'RT::Model::Queue' ) {
-        $queue_obj = RT::Model::Queue->new( current_user => RT->system_user );
-        $queue_obj->load( $args{'queue'}->id );
-    } else {
-        Jifty->log->debug(
-            "$self " . $args{'queue'} . " not a recognised queue object." );
-    }
-
-    #Can't create a ticket without a queue.
-    unless ( defined($queue_obj) and $queue_obj->id ) {
-        Jifty->log->debug("$self No queue given for ticket creation.");
-        return ( 0, _('Could not create ticket. queue not set') );
-    }
-
-    #Now that we have a queue, Check the ACLS
-    unless (
-        $self->current_user->has_right(
-            right  => 'CreateTicket',
-            object => $queue_obj
-        )
-        )
-    {
-        return (
-            0,
-            _(  "No permission to create tickets in the queue '%1'",
-                $queue_obj->name
-            )
-        );
-    }
-
-    # {{{ Deal with setting the owner
-
-    # Attempt to take user object, user name or user id.
-    # Assign to nobody if lookup fails.
-    if ( defined( $args{'owner'} ) ) {
-        if ( ref( $args{'owner'} ) ) {
-            $owner = $args{'owner'};
-        } else {
-            $owner = RT::Model::User->new();
-            $owner->load( $args{'owner'} );
-            if ( !defined( $owner->id ) ) {
-                $owner->load( RT->nobody->id );
-            }
-        }
-    }
-
-    #If we have a proposed owner and they don't have the right
-    #to own a ticket, scream about it and make them not the owner
-    if (    ( defined($owner) )
-        and ( $owner->id != RT->nobody->id )
-        and (
-            !$owner->has_right(
-                object => $queue_obj,
-                right  => 'OwnTicket'
-            )
-        )
-        )
-    {
-
-        Jifty->log->warn( "$self user "
-                . $owner->name . "("
-                . $owner->id
-                . ") was proposed "
-                . "as a ticket owner but has no rights to own "
-                . "tickets in '"
-                . $queue_obj->name
-                . "'\n" );
-
-        $owner = undef;
-    }
-
-    #If we haven't been handed a valid owner, make it nobody.
-    unless ( defined($owner) ) {
-        $owner = RT::Model::User->new();
-        $owner->load( RT->nobody->user_object->id );
-    }
-
-    # }}}
-
-    unless ( $self->validate_status( $args{'status'} ) ) {
-        return ( 0,
-            _( "'%1' is an invalid value for status", $args{'status'} ) );
-    }
-
-    # If we're coming in with an id, set that now.
-    my $effective_id = undef;
-    if ( $args{'id'} ) {
-        $effective_id = $args{'id'};
-
-    }
-
-    my $id = $self->SUPER::create(
-        id               => $args{'id'},
-        effective_id      => $effective_id,
-        queue            => $queue_obj->id,
-        owner            => $owner->id,
-        subject          => $args{'subject'},             # loc
-        initial_priority => $args{'initial_priority'},    # loc
-        final_priority   => $args{'final_priority'},      # loc
-        priority         => $args{'initial_priority'},    # loc
-        status           => $args{'status'},              # loc
-        time_worked      => $args{'time_worked'},         # loc
-        type             => $args{'type'},                # loc
-        created          => $args{'created'},             # loc
-        told             => $args{'told'},                # loc
-        last_updated      => $args{'Updated'},             # loc
-        resolved         => $args{'resolved'},            # loc
-        due              => $args{'due'},                 # loc
-    );
-
-    # If the ticket didn't have an id
-    # Set the ticket's effective ID now that we've created it.
-    if ( $args{'id'} ) {
-        $self->load( $args{'id'} );
-    } else {
-        my ( $val, $msg )
-            = $self->__set( column => 'effective_id', value => $id );
-
-        unless ($val) {
-            Jifty->log->err(
-                $self . "->import couldn't set effective_id: $msg\n" );
-        }
-    }
-
-    my $create_groups_ret = $self->_create_ticket_groups();
-    unless ($create_groups_ret) {
-        Jifty->log->fatal(
-            "Couldn't create ticket groups for ticket " . $self->id );
-    }
-
-    $self->owner_group->_add_member( principal_id => $owner->principal_id );
-
-    my $watcher;
-    foreach $watcher ( @{ $args{'Cc'} } ) {
-        $self->_add_watcher( type => 'Cc', email => $watcher, silent => 1 );
-    }
-    foreach $watcher ( @{ $args{'AdminCc'} } ) {
-        $self->_add_watcher(
-            type   => 'AdminCc',
-            email  => $watcher,
-            silent => 1
-        );
-    }
-    foreach $watcher ( @{ $args{'Requestor'} } ) {
-        $self->_add_watcher(
-            type   => 'Requestor',
-            email  => $watcher,
-            silent => 1
-        );
-    }
-
-    return ( $self->id, $ErrStr );
-}
-
-# }}}
 
 # {{{ Routines dealing with watchers.
 


More information about the Rt-commit mailing list