aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-07-06 12:10:46 +0100
committerMatthew Somerville <matthew@mysociety.org>2012-07-06 12:10:46 +0100
commit842ff2b00f4924f8580710c977ccce7bef33b0c2 (patch)
treee2ab4fda5a811b214fb4f501208f98f07a2c3c41 /perllib/FixMyStreet
parentdeb369669b540f607e435390f4606b927569dded (diff)
Factor out the SQL restriction from site_restriction, as it's only used in one place.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm11
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm6
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm4
8 files changed, 23 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 871da737f..3bcadd758 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -50,7 +50,7 @@ sub index : Path : Args(0) {
$c->forward('check_page_allowed');
- my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction();
+ my ( $id, $site_restriction ) = $c->cobrand->site_restriction();
my $problems = $c->cobrand->problems->summary_count;
@@ -122,7 +122,7 @@ sub timeline : Path( 'timeline' ) : Args(0) {
$c->forward('check_page_allowed');
- my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction();
+ my ( $id, $site_restriction ) = $c->cobrand->site_restriction();
my %time;
$c->model('DB')->schema->storage->sql_maker->quote_char( '"' );
@@ -472,7 +472,7 @@ sub search_reports : Path('search_reports') {
if (my $search = $c->req->param('search')) {
$c->stash->{searched} = 1;
- my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction;
+ my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction;
my $search_n = 0;
$search_n = int($search) if $search =~ /^\d+$/;
@@ -574,7 +574,7 @@ sub search_reports : Path('search_reports') {
sub report_edit : Path('report_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
- my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction;
+ my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction;
my $problem = $c->cobrand->problems->search(
{
@@ -735,8 +735,7 @@ sub search_users: Path('search_users') : Args(0) {
sub update_edit : Path('update_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
- my ( $site_res_sql, $site_key, $site_restriction ) =
- $c->cobrand->site_restriction;
+ my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction;
my $update = $c->model('DB::Comment')->search(
{
id => $id,
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index 4d0b6cb93..f898d06a0 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -205,14 +205,14 @@ sub query_main : Private {
my ( $self, $c ) = @_;
my $alert_type = $c->stash->{alert_type};
- my ( $site_restriction, $site_id ) = $c->cobrand->site_restriction( $c->cobrand->extra_data );
+ my ( $sql_restriction ) = $c->cobrand->sql_restriction( $c->cobrand->extra_data );
# Only apply a site restriction if the alert uses the problem table
- $site_restriction = '' unless $alert_type->item_table eq 'problem';
+ $sql_restriction = '' unless $alert_type->item_table eq 'problem';
# FIXME Do this in a nicer way at some point in the future...
my $query = 'select * from ' . $alert_type->item_table . ' where '
. ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '')
- . $alert_type->item_where . $site_restriction . ' order by '
+ . $alert_type->item_where . $sql_restriction . ' order by '
. $alert_type->item_order;
my $rss_limit = mySociety::Config::get('RSS_LIMIT');
$query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/;
diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm
index b88f6facc..d694e4bdb 100644
--- a/perllib/FixMyStreet/Cobrand.pm
+++ b/perllib/FixMyStreet/Cobrand.pm
@@ -38,7 +38,7 @@ Simply returns the config variable (so this function can be overridden in test s
=cut
sub _get_allowed_cobrands {
- return FixMyStreet->config('ALLOWED_COBRANDS');
+ return FixMyStreet->config('ALLOWED_COBRANDS') || [];
}
=head2 available_cobrand_classes
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index b06c534ac..aabf708f8 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -50,7 +50,8 @@ empty string and site key 0 if the cobrand uses all the data.
=cut
-sub site_restriction { return ( "", 0, {} ) }
+sub site_restriction { return ( 0, {} ) }
+sub sql_restriction { return ""; }
=head2 restriction
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index 804289d34..014981daf 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -12,7 +12,10 @@ sub council_url { return 'lichfielddc'; }
# Different to councils parent due to this being a two-tier council. If we get
# more, this can be genericised in the parent.
sub site_restriction {
- return ( "and council like '%2434%'", 'lichfield', { council => '2434' } );
+ return ( 'lichfield', { council => '2434' } );
+}
+sub sql_restriction {
+ return "and council like '%2434%'";
}
sub problems_clause {
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index 8a6954418..036e2684a 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -13,7 +13,11 @@ sub is_council {
sub site_restriction {
my $self = shift;
- return ( "and council='" . $self->council_id . "'", $self->council_url, { council => sprintf('%d', $self->council_id) } );
+ return ( $self->council_url, { council => sprintf('%d', $self->council_id) } );
+}
+sub sql_restriction {
+ my $self = shift;
+ return "and council='" . $self->council_id . "'";
}
sub restriction {
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 26d8f32a9..b985ccad6 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -65,7 +65,7 @@ sub email_alerts ($) {
# call checks if this is the host that sends mail for this cobrand.
next unless $cobrand->email_host;
- my ( $sql_restriction, $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} );
+ my ( $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} );
FixMyStreet::App->model('DB::AlertSent')->create( {
alert_id => $row->{alert_id},
@@ -141,7 +141,7 @@ sub email_alerts ($) {
my $longitude = $alert->parameter;
my $latitude = $alert->parameter2;
- my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data );
+ my ($site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data );
my $d = mySociety::Gaze::get_radius_containing_population($latitude, $longitude, 200000);
# Convert integer to GB locale string (with a ".")
$d = mySociety::Locale::in_gb_locale {
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index a7738becf..c4fd07615 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -14,13 +14,11 @@ use mySociety::MaPit;
use FixMyStreet::App;
use FixMyStreet::SendReport;
-my $site_restriction;
my $site_key;
sub set_restriction {
- my ( $rs, $sql, $key, $restriction ) = @_;
+ my ( $rs, $key, $restriction ) = @_;
$site_key = $key;
- $site_restriction = $restriction;
}
# Front page statistics