Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • gg/redmine-sync
1 result
Select Git revision
  • master
1 result
Show changes
Commits on Source (4)
@*
ts.*
*.tsv
.*.swp
typescript
tmp/
export/
......@@ -56,8 +56,12 @@ EOPOD
=head2 Overview
help [topic] (this overview)
list
show ticket
list ... list tickets in current project
show ticket ... show ticket with this number
att ticket nr ... download attachment nr <nr> from ticket <ticket>
instances ... list all instances
projects ... list all projects
=cut
EOPOD
......@@ -277,6 +281,8 @@ sub interpret
return undef;
}
my @res;
if ($op_mode eq 'help') { usage('help', (@$pars) ? shift (@$pars) : 'overview'); }
elsif ($op_mode eq 'exit') { return 0; }
elsif ($op_mode eq 'interact' || $op_mode eq 'i')
......@@ -334,6 +340,7 @@ sub interpret
my $out_tsv= $self->{out_tsv};
my ($proj_list, $csv)= Redmine::CLI::show_projects ($rm, $out_tsv);
$self->{project_list}= $proj_list;
push (@res, $proj_list);
}
elsif ($op_mode eq 'wiki')
{
......@@ -371,7 +378,19 @@ sub interpret
push (@$pars, $self->{ticket_number}) if (!@$pars && exists ($self->{ticket_number}));
foreach my $ticket_number (@$pars)
{
Redmine::CLI::show_issue ($rm, $ticket_number);
my $issue= Redmine::CLI::show_issue ($rm, $ticket_number);
$self->{ticket_number}= $ticket_number;
push (@res, $issue);
}
}
elsif ($op_mode eq 'att')
{
my $rm= $mRM->attach();
push (@$pars, $self->{ticket_number}) if (!@$pars && exists ($self->{ticket_number}));
my $att_nr= $pars->[1];
foreach my $ticket_number (@$pars)
{
Redmine::CLI::download_attachment ($rm, $ticket_number, $att_nr);
$self->{ticket_number}= $ticket_number;
}
}
......@@ -438,7 +457,7 @@ not needed?
=end comment
=cut
return 1;
return (1, \@res);
}
sub interact
......@@ -459,7 +478,7 @@ sub interact
my ($op, @pars)= split (' ', $l);
print "op=[$op]\n";
my $continue= interpret ($self, $op, \@pars);
my ($continue)= interpret ($self, $op, \@pars);
last unless ($continue);
}
}
......@@ -726,6 +745,41 @@ sub show_issue
$issue;
}
sub download_attachment
{
my $rm= shift;
my $ticket_number= shift;
my $number= shift;
my $ua= $rm->{ua};
return undef unless (defined ($ua));
my $issue= $rm->issue( $ticket_number, { include => 'attachments' } );
my $attachments= $issue->{issue}->{attachments};
# print "attachments: ", Dumper ($attachments);
return undef unless (defined ($attachments));
my @attachment_numbers;
if (!defined ($number) || $number eq '*') { push (@attachment_numbers, 0 .. $#$attachments); }
elsif ($number =~ /^\d+$/) { @attachment_numbers= $number; }
elsif ($number =~ /^\d[\d,-]*\d$/) { print "number ranges not yet implemented\n"; return undef; }
print __LINE__, " attachment_numbers: ", join(' ', @attachment_numbers), "\n";
my @dl_attachments;
foreach my $num (@attachment_numbers)
{
my $attachment= $attachments->[$num];
next unless (defined ($attachment));
# print __LINE__, " attachment: ", Dumper ($attachment);
print __LINE__, " attachment num=[$num] ", $attachment->{filename}, "\n";
$ua->get($attachment->{content_url}, ':content_file' => $attachment->{filename});
push (@dl_attachments, $attachment);
}
return (wantarray) ? @dl_attachments : \@dl_attachments;
}
sub usage
{
my $pod= new Pod::Simple::Text();
......
......@@ -31,7 +31,8 @@ sub connect
# print "db_con=[$db_con]\n";
$dbh= DBI->connect($db_con, map { $self->{$_} } qw(username password));
# print "dbh=[$dbh]\n";
print join(' ', __FILE__, __LINE__, 'caller', caller(), "dbh=[$dbh]\n");
# exit;
if (exists ($self->{encoding}))
{
......@@ -110,14 +111,14 @@ sub get_all_x
my $t= $self->table($table);
my $tt= {};
my $pri= (exists ($self->{PRI}->{$table})) ? $self->{PRI}->{$table} : 'id';
my $pri= (exists ($self->{PRI}->{$table})) ? $self->{PRI}->{$table} : ['id'];
# print __LINE__, " pri=[$pri] ", main::Dumper ($self->{PRI});
# print __LINE__, " pri=[$pri]\n";
# print __LINE__, " table=[$table] pri=[$pri]\n";
while (defined (my $x= $sth->fetchrow_hashref()))
{
print "x: ", Dumper ($x) if ($show_fetched);
my $i= $x->{$pri};
my $i= join(',', map { $x->{$_} } @$pri);
$t->{$i}= $tt->{$i}= $x;
}
......@@ -224,6 +225,7 @@ sub desc
# my @desc_columns= qw(Field Type Null Key Default Extra);
my @PRI;
while (my @x= $sth->fetchrow_array())
{
last unless (@x);
......@@ -232,10 +234,14 @@ sub desc
if ($x[3] eq 'PRI')
{
$self->{PRI}->{$table}= $x[0];
push (@PRI, $x[0]);
}
}
my $PRI= join(',', @PRI);
$self->{PRI}->{$table}= \@PRI;
# print join(' ', __FILE__, __LINE__, 'table:', $table, 'PRI:', $PRI), "\n";
$td;
}
......@@ -299,13 +305,31 @@ sub update
push (@vars, $an);
push (@vals, $updates->{$an});
}
push (@vals, $id);
my $pri= (exists ($self->{PRI}->{$table})) ? $self->{PRI}->{$table} : 'id';
# print __LINE__, " pri=[$pri] ", main::Dumper ($self->{PRI});
# print __LINE__, " pri=[$pri]\n";
my $ssu= "UPDATE `$table` SET ". join (', ', map { $_.'=?' } @vars) . " WHERE `$pri`=?"; # Hmm... WHERE ?=?
# ATTN: $pri is a array ref with the column names forming the primary key; there can be more than one!!
# TODO: currently only the first variable name is used with a value!
print __LINE__, " caller: ", join(' ', caller()), "\n";
my @conditions;
if (ref($pri) eq 'ARRAY')
{
foreach my $attr_name (@$pri)
{
push (@conditions, "`$attr_name`=?");
}
push (@vals, @$id);
}
else
{
push (@conditions, "`$pri`=?");
push (@vals, $id);
}
my $ssu= "UPDATE `$table` SET ". join (', ', map { $_.'=?' } @vars) . " WHERE " . join (' AND ', @conditions); # Hmm... WHERE ?=?
if ($show_updates)
{
......