diff options
-rwxr-xr-x | bin/fixmystreet.com/fixture | 2 | ||||
-rwxr-xr-x | bin/oxfordshire/send-rdi-emails | 2 | ||||
-rwxr-xr-x | bin/zurich/overdue-alert | 4 | ||||
-rwxr-xr-x | db/rerun_dbic_loader.pl | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/DB.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Schema.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 4 | ||||
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Test.pm | 2 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 2 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 2 | ||||
-rw-r--r-- | t/app/model/extra.t | 2 | ||||
-rw-r--r-- | t/app/model/photoset.t | 2 | ||||
-rw-r--r-- | t/app/sendreport/open311.t | 2 |
15 files changed, 54 insertions, 29 deletions
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture index d3b0a8349..912d34aab 100755 --- a/bin/fixmystreet.com/fixture +++ b/bin/fixmystreet.com/fixture @@ -31,7 +31,7 @@ my ($opt, $usage) = describe_options( ); print($usage->text), exit if $opt->help; -my $db = FixMyStreet::DB->storage; +my $db = FixMyStreet::DB->schema->storage; $db->txn_begin; END { if ($db) { diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails index 11e7a6fe9..9eff02715 100755 --- a/bin/oxfordshire/send-rdi-emails +++ b/bin/oxfordshire/send-rdi-emails @@ -55,7 +55,7 @@ foreach my $inspector (@inspectors) { }; my $result = FixMyStreet::Email::send_cron( - FixMyStreet::DB->storage->schema, + FixMyStreet::DB->schema, "rdi.txt", $params, $hdrs, undef, 0, $cobrand, ); diff --git a/bin/zurich/overdue-alert b/bin/zurich/overdue-alert index 90e31df1c..f4fd0f4b7 100755 --- a/bin/zurich/overdue-alert +++ b/bin/zurich/overdue-alert @@ -38,7 +38,7 @@ loop_through( 'alert-overdue.txt', 0, 6, ['confirmed', 'planned'] ); sub loop_through { my ( $template, $include_parent, $days, $states ) = @_; - my $dtf = FixMyStreet::DB->storage->datetime_parser; + my $dtf = FixMyStreet::DB->schema->storage->datetime_parser; my $date_threshold = $dtf->format_datetime(FixMyStreet::Cobrand::Zurich::sub_days( $now, $days )); my $reports = FixMyStreet::DB->resultset("Problem")->search( { @@ -78,7 +78,7 @@ sub send_alert { } FixMyStreet::Email::send_cron( - FixMyStreet::DB->storage->schema, + FixMyStreet::DB->schema, $template, $h, { diff --git a/db/rerun_dbic_loader.pl b/db/rerun_dbic_loader.pl index 958b28241..cf6e89ab2 100755 --- a/db/rerun_dbic_loader.pl +++ b/db/rerun_dbic_loader.pl @@ -3,6 +3,13 @@ use strict; use warnings; +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + # This script inspects the current state of the database and then amends the # FixMyStreet::DB::Result::* files to suit. After running the changes should be # inspected before the code is commited. @@ -20,13 +27,15 @@ my @tables_to_ignore = ( my $exclude = '^(?:' . join( '|', @tables_to_ignore ) . ')$'; make_schema_at( - 'FixMyStreet::DB', + 'FixMyStreet::DB::Schema', { debug => 0, # switch on to be chatty dump_directory => './perllib', # edit files in place exclude => qr{$exclude}, # ignore some tables generate_pod => 0, # no need for pod overwrite_modifications => 1, # don't worry that the md5 is wrong + result_namespace => '+FixMyStreet::DB::Result', + resultset_namespace => '+FixMyStreet::DB::ResultSet', # add in some extra components components => [ 'FilterColumn', 'InflateColumn::DateTime', 'EncodedColumn' ], diff --git a/perllib/FixMyStreet/App/Model/DB.pm b/perllib/FixMyStreet/App/Model/DB.pm index ac1f98dc9..9d09186b8 100644 --- a/perllib/FixMyStreet/App/Model/DB.pm +++ b/perllib/FixMyStreet/App/Model/DB.pm @@ -7,8 +7,8 @@ use warnings; use FixMyStreet; __PACKAGE__->config( - schema_class => 'FixMyStreet::DB', - connect_info => sub { FixMyStreet::DB->storage->dbh }, + schema_class => 'FixMyStreet::DB::Schema', + connect_info => sub { FixMyStreet::DB->schema->storage->dbh }, ); =head1 NAME diff --git a/perllib/FixMyStreet/DB.pm b/perllib/FixMyStreet/DB.pm index d920c809f..cee66b434 100644 --- a/perllib/FixMyStreet/DB.pm +++ b/perllib/FixMyStreet/DB.pm @@ -1,22 +1,13 @@ -use utf8; package FixMyStreet::DB; -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - use strict; use warnings; +use FixMyStreet::DB::Schema; -use base 'DBIx::Class::Schema'; - -__PACKAGE__->load_namespaces; - - -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CjFpUvon7KggFM7OF7VK/w +my $schema; -use FixMyStreet; +sub schema { $schema ||= FixMyStreet::DB::Schema->clone } -__PACKAGE__->connection(FixMyStreet->dbic_connect_info); +sub resultset { shift->schema->resultset(@_) } 1; diff --git a/perllib/FixMyStreet/DB/Schema.pm b/perllib/FixMyStreet/DB/Schema.pm new file mode 100644 index 000000000..7833ee68c --- /dev/null +++ b/perllib/FixMyStreet/DB/Schema.pm @@ -0,0 +1,25 @@ +use utf8; +package FixMyStreet::DB::Schema; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Schema'; + +__PACKAGE__->load_namespaces( + result_namespace => "+FixMyStreet::DB::Result", + resultset_namespace => "+FixMyStreet::DB::ResultSet", +); + + +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-07-13 14:15:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UpH30RXb6SbCqRv2FPmpkg + +use FixMyStreet; + +__PACKAGE__->connection(FixMyStreet->dbic_connect_info); + +1; diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index ef1bdb08b..aefe13318 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -62,7 +62,7 @@ sub send() { $query =~ s/\?/alert.parameter/ if ($query =~ /\?/); $query =~ s/\?/alert.parameter2/ if ($query =~ /\?/); - $query = FixMyStreet::DB->storage->dbh->prepare($query); + $query = FixMyStreet::DB->schema->storage->dbh->prepare($query); $query->execute(); my $last_alert_id; my %data = ( template => $alert_type->template, data => [], schema => $schema ); @@ -225,7 +225,7 @@ sub send() { and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? order by confirmed desc"; - $q = FixMyStreet::DB->storage->dbh->prepare($q); + $q = FixMyStreet::DB->schema->storage->dbh->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); while (my $row = $q->fetchrow_hashref) { $schema->resultset('AlertSent')->create( { diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm index 51cb7b856..1bd069ee8 100755 --- a/perllib/FixMyStreet/Script/UpdateAllReports.pm +++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm @@ -158,7 +158,7 @@ sub generate_dashboard { ); $data{last_seven_days} = \%last_seven_days; - my $dtf = FixMyStreet::DB->storage->datetime_parser; + my $dtf = FixMyStreet::DB->schema->storage->datetime_parser; my $eight_ago = $dtf->format_datetime(DateTime->now->subtract(days => 8)); %problems_reported_by_period = stuff_by_day_or_year('day', 'Problem', diff --git a/perllib/FixMyStreet/Test.pm b/perllib/FixMyStreet/Test.pm index add67dfd9..6b6bc02bc 100644 --- a/perllib/FixMyStreet/Test.pm +++ b/perllib/FixMyStreet/Test.pm @@ -8,7 +8,7 @@ use utf8; use Test::More; use FixMyStreet::DB; -my $db = FixMyStreet::DB->storage; +my $db = FixMyStreet::DB->schema->storage; sub import { strict->import; diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 30db24164..6ba53b7af 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -11,7 +11,7 @@ has start_date => ( is => 'ro', default => sub { undef } ); has end_date => ( is => 'ro', default => sub { undef } ); has suppress_alerts => ( is => 'rw', default => 0 ); has verbose => ( is => 'ro', default => 0 ); -has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->connect } ); +has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } ); Readonly::Scalar my $AREA_ID_BROMLEY => 2482; Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237; diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 540425bf1..764207626 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -6,7 +6,7 @@ use Open311; has bodies => ( is => 'ro' ); has found_contacts => ( is => 'rw', default => sub { [] } ); has verbose => ( is => 'ro', default => 0 ); -has schema => ( is => 'ro', lazy => 1, default => sub { FixMyStreet::DB->connect } ); +has schema => ( is => 'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } ); has _current_body => ( is => 'rw' ); has _current_open311 => ( is => 'rw' ); diff --git a/t/app/model/extra.t b/t/app/model/extra.t index 4e2a8ed37..17f34c6c1 100644 --- a/t/app/model/extra.t +++ b/t/app/model/extra.t @@ -2,7 +2,7 @@ use FixMyStreet::Test; use DateTime; -my $db = FixMyStreet::DB->storage->schema; +my $db = FixMyStreet::DB->schema; my $body = $db->resultset('Body')->create({ name => 'ExtraTestingBody' }); diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index 3651a188a..4aa5c8992 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -10,7 +10,7 @@ my $dt = DateTime->now; my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); -my $db = FixMyStreet::DB->storage->schema; +my $db = FixMyStreet::DB->schema; my $user = $db->resultset('User')->find_or_create({ name => 'Bob', email => 'bob@example.com', diff --git a/t/app/sendreport/open311.t b/t/app/sendreport/open311.t index 8f933065c..32564dbd8 100644 --- a/t/app/sendreport/open311.t +++ b/t/app/sendreport/open311.t @@ -157,7 +157,7 @@ sub test_overrides { FixMyStreet::override_config { ALLOWED_COBRANDS => ['fixmystreet', 'oxfordshire', 'bromley', 'westberkshire', 'greenwich'], }, sub { - my $db = FixMyStreet::DB->storage->schema; + my $db = FixMyStreet::DB->schema; #$db->txn_begin; my $params = { id => $input->{body_id}, name => $input->{body_name} }; |