aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/RABXColumn.pm18
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm2
2 files changed, 11 insertions, 9 deletions
diff --git a/perllib/FixMyStreet/DB/RABXColumn.pm b/perllib/FixMyStreet/DB/RABXColumn.pm
index d14b48dc8..76eb21030 100644
--- a/perllib/FixMyStreet/DB/RABXColumn.pm
+++ b/perllib/FixMyStreet/DB/RABXColumn.pm
@@ -52,6 +52,8 @@ set_filtered_column behaviour to not trust the cache.
sub rabx_column {
my ($class, $col) = @_;
+ my $data_type = $class->column_info($col)->{data_type};
+
# Apply the filtering for this column
$class->filter_column(
$col => {
@@ -59,6 +61,10 @@ sub rabx_column {
my $self = shift;
my $ser = shift;
return undef unless defined $ser;
+ # Some RABX columns are text, when they should be bytea. For
+ # these we must re-encode the string returned from the
+ # database, so that it is decoded again by RABX.
+ utf8::encode($ser) if $data_type ne 'bytea';
my $h = new IO::String($ser);
return RABX::wire_rd($h);
},
@@ -68,6 +74,10 @@ sub rabx_column {
my $ser = '';
my $h = new IO::String($ser);
RABX::wire_wr( $data, $h );
+ # Some RABX columns are text, when they should be bytea. For
+ # these, we must re-decode the string encoded by RABX, so that
+ # it is encoded again when saved to the db.
+ utf8::decode($ser) if $data_type ne 'bytea';
return $ser;
},
}
@@ -77,14 +87,6 @@ sub rabx_column {
$RABX_COLUMNS{ _get_class_identifier($class) }{$col} = 1;
}
-# The underlying column should always be UTF-8 encoded bytes.
-sub get_column {
- my ($self, $col) = @_;
- my $res = $self->next::method ($col);
- utf8::encode($res) if $RABX_COLUMNS{_get_class_identifier($self)}{$col} && utf8::is_utf8($res);
- return $res;
-}
-
sub set_filtered_column {
my ($self, $col, $val) = @_;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 37fc34057..dae946816 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -273,7 +273,7 @@ sub categories_summary {
sub include_comment_counts {
my $rs = shift;
my $order_by = $rs->{attrs}{order_by};
- return $rs unless ref $order_by eq 'HASH' && $order_by->{-desc} eq 'comment_count';
+ return $rs unless ref $order_by eq 'ARRAY' && ref $order_by->[0] eq 'HASH' && $order_by->[0]->{-desc} eq 'comment_count';
$rs->search({}, {
'+select' => [ {
"" => \'(select count(*) from comment where problem_id=me.id and state=\'confirmed\')',