diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-07-06 12:49:40 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-07-06 12:49:40 +0100 |
commit | 9a696b0cb64667ed4608021771aed441a09f3ac0 (patch) | |
tree | f8e12b152e0ca745c651a268abb907ecad6d8d59 | |
parent | 842ff2b00f4924f8580710c977ccce7bef33b0c2 (diff) |
Factor out site_key as that's only used in one place too.
-rw-r--r-- | perllib/FixMyStreet/App.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 2 |
7 files changed, 20 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 6ccc801ce..2f199f4bf 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -177,7 +177,7 @@ sub setup_request { $c->log->debug( sprintf "Set lang to '%s' and cobrand to '%s'", $set_lang, $cobrand->moniker ); - $c->model('DB::Problem')->set_restriction( $cobrand->site_restriction() ); + $c->model('DB::Problem')->set_restriction( $cobrand->site_key() ); Memcached::set_namespace( FixMyStreet->config('FMS_DB_NAME') . ":" ); diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 3bcadd758..58977473f 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 ( $id, $site_restriction ) = $c->cobrand->site_restriction(); + my $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 ( $id, $site_restriction ) = $c->cobrand->site_restriction(); + my $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_key, $site_restriction ) = $c->cobrand->site_restriction; + my $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_key, $site_restriction ) = $c->cobrand->site_restriction; + my $site_restriction = $c->cobrand->site_restriction; my $problem = $c->cobrand->problems->search( { @@ -735,7 +735,7 @@ sub search_users: Path('search_users') : Args(0) { sub update_edit : Path('update_edit') : Args(1) { my ( $self, $c, $id ) = @_; - my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my $site_restriction = $c->cobrand->site_restriction; my $update = $c->model('DB::Comment')->search( { id => $id, diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index aabf708f8..a987cf65d 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -50,8 +50,9 @@ empty string and site key 0 if the cobrand uses all the data. =cut -sub site_restriction { return ( 0, {} ) } sub sql_restriction { return ""; } +sub site_restriction { return {}; } +sub site_key { return 0; } =head2 restriction diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 014981daf..1627616bd 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -12,11 +12,14 @@ 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 ( 'lichfield', { council => '2434' } ); + return { council => '2434' }; } sub sql_restriction { return "and council like '%2434%'"; } +sub site_key { + return 'lichfield'; +} sub problems_clause { return { council => { like => '%2434%' } }; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 036e2684a..bb71bdd35 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -13,12 +13,16 @@ sub is_council { sub site_restriction { my $self = shift; - return ( $self->council_url, { council => sprintf('%d', $self->council_id) } ); + return { council => sprintf('%d', $self->council_id) }; } sub sql_restriction { my $self = shift; return "and council='" . $self->council_id . "'"; } +sub site_key { + my $self = shift; + return $self->council_url; +} sub restriction { return { cobrand => shift->moniker }; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index b985ccad6..981b8e8f7 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 ( $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} ); + my $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_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data ); + my $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 c4fd07615..a689e80a9 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -17,7 +17,7 @@ use FixMyStreet::SendReport; my $site_key; sub set_restriction { - my ( $rs, $key, $restriction ) = @_; + my ( $rs, $key ) = @_; $site_key = $key; } |