From: Emmanuel Lacour Date: Wed, 22 Jan 2014 15:13:50 +0000 (+0100) Subject: Make it works with RT >= 4.2.0 X-Git-Tag: 0.03 X-Git-Url: http://git.home-dn.net/?p=manu%2FRT-Extension-SearchResults-ODS.git;a=commitdiff_plain;h=8c7186545d13b38783caf887a92871536aa01d18 Make it works with RT >= 4.2.0 --- diff --git a/Changes b/Changes index a30aca9..037f0d2 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for RT-Extension-SearchResults-ODS +0.03 Wed, 22 Jan 2014 16:11:01 +0100 + Add support for RT 4.2.x + Require RT >= 4.2.0 + 0.02 Wed, 25 May 2011 11:53:10 +0200 Add Tab for RT 4 diff --git a/MANIFEST b/MANIFEST index 2fc5468..e64d305 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,7 +1,5 @@ Changes html/Callbacks/Results-ODS/Elements/Tabs/Privileged -html/Callbacks/Results-ODS/Search/Elements/ResultViews/AfterTools -html/Callbacks/Results-ODS/Search/Results.html/SearchActions html/Search/Results.ods inc/Module/Install.pm inc/Module/Install/Base.pm @@ -9,7 +7,10 @@ inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm +inc/Module/Install/ReadmeFromPod.pm inc/Module/Install/RTx.pm +inc/Module/Install/RTx/Factory.pm +inc/Module/Install/Substitute.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/RT/Extension/SearchResults/ODS.pm diff --git a/META.yml b/META.yml index 09b5979..5cbaf10 100644 --- a/META.yml +++ b/META.yml @@ -24,4 +24,4 @@ requires: resources: license: http://dev.perl.org/licenses/ repository: git://git.home-dn.net/manu/RT-Extension-SearchResults-ODS.git -version: 0.02 +version: 0.03 diff --git a/README b/README index 47ffea8..15f429a 100644 --- a/README +++ b/README @@ -45,7 +45,7 @@ You can also look for information at: COPYRIGHT AND LICENCE -Copyright (C) 2011 Emmanuel Lacour +Copyright (C) 2011-2014 Emmanuel Lacour This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/html/Callbacks/Results-ODS/Elements/Tabs/Privileged b/html/Callbacks/Results-ODS/Elements/Tabs/Privileged index e144564..ec849a6 100644 --- a/html/Callbacks/Results-ODS/Elements/Tabs/Privileged +++ b/html/Callbacks/Results-ODS/Elements/Tabs/Privileged @@ -55,12 +55,29 @@ my $query_string = sub { return $u->query; }; -if ( $request_path =~ qr{^/Search/Results\.html} ) { - my $tabs = PageMenu; - $tabs->child( - 'ods' => title => loc('ODS'), - path => '/Search/Results.ods?' . $query_string->( %{ $m->request_args } ) - ); + +if ( + ( + $request_path =~ m{^/(?:Ticket|Search)/} + && $request_path !~ m{^/Search/Simple\.html} + ) + || ( $request_path =~ m{^/Search/Simple\.html} + && $DECODED_ARGS->{'q'} ) + ) { + + my $has_query = ''; + my $current_search = $session{"CurrentSearchHash"} || {}; + $has_query = 1 if ( $DECODED_ARGS->{'Query'} or $current_search->{'Query'} ); + + if ( $has_query ) { + my $tabs = PageMenu; + my $feeds = $tabs->child('more'); + + $feeds->child( + 'ods' => title => loc('ODS'), + path => '/Search/Results.ods?' . $query_string->( %{ $m->request_args } ) + ); + } } diff --git a/html/Callbacks/Results-ODS/Search/Elements/ResultViews/AfterTools b/html/Callbacks/Results-ODS/Search/Elements/ResultViews/AfterTools deleted file mode 100644 index 8cd5e63..0000000 --- a/html/Callbacks/Results-ODS/Search/Elements/ResultViews/AfterTools +++ /dev/null @@ -1,4 +0,0 @@ -
  • <&|/l&>ODS
  • -<%ARGS> -$QueryString => undef - diff --git a/html/Callbacks/Results-ODS/Search/Results.html/SearchActions b/html/Callbacks/Results-ODS/Search/Results.html/SearchActions deleted file mode 100644 index 821cb68..0000000 --- a/html/Callbacks/Results-ODS/Search/Results.html/SearchActions +++ /dev/null @@ -1,27 +0,0 @@ -% # Don't display this callback if our RT Version contains the new ResultsView -% # AfterTools Callback -% if ( $must_display ) { -ODS -% } -<%INIT> -my $must_display = 0; - -# cmp_version is present only since 3.8.0 -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; -} - -$must_display = ( cmp_version( '3.8.1', $RT::VERSION ) > 0 ); - - -<%ARGS> -$QueryString => undef - diff --git a/html/Search/Results.ods b/html/Search/Results.ods index 9659c86..37d4e6f 100644 --- a/html/Search/Results.ods +++ b/html/Search/Results.ods @@ -1,40 +1,40 @@ %# BEGIN BPS TAGGED BLOCK {{{ -%# +%# %# COPYRIGHT: -%# -%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC -%# -%# +%# +%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC +%# +%# %# (Except where explicitly superseded by other copyright notices) -%# -%# +%# +%# %# LICENSE: -%# +%# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org. -%# +%# %# This work is distributed in the hope that it will be useful, but %# WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %# General Public License for more details. -%# +%# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. -%# -%# +%# +%# %# CONTRIBUTION SUBMISSION POLICY: -%# +%# %# (The following paragraph is not intended to limit the rights granted %# to you to modify and distribute this software under the terms of %# the GNU General Public License and is only of importance to you if %# you choose to contribute your changes and enhancements to the %# community by submitting them to Best Practical Solutions, LLC.) -%# +%# %# By intentionally submitting any modifications, corrections or %# derivatives to this work, or any other work intended for use with %# Request Tracker, to Best Practical Solutions, LLC, you confirm that @@ -43,13 +43,20 @@ %# royalty-free, perpetual, license to use, copy, create derivative %# works based on those contributions, and sublicense and distribute %# those contributions and any derivatives thereof. -%# +%# %# END BPS TAGGED BLOCK }}} <%ARGS> +$Format => undef +$Query => '' $OrderBy => 'id' $Order => 'ASC' +$PreserveNewLines => 0 +<%ONCE> +my $no_html = HTML::Scrubber->new( deny => '*' ); + <%INIT> +require HTML::Entities; use OpenOffice::OODoc; my $tmpdir; @@ -64,57 +71,73 @@ my $tmpfile = File::Spec->catfile( $tmpdir, 'Results.ods' ); odfWorkingDirectory($tmpdir); my $workbook = odfDocument(file => $tmpfile, create => 'spreadsheet') or die $!; -my $Tickets = RT::Tickets->new( $session{'CurrentUser'} ); -$Tickets->FromSQL( $ARGS{'Query'} ); -if ( $OrderBy =~ /\|/ ) { +$r->content_type('application/vnd.oasis.opendocument.spreadsheet'); - # Multiple Sorts - my @OrderBy = split /\|/, $OrderBy; - my @Order = split /\|/, $Order; - $Tickets->OrderByCols( - map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } - ( 0 .. $#OrderBy ) ); -} -else { - $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order ); -} +my $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $Format); -my @rows; -my %known_cfs; +my @Format = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat); -my @attrs = qw( id QueueObj->Name Subject Status TimeEstimated TimeWorked TimeLeft Priority FinalPriority OwnerObj->Name - Requestors->MemberEmailAddressesAsString Cc->MemberEmailAddressesAsString AdminCc->MemberEmailAddressesAsString - DueObj->ISO ToldObj->ISO CreatedObj->ISO ResolvedObj->ISO LastUpdatedObj->ISO); +my @columns; -$r->content_type('application/vnd.oasis.opendocument.spreadsheet'); -while ( my $Ticket = $Tickets->Next()) { - my $row; - foreach my $attr (@attrs) { - if ($attr =~ /(.*)->ISO$/ and $Ticket->$1->Unix <= 0) { - $row->{$attr} = ""; - } else { - my $method = '$Ticket->'.$attr.'()'; - $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/; - $row->{$attr} = eval $method; - if ($@) {die "Failed to find $attr - ". $@}; - } - } +my $should_loc = { map { $_ => 1 } qw(Status) }; - my $cfs = $Ticket->QueueObj->TicketCustomFields(); - while (my $cf = $cfs->Next) { - $known_cfs{$cf->Id} = $cf->Name; - my @content; - my $values = $Ticket->CustomFieldValues($cf->Id); - while (my $value = $values->Next) { - push @content, $value->Content; +my $col_entry = sub { + my $col = shift; + # in tsv output, "#" is often a comment character but we use it for "id" + delete $col->{title} + if $col->{title} and $col->{title} =~ /^\s*#\s*$/; + return { + header => Encode::encode_utf8(loc($col->{title} || $col->{attribute})), + map => $m->comp( + "/Elements/ColumnMap", + Name => $col->{attribute}, + Attr => 'value' + ), + should_loc => $should_loc->{$col->{attribute}}, + } +}; + +if ($PreserveNewLines) { + my $col = []; + push @columns, $col; + for (@Format) { + if ($_->{title} eq 'NEWLINE') { + $col = []; + push @columns, $col; + } + else { + push @$col, $col_entry->($_); } - $row->{'CustomField-'.$cf->Id} = join(', ',@content); } - push @rows, $row; +} +else { + push @columns, [map { $_->{attribute} + ? $col_entry->($_) + : () } @Format]; +} + +my $Tickets = RT::Tickets->new( $session{'CurrentUser'} ); +$Tickets->FromSQL( $Query ); +if ( $OrderBy =~ /\|/ ) { + # Multiple Sorts + my @OrderBy = split /\|/, $OrderBy; + my @Order = split /\|/, $Order; + $Tickets->OrderByCols( + map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } + ( 0 .. $#OrderBy ) + ); +} +else { + $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order ); } -my $rows_count = scalar(@rows) + 1; -my $cols_count = scalar(@attrs) + scalar( keys %known_cfs ); +my $rows_count = $Tickets->Count; +my $cols_count = 0; +foreach my $col (@columns) { + foreach my $sub_col (@$col) { + $cols_count++; + } +} $workbook->expandTable(0, $rows_count, $cols_count ); @@ -135,47 +158,41 @@ sub int_to_alpha { return $alpha; } - my $xml = ''; my $xmlpos = $workbook->getElement('//table:table', 0); -$workbook->insertElement ( $xmlpos, $xml, position => 'after'); - -{ - my @header; - my $ws_col = 0; - foreach my $attr (@attrs) { - my $label = $attr; - $label =~ s'Obj-.(?:AsString|Name|ISO)''g; - $label =~ s'-\>MemberEmailAddressesAsString''g; +$workbook->insertElement ( $xmlpos, $xml, position => 'after'); + +my $ws_col = 0; +foreach my $col (@columns) { + foreach my $sub_col ( @$col ) { + my $label = $sub_col->{header}; Encode::_utf8_off($label); $workbook->updateCell(0, 0, $ws_col, $label); $ws_col++; } - foreach my $id (sort keys %known_cfs) { - Encode::_utf8_off($known_cfs{$id}); - $workbook->updateCell(0, 0, $ws_col, "CF-".$known_cfs{$id}); - $ws_col++; - } } my $ws_row = 1; -foreach my $row (@rows) { - my $ws_col = 0; - my @row; - foreach my $attr(@attrs) { - Encode::_utf8_off($row->{"$attr"}); - $workbook->updateCell(0, $ws_row, $ws_col, $row->{"$attr"}); - $ws_col++; - } - foreach my $id (sort keys %known_cfs) { - my $val = $row->{'CustomField-'.$id}; - #$val =~ s/(\n|\r)//g; - Encode::_utf8_off($val); - $workbook->updateCell(0, $ws_row, $ws_col, $val); - $ws_col++; +my $ii = 0; +while (my $row = $Tickets->Next) { + $ws_col = 0; + for my $col (@columns) { + for (@$col) { + my $val = ProcessColumnMapValue($_->{map}, Arguments => [$row, $ii++], Escape => 0); + $val = loc($val) if $_->{should_loc}; + # remove tabs from all field values, they screw up the tsv + $val = '' unless defined $val; + $val =~ s/(?:\n|\r)//g; $val =~ s{\t}{ }g; + $val = $no_html->scrub($val); + $val = HTML::Entities::decode_entities($val); + Encode::_utf8_off($val); + $workbook->updateCell(0, $ws_row, $ws_col, $val); + $ws_col++; + } } $ws_row++; } + $workbook->save(); open (ODT, $tmpfile); while () { @@ -184,5 +201,7 @@ while () { close (ODT); unlink ($tmpfile); $m->abort(); - +$m->abort(); + + diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm index 8ee839d..4ecf46b 100644 --- a/inc/Module/Install.pm +++ b/inc/Module/Install.pm @@ -31,7 +31,7 @@ BEGIN { # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. - $VERSION = '1.00'; + $VERSION = '1.06'; # Storage for the pseudo-singleton $MAIN = undef; @@ -451,7 +451,7 @@ sub _version ($) { } sub _cmp ($$) { - _version($_[0]) <=> _version($_[1]); + _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS @@ -467,4 +467,4 @@ sub _CLASS ($) { 1; -# Copyright 2008 - 2010 Adam Kennedy. +# Copyright 2008 - 2012 Adam Kennedy. diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm index b55bda3..802844a 100644 --- a/inc/Module/Install/Base.pm +++ b/inc/Module/Install/Base.pm @@ -4,7 +4,7 @@ package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; } # Suspend handler for "redefined" warnings diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm index 71ccc27..22167b8 100644 --- a/inc/Module/Install/Can.pm +++ b/inc/Module/Install/Can.pm @@ -3,13 +3,12 @@ package Module::Install::Can; use strict; use Config (); -use File::Spec (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -29,7 +28,7 @@ sub can_use { eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } -# check if we can run some command +# Check if we can run some command sub can_run { my ($self, $cmd) = @_; @@ -38,14 +37,88 @@ sub can_run { for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; - my $abs = File::Spec->catfile($dir, $_[1]); + require File::Spec; + my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } -# can we locate a (the) C compiler +# Can our C compiler environment build XS files +sub can_xs { + my $self = shift; + + # Ensure we have the CBuilder module + $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); + + # Do we have the configure_requires checker? + local $@; + eval "require ExtUtils::CBuilder;"; + if ( $@ ) { + # They don't obey configure_requires, so it is + # someone old and delicate. Try to avoid hurting + # them by falling back to an older simpler test. + return $self->can_cc(); + } + + # Do we have a working C compiler + my $builder = ExtUtils::CBuilder->new( + quiet => 1, + ); + unless ( $builder->have_compiler ) { + # No working C compiler + return 0; + } + + # Write a C file representative of what XS becomes + require File::Temp; + my ( $FH, $tmpfile ) = File::Temp::tempfile( + "compilexs-XXXXX", + SUFFIX => '.c', + ); + binmode $FH; + print $FH <<'END_C'; +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +int main(int argc, char **argv) { + return 0; +} + +int boot_sanexs() { + return 1; +} + +END_C + close $FH; + + # Can the C compiler access the same headers XS does + my @libs = (); + my $object = undef; + eval { + local $^W = 0; + $object = $builder->compile( + source => $tmpfile, + ); + @libs = $builder->link( + objects => $object, + module_name => 'sanexs', + ); + }; + my $result = $@ ? 0 : 1; + + # Clean up all the build files + foreach ( $tmpfile, $object, @libs ) { + next unless defined $_; + 1 while unlink; + } + + return $result; +} + +# Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; @@ -78,4 +151,4 @@ if ( $^O eq 'cygwin' ) { __END__ -#line 156 +#line 236 diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm index ec1f106..bee0c4f 100644 --- a/inc/Module/Install/Fetch.pm +++ b/inc/Module/Install/Fetch.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm index 5dfd0e9..7052f36 100644 --- a/inc/Module/Install/Makefile.pm +++ b/inc/Module/Install/Makefile.pm @@ -8,7 +8,7 @@ use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -215,18 +215,22 @@ sub write { require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { - # MakeMaker can complain about module versions that include - # an underscore, even though its own version may contain one! - # Hence the funny regexp to get rid of it. See RT #35800 - # for details. - my $v = $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/; - $self->build_requires( 'ExtUtils::MakeMaker' => $v ); - $self->configure_requires( 'ExtUtils::MakeMaker' => $v ); + # This previous attempted to inherit the version of + # ExtUtils::MakeMaker in use by the module author, but this + # was found to be untenable as some authors build releases + # using future dev versions of EU:MM that nobody else has. + # Instead, #toolchain suggests we use 6.59 which is the most + # stable version on CPAN at time of writing and is, to quote + # ribasushi, "not terminally fucked, > and tested enough". + # TODO: We will now need to maintain this over time to push + # the version up as new versions are released. + $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); + $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. - $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 ); - $self->configure_requires( 'ExtUtils::MakeMaker' => 6.42 ); + $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); + $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params @@ -241,7 +245,6 @@ in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT - $DB::single = 1; if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; @@ -412,4 +415,4 @@ sub postamble { __END__ -#line 541 +#line 544 diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm index cfe45b3..58430f3 100644 --- a/inc/Module/Install/Metadata.pm +++ b/inc/Module/Install/Metadata.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } @@ -151,15 +151,21 @@ sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { - my $self = shift; - unless ( @_ ) { - warn "You MUST provide an explicit true/false value to dynamic_config\n"; - return $self; + my $self = shift; + my $value = @_ ? shift : 1; + if ( $self->{values}->{dynamic_config} ) { + # Once dynamic we never change to static, for safety + return 0; } - $self->{values}->{dynamic_config} = $_[0] ? 1 : 0; + $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } +# Convenience command +sub static_config { + shift->dynamic_config(0); +} + sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; @@ -170,7 +176,7 @@ sub perl_version { # Normalize the version $version = $self->_perl_version($version); - # We don't support the reall old versions + # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } @@ -515,6 +521,7 @@ sub __extract_license { 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, + 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, @@ -550,9 +557,9 @@ sub license_from { sub _extract_bugtracker { my @links = $_[0] =~ m#L<( - \Qhttp://rt.cpan.org/\E[^>]+| - \Qhttp://github.com/\E[\w_]+/[\w_]+/issues| - \Qhttp://code.google.com/p/\E[\w_\-]+/issues/list + https?\Q://rt.cpan.org/\E[^>]+| + https?\Q://github.com/\E[\w_]+/[\w_]+/issues| + https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @@ -581,7 +588,7 @@ sub bugtracker_from { sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); - my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; + my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; diff --git a/inc/Module/Install/RTx.pm b/inc/Module/Install/RTx.pm index 20a354b..ac04c79 100644 --- a/inc/Module/Install/RTx.pm +++ b/inc/Module/Install/RTx.pm @@ -8,13 +8,13 @@ no warnings 'once'; use Module::Install::Base; use base 'Module::Install::Base'; -our $VERSION = '0.24'; +our $VERSION = '0.32'; use FindBin; use File::Glob (); use File::Basename (); -my @DIRS = qw(etc lib html bin sbin po var); +my @DIRS = qw(etc lib html static bin sbin po var); my @INDEX_DIRS = qw(lib bin sbin); sub RTx { @@ -42,15 +42,16 @@ sub RTx { $INC{'RT.pm'} = "$RT::LocalPath/lib/RT.pm"; } else { local @INC = ( - @INC, $ENV{RTHOME} ? ( $ENV{RTHOME}, "$ENV{RTHOME}/lib" ) : (), - map { ( "$_/rt3/lib", "$_/lib/rt3", "$_/lib" ) } grep $_, - @prefixes + @INC, + map { ( "$_/rt4/lib", "$_/lib/rt4", "$_/rt3/lib", "$_/lib/rt3", "$_/lib" ) + } grep $_, @prefixes ); until ( eval { require RT; $RT::LocalPath } ) { warn "Cannot find the location of RT.pm that defines \$RT::LocalPath in: @INC\n"; - $_ = $self->prompt("Path to your RT.pm:") or exit; + $_ = $self->prompt("Path to directory containing your RT.pm:") or exit; + $_ =~ s/\/RT\.pm$//; push @INC, $_, "$_/rt3/lib", "$_/lib/rt3", "$_/lib"; } } @@ -59,11 +60,13 @@ sub RTx { my $local_lib_path = "$RT::LocalPath/lib"; print "Using RT configuration from $INC{'RT.pm'}:\n"; unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath; + unshift @INC, $lib_path; - $RT::LocalVarPath ||= $RT::VarPath; - $RT::LocalPoPath ||= $RT::LocalLexiconPath; - $RT::LocalHtmlPath ||= $RT::MasonComponentRoot; - $RT::LocalLibPath ||= "$RT::LocalPath/lib"; + $RT::LocalVarPath ||= $RT::VarPath; + $RT::LocalPoPath ||= $RT::LocalLexiconPath; + $RT::LocalHtmlPath ||= $RT::MasonComponentRoot; + $RT::LocalStaticPath ||= $RT::StaticPath; + $RT::LocalLibPath ||= "$RT::LocalPath/lib"; my $with_subdirs = $ENV{WITH_SUBDIRS}; @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? ( ( $with_subdirs = $1 ), 0 ) : 1 } @@ -127,23 +130,13 @@ install :: my %has_etc; if ( File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*") ) { - - # got schema, load factory module $has_etc{schema}++; - $self->load('RTxFactory'); - $self->postamble(<< "."); -factory :: -\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name))" - -dropdb :: -\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name drop))" - -. } if ( File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*") ) { $has_etc{acl}++; } if ( -e 'etc/initialdata' ) { $has_etc{initialdata}++; } + if ( -d 'etc/upgrade/' ) { $has_etc{upgrade}++; } $self->postamble("$postamble\n"); unless ( $subdirs{'lib'} ) { @@ -162,30 +155,65 @@ dropdb :: print "For first-time installation, type 'make initdb'.\n"; my $initdb = ''; $initdb .= <<"." if $has_etc{schema}; -\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema))" +\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema \$(NAME) \$(VERSION)))" . $initdb .= <<"." if $has_etc{acl}; -\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl))" +\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl \$(NAME) \$(VERSION)))" . $initdb .= <<"." if $has_etc{initialdata}; -\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert))" +\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert \$(NAME) \$(VERSION)))" . $self->postamble("initdb ::\n$initdb\n"); $self->postamble("initialize-database ::\n$initdb\n"); + if ($has_etc{upgrade}) { + print "To upgrade from a previous version of this extension, use 'make upgrade-database'\n"; + my $upgradedb = qq|\t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(upgrade \$(NAME) \$(VERSION)))"\n|; + $self->postamble("upgrade-database ::\n$upgradedb\n"); + $self->postamble("upgradedb ::\n$upgradedb\n"); + } } } -sub RTxInit { - unshift @INC, substr( delete( $INC{'RT.pm'} ), 0, -5 ) if $INC{'RT.pm'}; - require RT; - RT::LoadConfig(); - RT::ConnectToDatabase(); +# stolen from RT::Handle so we work on 3.6 (cmp_versions came in with 3.8) +{ my %word = ( + a => -4, + alpha => -4, + b => -3, + beta => -3, + pre => -2, + rc => -1, + head => 9999, +); +sub cmp_version($$) { + my ($a, $b) = (@_); + my @a = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef } + split /([^0-9]+)/, $a; + my @b = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef } + split /([^0-9]+)/, $b; + @a > @b + ? push @b, (0) x (@a-@b) + : push @a, (0) x (@b-@a); + for ( my $i = 0; $i < @a; $i++ ) { + return $a[$i] <=> $b[$i] if $a[$i] <=> $b[$i]; + } + return 0; +}} +sub requires_rt { + my ($self,$version) = @_; + + # if we're exactly the same version as what we want, silently return + return if ($version eq $RT::VERSION); - die "Cannot load RT" unless $RT::Handle and $RT::DatabaseType; + my @sorted = sort cmp_version $version,$RT::VERSION; + + if ($sorted[-1] eq $version) { + # should we die? + warn "\nWarning: prerequisite RT $version not found. Your installed version of RT ($RT::VERSION) is too old.\n\n"; + } } 1; __END__ -#line 302 +#line 336 diff --git a/inc/Module/Install/RTx/Factory.pm b/inc/Module/Install/RTx/Factory.pm new file mode 100644 index 0000000..6776688 --- /dev/null +++ b/inc/Module/Install/RTx/Factory.pm @@ -0,0 +1,53 @@ +#line 1 +package Module::Install::RTx::Factory; +use Module::Install::Base; @ISA = qw(Module::Install::Base); + +use strict; +use File::Basename (); + +sub RTxInitDB { + my ($self, $action, $name, $version) = @_; + + unshift @INC, substr(delete($INC{'RT.pm'}), 0, -5) if $INC{'RT.pm'}; + + require RT; + unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath; + + $RT::SbinPath ||= $RT::LocalPath; + $RT::SbinPath =~ s/local$/sbin/; + + foreach my $file ($RT::CORE_CONFIG_FILE, $RT::SITE_CONFIG_FILE) { + next if !-e $file or -r $file; + die "No permission to read $file\n-- please re-run $0 with suitable privileges.\n"; + } + + RT::LoadConfig(); + + require RT::System; + + my $lib_path = File::Basename::dirname($INC{'RT.pm'}); + my @args = ("-Ilib"); + push @args, "-I$RT::LocalPath/lib" if $RT::LocalPath; + push @args, ( + "-I$lib_path", + "$RT::SbinPath/rt-setup-database", + "--action" => $action, + ($action eq 'upgrade' ? () : ("--datadir" => "etc")), + (($action eq 'insert') ? ("--datafile" => "etc/initialdata") : ()), + "--dba" => $RT::DatabaseAdmin || $RT::DatabaseUser, + "--prompt-for-dba-password" => '', + (RT::System->can('AddUpgradeHistory') ? ("--package" => $name, "--ext-version" => $version) : ()), + ); + # If we're upgrading against an RT which isn't at least 4.2 (has + # AddUpgradeHistory) then pass --package. Upgrades against later RT + # releases will pick up --package from AddUpgradeHistory. + if ($action eq 'upgrade' and + not RT::System->can('AddUpgradeHistory')) { + push @args, "--package" => $name; + } + + print "$^X @args\n"; + (system($^X, @args) == 0) or die "...returned with error: $?\n"; +} + +1; diff --git a/inc/Module/Install/ReadmeFromPod.pm b/inc/Module/Install/ReadmeFromPod.pm new file mode 100644 index 0000000..b5e03c3 --- /dev/null +++ b/inc/Module/Install/ReadmeFromPod.pm @@ -0,0 +1,138 @@ +#line 1 +package Module::Install::ReadmeFromPod; + +use 5.006; +use strict; +use warnings; +use base qw(Module::Install::Base); +use vars qw($VERSION); + +$VERSION = '0.22'; + +sub readme_from { + my $self = shift; + return unless $self->is_admin; + + # Input file + my $in_file = shift || $self->_all_from + or die "Can't determine file to make readme_from"; + + # Get optional arguments + my ($clean, $format, $out_file, $options); + my $args = shift; + if ( ref $args ) { + # Arguments are in a hashref + if ( ref($args) ne 'HASH' ) { + die "Expected a hashref but got a ".ref($args)."\n"; + } else { + $clean = $args->{'clean'}; + $format = $args->{'format'}; + $out_file = $args->{'output_file'}; + $options = $args->{'options'}; + } + } else { + # Arguments are in a list + $clean = $args; + $format = shift; + $out_file = shift; + $options = \@_; + } + + # Default values; + $clean ||= 0; + $format ||= 'txt'; + + # Generate README + print "readme_from $in_file to $format\n"; + if ($format =~ m/te?xt/) { + $out_file = $self->_readme_txt($in_file, $out_file, $options); + } elsif ($format =~ m/html?/) { + $out_file = $self->_readme_htm($in_file, $out_file, $options); + } elsif ($format eq 'man') { + $out_file = $self->_readme_man($in_file, $out_file, $options); + } elsif ($format eq 'pdf') { + $out_file = $self->_readme_pdf($in_file, $out_file, $options); + } + + if ($clean) { + $self->clean_files($out_file); + } + + return 1; +} + + +sub _readme_txt { + my ($self, $in_file, $out_file, $options) = @_; + $out_file ||= 'README'; + require Pod::Text; + my $parser = Pod::Text->new( @$options ); + open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; + $parser->output_fh( *$out_fh ); + $parser->parse_file( $in_file ); + close $out_fh; + return $out_file; +} + + +sub _readme_htm { + my ($self, $in_file, $out_file, $options) = @_; + $out_file ||= 'README.htm'; + require Pod::Html; + Pod::Html::pod2html( + "--infile=$in_file", + "--outfile=$out_file", + @$options, + ); + # Remove temporary files if needed + for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') { + if (-e $file) { + unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n"; + } + } + return $out_file; +} + + +sub _readme_man { + my ($self, $in_file, $out_file, $options) = @_; + $out_file ||= 'README.1'; + require Pod::Man; + my $parser = Pod::Man->new( @$options ); + $parser->parse_from_file($in_file, $out_file); + return $out_file; +} + + +sub _readme_pdf { + my ($self, $in_file, $out_file, $options) = @_; + $out_file ||= 'README.pdf'; + eval { require App::pod2pdf; } + or die "Could not generate $out_file because pod2pdf could not be found\n"; + my $parser = App::pod2pdf->new( @$options ); + $parser->parse_from_file($in_file); + open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; + select $out_fh; + $parser->output; + select STDOUT; + close $out_fh; + return $out_file; +} + + +sub _all_from { + my $self = shift; + return unless $self->admin->{extensions}; + my ($metadata) = grep { + ref($_) eq 'Module::Install::Metadata'; + } @{$self->admin->{extensions}}; + return unless $metadata; + return $metadata->{values}{all_from} || ''; +} + +'Readme!'; + +__END__ + +#line 254 + diff --git a/inc/Module/Install/Substitute.pm b/inc/Module/Install/Substitute.pm new file mode 100644 index 0000000..56af7fe --- /dev/null +++ b/inc/Module/Install/Substitute.pm @@ -0,0 +1,131 @@ +#line 1 +package Module::Install::Substitute; + +use strict; +use warnings; +use 5.008; # I don't care much about earlier versions + +use Module::Install::Base; +our @ISA = qw(Module::Install::Base); + +our $VERSION = '0.03'; + +require File::Temp; +require File::Spec; +require Cwd; + +#line 89 + +sub substitute +{ + my $self = shift; + $self->{__subst} = shift; + $self->{__option} = {}; + if( UNIVERSAL::isa( $_[0], 'HASH' ) ) { + my $opts = shift; + while( my ($k,$v) = each( %$opts ) ) { + $self->{__option}->{ lc( $k ) } = $v || ''; + } + } + $self->_parse_options; + + my @file = @_; + foreach my $f (@file) { + $self->_rewrite_file( $f ); + } + + return; +} + +sub _parse_options +{ + my $self = shift; + my $cwd = Cwd::getcwd(); + foreach my $t ( qw(from to) ) { + $self->{__option}->{$t} = $cwd unless $self->{__option}->{$t}; + my $d = $self->{__option}->{$t}; + die "Couldn't read directory '$d'" unless -d $d && -r _; + } +} + +sub _rewrite_file +{ + my ($self, $file) = @_; + my $source = File::Spec->catfile( $self->{__option}{from}, $file ); + $source .= $self->{__option}{sufix} if $self->{__option}{sufix}; + unless( -f $source && -r _ ) { + print STDERR "Couldn't find file '$source'\n"; + return; + } + my $dest = File::Spec->catfile( $self->{__option}{to}, $file ); + return $self->__rewrite_file( $source, $dest ); +} + +sub __rewrite_file +{ + my ($self, $source, $dest) = @_; + + my $mode = (stat($source))[2]; + + open my $sfh, "<$source" or die "Couldn't open '$source' for read"; + print "Open input '$source' file for substitution\n"; + + my ($tmpfh, $tmpfname) = File::Temp::tempfile('mi-subst-XXXX', UNLINK => 1); + $self->__process_streams( $sfh, $tmpfh, ($source eq $dest)? 1: 0 ); + close $sfh; + + seek $tmpfh, 0, 0 or die "Couldn't seek in tmp file"; + + open my $dfh, ">$dest" or die "Couldn't open '$dest' for write"; + print "Open output '$dest' file for substitution\n"; + + while( <$tmpfh> ) { + print $dfh $_; + } + close $dfh; + chmod $mode, $dest or "Couldn't change mode on '$dest'"; +} + +sub __process_streams +{ + my ($self, $in, $out, $replace) = @_; + + my @queue = (); + my $subst = $self->{'__subst'}; + my $re_subst = join('|', map {"\Q$_"} keys %{ $subst } ); + + while( my $str = <$in> ) { + if( $str =~ /^###\s*(before|replace|after)\:\s?(.*)$/s ) { + my ($action, $nstr) = ($1,$2); + $nstr =~ s/\@($re_subst)\@/$subst->{$1}/ge; + + die "Replace action is bad idea for situations when dest is equal to source" + if $replace && $action eq 'replace'; + if( $action eq 'before' ) { + die "no line before 'before' action" unless @queue; + # overwrite prev line; + pop @queue; + push @queue, $nstr; + push @queue, $str; + } elsif( $action eq 'replace' ) { + push @queue, $nstr; + } elsif( $action eq 'after' ) { + push @queue, $str; + push @queue, $nstr; + # skip one line; + <$in>; + } + } else { + push @queue, $str; + } + while( @queue > 3 ) { + print $out shift(@queue); + } + } + while( scalar @queue ) { + print $out shift(@queue); + } +} + +1; + diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm index edc18b4..eeaa3fe 100644 --- a/inc/Module/Install/Win32.pm +++ b/inc/Module/Install/Win32.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm index d0f6599..85d8018 100644 --- a/inc/Module/Install/WriteAll.pm +++ b/inc/Module/Install/WriteAll.pm @@ -6,7 +6,7 @@ use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { - $VERSION = '1.00'; + $VERSION = '1.06'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } diff --git a/lib/RT/Extension/SearchResults/ODS.pm b/lib/RT/Extension/SearchResults/ODS.pm index a642a37..d7e4abe 100644 --- a/lib/RT/Extension/SearchResults/ODS.pm +++ b/lib/RT/Extension/SearchResults/ODS.pm @@ -9,11 +9,11 @@ RT::Extension::SearchResults::ODS - Add Excel format export to RT search results =head1 VERSION -Version 0.02 +Version 0.03 =cut -our $VERSION = '0.02'; +our $VERSION = '0.03'; =head1 SYNOPSIS @@ -72,7 +72,7 @@ L =head1 COPYRIGHT & LICENSE -Copyright 2011 Emmanuel Lacour, all rights reserved. +Copyright 2011-2014 Emmanuel Lacour, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.