[freeside-commits] branch FREESIDE_3_BRANCH updated. e6def4dfd7d855083fbe4859c8882c16dad9c582

Mark Wells mark at 420.am
Wed Jul 1 17:04:12 PDT 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  e6def4dfd7d855083fbe4859c8882c16dad9c582 (commit)
       via  2f598fd16823ad9ed461993840428e693e22c5fb (commit)
      from  a931e7703fc3b7b68a1e17c11cc9c76949372898 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e6def4dfd7d855083fbe4859c8882c16dad9c582
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Jul 1 19:37:47 2015 -0400

    another useful debugging tool

diff --git a/bin/fetch_pages b/bin/fetch_pages
new file mode 100755
index 0000000..0bcdcfa
--- /dev/null
+++ b/bin/fetch_pages
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+use strict;
+use WWW::Mechanize;
+use Getopt::Std;
+use File::chdir;
+use URI;
+use File::Slurp qw(write_file);
+
+my %opt;
+getopts('d:h:u:p:', \%opt);
+die usage() unless ($opt{d} and $opt{u} and $opt{p});
+my $host = $opt{h} || 'http://localhost/freeside';
+
+my $mech = WWW::Mechanize->new;
+$mech->credentials($opt{u}, $opt{p}); # 3.x auth only
+
+my @tests = <>;
+
+mkdir($opt{d}) unless -d $opt{d};
+push @CWD, $opt{d};
+
+while (my $path = shift @tests) {
+  if ($path =~ /^#(.*)/) {
+    print "$1 - skipped\n";
+    next;
+  }
+  my $uri = URI->new("$host/$path");
+  print $uri->path;
+  my $response = $mech->get($uri);
+  print " - " . $response->code . "\n";
+  if ($response->is_success) {
+    local $CWD;
+    my @dirs = $uri->path_segments;
+    my $file = pop @dirs;
+    foreach my $dir (@dirs) {
+      mkdir $dir unless -d $dir;
+      push @CWD, $dir;
+    }
+    write_file($file, {binmode => ':utf8'}, $response->decoded_content);
+  }
+}
+
+sub usage {
+  "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n";
+}
+
+=head1 NAME
+
+fetch_pages - a testing tool for UI changes
+
+=head1 USAGE
+
+fetch_pages -d before_change -u myuser -p mypass list_of_tests
+git checkout newbranch
+make install; apache2ctl restart
+fetch_pages -d after_change -u myuser -p mypass list_of_tests
+diff -ur before_change/ after_change/ |diffstat
+
+=head1 ARGUMENTS
+
+-d: the directory to put the files in. Required.
+
+-u: the username to use with the Freeside web interface. Required.
+
+-p: the password. Required.
+
+-h: the URL prefix for the Freeside server. Defaults to
+"http://localhost/freeside".
+
+The list of tests can be in a file specified after all arguments, or passed
+to stdin.
+
+=cut

commit 2f598fd16823ad9ed461993840428e693e22c5fb
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Jul 1 19:18:56 2015 -0400

    ensure all reports work correctly after #25994 changes

diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 80bc89d..f136832 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -245,6 +245,18 @@ $opt{disable_download} = 0
 $opt{disable_download} = 1
   if $opt{really_disable_download};
 
+# split/map aligns here, so that agent_virt can add a column
+# (search-html.html will split aligns also if they aren't already split)
+my %align = (
+  'l' => 'left',
+  'r' => 'right',
+  'c' => 'center',
+  ' ' => '',
+  '.' => '',
+);
+$opt{align} = [ map $align{$_}, split(//, $opt{align}) ],
+  unless !$opt{align} || ref($opt{align});
+
 # get our queries ready
 my $query = $opt{query} or die "query required";
 my $count_query = $opt{count_query} or die "count_query required";
@@ -265,11 +277,17 @@ if ( $opt{'agent_virt'} ) {
                         'table'      => $query->{'table'},
                       );
 
+  # this is ridiculous, but we do have searches where $query has constraints
+  # and $count_query doesn't, or vice versa.
   if ( $query->{'extra_sql'} =~ /\bWHERE\b/i or keys %{$query->{hashref}} ) {
     $query->{'extra_sql'} .= " AND $agentnums_sql";
-    $count_query .= " AND $agentnums_sql";
   } else {
     $query->{'extra_sql'} .= " WHERE $agentnums_sql";
+  }
+
+  if ( $count_query =~ /\bWHERE\b/i ) {
+    $count_query .= " AND $agentnums_sql";
+  } else {
     $count_query .= " WHERE $agentnums_sql";
   }
 
@@ -388,48 +406,55 @@ $order_by = $cgi->param('order_by') if $cgi->param('order_by');
 my $header = [ map { ref($_) ? $_->{'label'} : $_ } @{$opt{header}} ];
 my $rows;
 
-my @query;
-if (ref($query) eq 'HASH') {
-  @query = $query;
-
-  if ( $order_by ) {
-    if ( $query->{'order_by'} ) {
-      if ( $query->{'order_by'} =~ /^(\s*ORDER\s+BY\s+)?(\S.*)$/is ) {
-        $query->{'order_by'} = "ORDER BY $order_by, $2";
+if ( ref $query ) {
+  my @query;
+  if (ref($query) eq 'HASH') {
+    @query = $query;
+
+    if ( $order_by ) {
+      if ( $query->{'order_by'} ) {
+        if ( $query->{'order_by'} =~ /^(\s*ORDER\s+BY\s+)?(\S.*)$/is ) {
+          $query->{'order_by'} = "ORDER BY $order_by, $2";
+        } else {
+          warn "unparsable query order_by: ". $query->{'order_by'};
+          die "unparsable query order_by: ". $query->{'order_by'};
+        }
       } else {
-        warn "unparsable query order_by: ". $query->{'order_by'};
-        die "unparsable query order_by: ". $query->{'order_by'};
+        $query->{'order_by'} = "ORDER BY $order_by";
       }
-    } else {
-      $query->{'order_by'} = "ORDER BY $order_by";
     }
+
+    $query->{'order_by'} .= " $limit";
+
+  } elsif (ref($query) eq 'ARRAY') {
+    # do we still use this? it was for the old 477 report.
+    @query = @{ $query };
+  } else {
+    die "invalid query reference";
   }
 
-  $query->{'order_by'} .= " $limit";
+  #eval "use FS::$opt{'query'};";
+  my @param = qw( select table addl_from hashref extra_sql order_by debug );
+  $rows = [ qsearch( [ map { my $query = $_;
+                             ({ map { $_ => $query->{$_} } @param });
+                           }
+                       @query
+                     ],
+                     #'order_by' => $opt{order_by}. " ". $limit,
+                   )
+          ]; 
 
-} elsif (ref($query) eq 'ARRAY') {
-  # do we still use this? it was for the old 477 report.
-  @query = @{ $query };
-} else {
-  die "invalid query reference";
-}
+} else { # not ref $query; plain SQL (still used as of 07/2015)
 
-if ( $opt{disableable} && ! $cgi->param('showdisabled') ) {
-  #%search = ( 'disabled' => '' );
-  $opt{'query'}->{'hashref'}->{'disabled'} = '';
-  $opt{'query'}->{'extra_sql'} =~ s/^\s*WHERE/ AND/i;
-}
+  $query .= " $limit";
+  my $sth = dbh->prepare($query)
+    or die "Error preparing $query: ". dbh->errstr;
+  $sth->execute
+    or die "Error executing $query: ". $sth->errstr;
 
-#eval "use FS::$opt{'query'};";
-my @param = qw( select table addl_from hashref extra_sql order_by debug );
-$rows = [ qsearch( [ map { my $query = $_;
-                           ({ map { $_ => $query->{$_} } @param });
-                         }
-                     @query
-                   ],
-                   #'order_by' => $opt{order_by}. " ". $limit,
-                 )
-        ]; 
+  $rows = $sth->fetchall_arrayref;
+  $header ||= $sth->{NAME};
+}
 
 # run the count query to get number of rows and other totals
 my $count_sth = dbh->prepare($count_query);
diff --git a/httemplate/search/sql.html b/httemplate/search/sql.html
index 71aa006..54d6c2d 100644
--- a/httemplate/search/sql.html
+++ b/httemplate/search/sql.html
@@ -2,7 +2,7 @@
                'title' => 'Query Results',
                'name'  => 'rows',
                'query' => "SELECT $sql",
-          
+               'count_query' => $count,          
 &>
 <%init>
 
@@ -12,4 +12,7 @@ die "access denied"
 my $sql = $cgi->param('sql') or errorpage('Empty query');
 $sql =~ s/;+\s*$//; #remove trailing ;
 
+my $count = $sql;
+$count =~ s/.* FROM /SELECT COUNT(*) FROM /i;
+
 </%init>

-----------------------------------------------------------------------

Summary of changes:
 bin/fetch_pages                        |   74 +++++++++++++++++++++++++
 httemplate/search/elements/search.html |   95 ++++++++++++++++++++------------
 httemplate/search/sql.html             |    5 +-
 3 files changed, 138 insertions(+), 36 deletions(-)
 create mode 100755 bin/fetch_pages




More information about the freeside-commits mailing list