aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-06-26 11:25:36 +0100
committerMatthew Somerville <matthew@mysociety.org>2019-06-26 13:03:06 +0100
commit09c7f9d765e2a58c3e74eee0ed03612d19ee7f9f (patch)
tree378822f700570d4b3a0de9bd4cb1aede659c1bf2
parent62b19194a099e6e5ac1140aea0ed42744cdff786 (diff)
Turn on quote_names.
-rw-r--r--perllib/FixMyStreet.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm89
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm34
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm180
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Alert.pm7
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Comment.pm7
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm9
-rw-r--r--perllib/FixMyStreet/Script/Questionnaires.pm4
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm4
-rw-r--r--t/cobrand/form_extras.t2
11 files changed, 150 insertions, 189 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index f698b1610..f6a69928b 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -157,6 +157,7 @@ sub dbic_connect_info {
};
my $local_time_zone = local_time_zone();
my $dbic_args = {
+ quote_names => 1,
on_connect_do => [
"SET TIME ZONE '" . $local_time_zone->name . "'",
],
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 5f18f8557..65b24f238 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -143,47 +143,38 @@ sub timeline : Path( 'timeline' ) : Args(0) {
my %time;
- try {
- $c->model('DB')->schema->storage->sql_maker->quote_char( '"' );
- $c->model('DB')->schema->storage->sql_maker->name_sep( '.' );
+ my $probs = $c->cobrand->problems->timeline;
- my $probs = $c->cobrand->problems->timeline;
-
- foreach ($probs->all) {
- push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created, obj => $_ };
- push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed, obj => $_ } if $_->confirmed;
- push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent, obj => $_ } if $_->whensent;
- }
+ foreach ($probs->all) {
+ push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created, obj => $_ };
+ push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed, obj => $_ } if $_->confirmed;
+ push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent, obj => $_ } if $_->whensent;
+ }
- my $questionnaires = $c->model('DB::Questionnaire')->timeline( $c->cobrand->restriction );
+ my $questionnaires = $c->model('DB::Questionnaire')->timeline( $c->cobrand->restriction );
- foreach ($questionnaires->all) {
- push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent, obj => $_ };
- push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered;
- }
+ foreach ($questionnaires->all) {
+ push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent, obj => $_ };
+ push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered;
+ }
- my $updates = $c->cobrand->updates->timeline;
+ my $updates = $c->cobrand->updates->timeline;
- foreach ($updates->all) {
- push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ;
- }
+ foreach ($updates->all) {
+ push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ;
+ }
- my $alerts = $c->model('DB::Alert')->timeline_created( $c->cobrand->restriction );
+ my $alerts = $c->model('DB::Alert')->timeline_created( $c->cobrand->restriction );
- foreach ($alerts->all) {
- push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed, obj => $_ };
- }
+ foreach ($alerts->all) {
+ push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed, obj => $_ };
+ }
- $alerts = $c->model('DB::Alert')->timeline_disabled( $c->cobrand->restriction );
+ $alerts = $c->model('DB::Alert')->timeline_disabled( $c->cobrand->restriction );
- foreach ($alerts->all) {
- push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled, obj => $_ };
- }
- } catch {
- die $_;
- } finally {
- $c->model('DB')->schema->storage->sql_maker->quote_char( '' );
- };
+ foreach ($alerts->all) {
+ push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled, obj => $_ };
+ }
$c->stash->{time} = \%time;
@@ -244,7 +235,7 @@ sub reports : Path('reports') {
my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1;
$c->stash->{order} = $order;
$c->stash->{dir} = $dir;
- $order .= ' desc' if $dir;
+ $order = $dir ? { -desc => "me.$order" } : "me.$order";
my $p_page = $c->get_param('p') || 1;
my $u_page = $c->get_param('u') || 1;
@@ -272,26 +263,13 @@ sub reports : Path('reports') {
my $valid_phone = $parsed->{phone};
my $valid_email = $parsed->{email};
- # when DBIC creates the join it does 'JOIN users user' in the
- # SQL which makes PostgreSQL unhappy as user is a reserved
- # word. So look up user ID for email separately.
- my @user_ids = $c->model('DB::User')->search({
- email => { ilike => $like_search },
- }, { columns => [ 'id' ] } )->all;
- @user_ids = map { $_->id } @user_ids;
-
- my @user_ids_phone = $c->model('DB::User')->search({
- phone => { ilike => $like_search },
- }, { columns => [ 'id' ] } )->all;
- @user_ids_phone = map { $_->id } @user_ids_phone;
-
if ($valid_email) {
$query->{'-or'} = [
- 'me.user_id' => { -in => \@user_ids },
+ 'user.email' => { ilike => $like_search },
];
} elsif ($valid_phone) {
$query->{'-or'} = [
- 'me.user_id' => { -in => \@user_ids_phone },
+ 'user.phone' => { ilike => $like_search },
];
} elsif ($search =~ /^id:(\d+)$/) {
$query->{'-or'} = [
@@ -308,7 +286,8 @@ sub reports : Path('reports') {
} else {
$query->{'-or'} = [
'me.id' => $search_n,
- 'me.user_id' => { -in => [ @user_ids, @user_ids_phone ] },
+ 'user.email' => { ilike => $like_search },
+ 'user.phone' => { ilike => $like_search },
'me.external_id' => { ilike => $like_search },
'me.name' => { ilike => $like_search },
'me.title' => { ilike => $like_search },
@@ -321,8 +300,9 @@ sub reports : Path('reports') {
my $problems = $c->cobrand->problems->search(
$query,
{
+ prefetch => 'user',
rows => 50,
- order_by => [ \"(state='hidden')", \$order ]
+ order_by => [ \"(state='hidden')", $order ]
}
)->page( $p_page );
@@ -331,11 +311,11 @@ sub reports : Path('reports') {
if ($valid_email) {
$query = [
- 'me.user_id' => { -in => \@user_ids },
+ 'user.email' => { ilike => $like_search },
];
} elsif ($valid_phone) {
$query = [
- 'me.user_id' => { -in => \@user_ids_phone },
+ 'user.phone' => { ilike => $like_search },
];
} elsif ($search =~ /^id:(\d+)$/) {
$query = [
@@ -348,7 +328,8 @@ sub reports : Path('reports') {
$query = [
'me.id' => $search_n,
'problem.id' => $search_n,
- 'me.user_id' => { -in => [ @user_ids, @user_ids_phone ] },
+ 'user.email' => { ilike => $like_search },
+ 'user.phone' => { ilike => $like_search },
'me.name' => { ilike => $like_search },
text => { ilike => $like_search },
'me.cobrand_data' => { ilike => $like_search },
@@ -362,7 +343,7 @@ sub reports : Path('reports') {
},
{
-select => [ 'me.*', qw/problem.bodies_str problem.state/ ],
- prefetch => [qw/problem/],
+ prefetch => [qw/user problem/],
rows => 50,
order_by => [ \"(me.state='hidden')", \"(problem.state='hidden')", { -desc => 'me.created' } ]
}
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index ea9b26e7a..0ccf488c7 100644
--- a/perllib/FixMyStreet/Cobrand/BathNES.pm
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -193,24 +193,16 @@ sub categories_restriction {
] } );
}
-# Do a manual prefetch, as easier than sorting out quoting 'user'
+# Do a manual prefetch of all staff users for contributed_by lookup
sub _dashboard_user_lookup {
my $self = shift;
my $c = $self->{c};
- # Fetch all the relevant user IDs, and look them up
- my @user_ids = $c->stash->{objects_rs}->search({}, { columns => [ 'user_id' ] })->all;
- @user_ids = map { $_->user_id } @user_ids;
- @user_ids = $c->model('DB::User')->search(
- { id => { -in => \@user_ids } },
- { columns => [ 'id', 'email', 'phone' ] })->all;
-
- # Plus all staff users for contributed_by lookup
- push @user_ids, $c->model('DB::User')->search(
+ my @user_ids = $c->model('DB::User')->search(
{ from_body => { '!=' => undef } },
- { columns => [ 'id', 'email', 'phone' ] })->all;
+ { columns => [ 'id', 'email' ] })->all;
- my %user_lookup = map { $_->id => { email => $_->email, phone => $_->phone } } @user_ids;
+ my %user_lookup = map { $_->id => $_->email } @user_ids;
return \%user_lookup;
}
@@ -225,6 +217,10 @@ sub dashboard_export_updates_add_columns {
push @{$c->stash->{csv}->{columns}}, "staff_user";
push @{$c->stash->{csv}->{columns}}, "user_email";
+ $c->stash->{csv}->{objects} = $c->stash->{csv}->{objects}->search(undef, {
+ '+columns' => ['user.email'],
+ prefetch => 'user',
+ });
my $user_lookup = $self->_dashboard_user_lookup;
$c->stash->{csv}->{extra_data} = sub {
@@ -232,11 +228,11 @@ sub dashboard_export_updates_add_columns {
my $staff_user = '';
if ( my $contributed_by = $report->get_extra_metadata('contributed_by') ) {
- $staff_user = $user_lookup->{$contributed_by}{email};
+ $staff_user = $user_lookup->{$contributed_by};
}
return {
- user_email => $user_lookup->{$report->user_id}{email} || '',
+ user_email => $report->user->email || '',
staff_user => $staff_user,
};
};
@@ -264,6 +260,10 @@ sub dashboard_export_problems_add_columns {
"attribute_data",
];
+ $c->stash->{csv}->{objects} = $c->stash->{csv}->{objects}->search(undef, {
+ '+columns' => ['user.email', 'user.phone'],
+ prefetch => 'user',
+ });
my $user_lookup = $self->_dashboard_user_lookup;
$c->stash->{csv}->{extra_data} = sub {
@@ -271,12 +271,12 @@ sub dashboard_export_problems_add_columns {
my $staff_user = '';
if ( my $contributed_by = $report->get_extra_metadata('contributed_by') ) {
- $staff_user = $user_lookup->{$contributed_by}{email};
+ $staff_user = $user_lookup->{$contributed_by};
}
my $attribute_data = join "; ", map { $_->{name} . " = " . $_->{value} } @{ $report->get_extra_fields };
return {
- user_email => $user_lookup->{$report->user_id}{email} || '',
- user_phone => $user_lookup->{$report->user_id}{phone} || '',
+ user_email => $report->user->email || '',
+ user_phone => $report->user->phone || '',
staff_user => $staff_user,
attribute_data => $attribute_data,
};
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 9b6a3b9cb..5fea9a03f 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -460,7 +460,7 @@ sub admin {
my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1;
$c->stash->{order} = $order;
$c->stash->{dir} = $dir;
- $order .= ' desc' if $dir;
+ $order = { -desc => $order } if $dir;
# XXX No multiples or missing bodies
$c->stash->{submitted} = $c->cobrand->problems->search({
@@ -494,7 +494,7 @@ sub admin {
my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1;
$c->stash->{order} = $order;
$c->stash->{dir} = $dir;
- $order .= ' desc' if $dir;
+ $order = { -desc => $order } if $dir;
# XXX No multiples or missing bodies
$c->stash->{reports_new} = $c->cobrand->problems->search( {
@@ -1202,100 +1202,94 @@ sub admin_stats {
sub export_as_csv {
my ($self, $c, $params) = @_;
- try {
- $c->model('DB')->schema->storage->sql_maker->quote_char('"');
- my $csv = $c->stash->{csv} = {
- objects => $c->model('DB::Problem')->search_rs(
- $params,
- {
- join => ['admin_log_entries', 'user'],
- distinct => 1,
- columns => [
- 'id', 'created',
- 'latitude', 'longitude',
- 'cobrand', 'category',
- 'state', 'user_id',
- 'external_body',
- 'title', 'detail',
- 'photo',
- 'whensent', 'lastupdate',
- 'service',
- 'extra',
- { sum_time_spent => { sum => 'admin_log_entries.time_spent' } },
- 'name', 'user.id', 'user.email', 'user.phone', 'user.name',
- ]
- }
- ),
- headers => [
- 'Report ID', 'Created', 'Sent to Agency', 'Last Updated',
- 'E', 'N', 'Category', 'Status', 'Closure Status',
- 'UserID', 'User email', 'User phone', 'User name',
- 'External Body', 'Time Spent', 'Title', 'Detail',
- 'Media URL', 'Interface Used', 'Council Response',
- 'Strasse', 'Mast-Nr.', 'Haus-Nr.', 'Hydranten-Nr.',
- ],
- columns => [
- 'id', 'created', 'whensent',' lastupdate', 'local_coords_x',
- 'local_coords_y', 'category', 'state', 'closure_status',
- 'user_id', 'user_email', 'user_phone', 'user_name',
- 'body_name', 'sum_time_spent', 'title', 'detail',
- 'media_url', 'service', 'public_response',
- 'strasse', 'mast_nr',' haus_nr', 'hydranten_nr',
- ],
- extra_data => sub {
- my $report = shift;
-
- my $body_name = "";
- if ( my $external_body = $report->body($c) ) {
- $body_name = $external_body->name || '[Unknown body]';
- }
- my $detail = $report->detail;
- my $public_response = $report->get_extra_metadata('public_response') || '';
- my $metas = $report->get_extra_fields();
- my %extras;
- foreach my $field (@$metas) {
- $extras{$field->{name}} = $field->{value};
- }
+ my $csv = $c->stash->{csv} = {
+ objects => $c->model('DB::Problem')->search_rs(
+ $params,
+ {
+ join => ['admin_log_entries', 'user'],
+ distinct => 1,
+ columns => [
+ 'id', 'created',
+ 'latitude', 'longitude',
+ 'cobrand', 'category',
+ 'state', 'user_id',
+ 'external_body',
+ 'title', 'detail',
+ 'photo',
+ 'whensent', 'lastupdate',
+ 'service',
+ 'extra',
+ { sum_time_spent => { sum => 'admin_log_entries.time_spent' } },
+ 'name', 'user.id', 'user.email', 'user.phone', 'user.name',
+ ]
+ }
+ ),
+ headers => [
+ 'Report ID', 'Created', 'Sent to Agency', 'Last Updated',
+ 'E', 'N', 'Category', 'Status', 'Closure Status',
+ 'UserID', 'User email', 'User phone', 'User name',
+ 'External Body', 'Time Spent', 'Title', 'Detail',
+ 'Media URL', 'Interface Used', 'Council Response',
+ 'Strasse', 'Mast-Nr.', 'Haus-Nr.', 'Hydranten-Nr.',
+ ],
+ columns => [
+ 'id', 'created', 'whensent',' lastupdate', 'local_coords_x',
+ 'local_coords_y', 'category', 'state', 'closure_status',
+ 'user_id', 'user_email', 'user_phone', 'user_name',
+ 'body_name', 'sum_time_spent', 'title', 'detail',
+ 'media_url', 'service', 'public_response',
+ 'strasse', 'mast_nr',' haus_nr', 'hydranten_nr',
+ ],
+ extra_data => sub {
+ my $report = shift;
+
+ my $body_name = "";
+ if ( my $external_body = $report->body($c) ) {
+ $body_name = $external_body->name || '[Unknown body]';
+ }
- # replace newlines with HTML <br/> element
- $detail =~ s{\r?\n}{ <br/> }g;
- $public_response =~ s{\r?\n}{ <br/> }g if $public_response;
-
- # Assemble photo URL, if report has a photo
- my $photo_to_display = $c->cobrand->allow_photo_display($report);
- my $media_url = (@{$report->photos} && $photo_to_display)
- ? $c->cobrand->base_url . $report->photos->[$photo_to_display-1]->{url}
- : '';
-
- return {
- whensent => $report->whensent,
- lastupdate => $report->lastupdate,
- user_id => $report->user_id,
- user_email => $report->user->email || '',
- user_phone => $report->user->phone || '',
- user_name => $report->name,
- closure_status => $report->get_extra_metadata('closure_status') || '',
- body_name => $body_name,
- sum_time_spent => $report->get_column('sum_time_spent') || 0,
- detail => $detail,
- media_url => $media_url,
- service => $report->service || 'Web interface',
- public_response => $public_response,
- strasse => $extras{'strasse'} || '',
- mast_nr => $extras{'mast_nr'} || '',
- haus_nr => $extras{'haus_nr'} || '',
- hydranten_nr => $extras{'hydranten_nr'} || ''
- };
- },
- filename => 'stats',
- };
- $c->forward('/dashboard/generate_csv');
- } catch {
- die $_;
- } finally {
- $c->model('DB')->schema->storage->sql_maker->quote_char('');
+ my $detail = $report->detail;
+ my $public_response = $report->get_extra_metadata('public_response') || '';
+ my $metas = $report->get_extra_fields();
+ my %extras;
+ foreach my $field (@$metas) {
+ $extras{$field->{name}} = $field->{value};
+ }
+
+ # replace newlines with HTML <br/> element
+ $detail =~ s{\r?\n}{ <br/> }g;
+ $public_response =~ s{\r?\n}{ <br/> }g if $public_response;
+
+ # Assemble photo URL, if report has a photo
+ my $photo_to_display = $c->cobrand->allow_photo_display($report);
+ my $media_url = (@{$report->photos} && $photo_to_display)
+ ? $c->cobrand->base_url . $report->photos->[$photo_to_display-1]->{url}
+ : '';
+
+ return {
+ whensent => $report->whensent,
+ lastupdate => $report->lastupdate,
+ user_id => $report->user_id,
+ user_email => $report->user->email || '',
+ user_phone => $report->user->phone || '',
+ user_name => $report->name,
+ closure_status => $report->get_extra_metadata('closure_status') || '',
+ body_name => $body_name,
+ sum_time_spent => $report->get_column('sum_time_spent') || 0,
+ detail => $detail,
+ media_url => $media_url,
+ service => $report->service || 'Web interface',
+ public_response => $public_response,
+ strasse => $extras{'strasse'} || '',
+ mast_nr => $extras{'mast_nr'} || '',
+ haus_nr => $extras{'haus_nr'} || '',
+ hydranten_nr => $extras{'hydranten_nr'} || ''
+ };
+ },
+ filename => 'stats',
};
+ $c->forward('/dashboard/generate_csv');
}
sub problem_confirm_email_extras {
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 7251bc863..afbeda88a 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -246,7 +246,7 @@ sub calculate_average {
'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
select => [
- { extract => "epoch from me.confirmed-problem.confirmed", -as => 'time' },
+ { extract => \"epoch from me.confirmed-problem.confirmed", -as => 'time' },
],
as => [ qw/time/ ],
rows => 100,
diff --git a/perllib/FixMyStreet/DB/ResultSet/Alert.pm b/perllib/FixMyStreet/DB/ResultSet/Alert.pm
index c61053fff..ddf80bc52 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Alert.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Alert.pm
@@ -7,11 +7,6 @@ use warnings;
sub timeline_created {
my ( $rs, $restriction ) = @_;
- my $prefetch =
- $rs->result_source->storage->sql_maker->quote_char ?
- [ qw/alert_type user/ ] :
- [ qw/alert_type/ ];
-
return $rs->search(
{
whensubscribed => { '>=', \"current_timestamp-'7 days'::interval" },
@@ -19,7 +14,7 @@ sub timeline_created {
%{ $restriction },
},
{
- prefetch => $prefetch,
+ prefetch => [ qw/alert_type user/ ],
}
);
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm
index b9a3df62d..034b86a40 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm
@@ -13,18 +13,13 @@ sub to_body {
sub timeline {
my ( $rs ) = @_;
- my $prefetch =
- $rs->result_source->storage->sql_maker->quote_char ?
- [ qw/user/ ] :
- [];
-
return $rs->search(
{
'me.state' => 'confirmed',
'me.created' => { '>=', \"current_timestamp-'7 days'::interval" },
},
{
- prefetch => $prefetch,
+ prefetch => 'user',
}
);
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 4f7c1dc5f..72a9852fc 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -141,7 +141,7 @@ sub _recent {
$query->{photo} = { '!=', undef } if $photos;
my $attrs = {
- order_by => { -desc => 'coalesce(confirmed, created)' },
+ order_by => { -desc => \'coalesce(confirmed, created)' },
rows => $num,
};
@@ -207,11 +207,6 @@ sub around_map {
sub timeline {
my ( $rs ) = @_;
- my $prefetch =
- $rs->result_source->storage->sql_maker->quote_char ?
- [ qw/user/ ] :
- [];
-
return $rs->search(
{
-or => {
@@ -221,7 +216,7 @@ sub timeline {
}
},
{
- prefetch => $prefetch,
+ prefetch => 'user',
}
);
}
diff --git a/perllib/FixMyStreet/Script/Questionnaires.pm b/perllib/FixMyStreet/Script/Questionnaires.pm
index aab4b9b75..5db66ff7c 100644
--- a/perllib/FixMyStreet/Script/Questionnaires.pm
+++ b/perllib/FixMyStreet/Script/Questionnaires.pm
@@ -33,8 +33,8 @@ sub send_questionnaires_period {
};
$q_params->{'-or'} = [
- '(select max(whensent) from questionnaire where me.id=problem_id)' => undef,
- '(select max(whenanswered) from questionnaire where me.id=problem_id)' => { '<', \"current_timestamp - '$period'::interval" }
+ \'(select max(whensent) from questionnaire where me.id=problem_id) IS NULL',
+ \"(select max(whenanswered) from questionnaire where me.id=problem_id) < current_timestamp - '$period'::interval",
];
my $unsent = FixMyStreet::DB->resultset('Problem')->search( $q_params, {
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm
index 33665b9da..b23ed5b6a 100755
--- a/perllib/FixMyStreet/Script/UpdateAllReports.pm
+++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm
@@ -36,8 +36,8 @@ sub generate {
{
columns => [
'id', 'bodies_str', 'state', 'areas', 'cobrand', 'category',
- { duration => { extract => "epoch from current_timestamp-lastupdate" } },
- { age => { extract => "epoch from current_timestamp-$age_column" } },
+ { duration => { extract => \"epoch from current_timestamp-lastupdate" } },
+ { age => { extract => \"epoch from current_timestamp-$age_column" } },
]
}
);
diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t
index df76ccbe1..3807dd56a 100644
--- a/t/cobrand/form_extras.t
+++ b/t/cobrand/form_extras.t
@@ -84,7 +84,7 @@ FixMyStreet::override_config {
);
$mech->content_contains('Now check your email');
- my $problem = FixMyStreet::DB->resultset('Problem')->search({}, { order_by => '-id' })->first;
+ my $problem = FixMyStreet::DB->resultset('Problem')->search({}, { order_by => { -desc => 'id' } })->first;
is $problem->get_extra_metadata('address'), 'My address', 'Address is stored';
is $problem->get_extra_metadata('passport'), 'P123456', 'Passport number is stored';
};