aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/AdminLog.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm10
-rw-r--r--perllib/FixMyStreet/DB/Result/ResponseTemplate.pm5
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm46
-rw-r--r--perllib/FixMyStreet/DB/Result/UserPlannedReport.pm55
5 files changed, 111 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm
index d60915cfc..1c9bd3a63 100644
--- a/perllib/FixMyStreet/DB/Result/AdminLog.pm
+++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm
@@ -38,7 +38,7 @@ __PACKAGE__->add_columns(
"reason",
{ data_type => "text", default_value => "", is_nullable => 0 },
"time_spent",
- { data_type => "integer", default_value => "0", is_nullable => 0 },
+ { data_type => "integer", default_value => 0, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
@@ -54,7 +54,7 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RCi1FEwb9T2MZ2X+QOTTUA
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y2xZ4BDv7H+f4vbIZyNflw
1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 010b7755b..308fba71f 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -132,10 +132,16 @@ __PACKAGE__->belongs_to(
{ id => "user_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
+__PACKAGE__->has_many(
+ "user_planned_reports",
+ "FixMyStreet::DB::Result::UserPlannedReport",
+ { "foreign.report_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Go+T9oFRfwQ1Ag89qPpF/g
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PMOhd1uloLTAYovW/fxgSg
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
index 48a1ab3ae..d189bf3ec 100644
--- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
@@ -29,6 +29,7 @@ __PACKAGE__->add_columns(
data_type => "timestamp",
default_value => \"current_timestamp",
is_nullable => 0,
+ original => { default_value => \"now()" },
},
);
__PACKAGE__->set_primary_key("id");
@@ -41,8 +42,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-02-19 16:13:43
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xzhmxtu0taAnBMZN0HBocw
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ECFQLMxOFGwv7cwfHLlszw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 7d1785c4b..cc8e050da 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -90,10 +90,21 @@ __PACKAGE__->has_many(
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->has_many(
+ "user_planned_reports",
+ "FixMyStreet::DB::Result::UserPlannedReport",
+ { "foreign.user_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-11 12:49:31
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SG86iN6Fr4/JIq7U2zYkug
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+pEOZ8GM14D4gqkp+fr+ZA
+
+use Moo;
+use mySociety::EmailUtil;
+
+__PACKAGE__->many_to_many( planned_reports => 'user_planned_reports', 'report' );
__PACKAGE__->add_columns(
"password" => {
@@ -104,8 +115,6 @@ __PACKAGE__->add_columns(
},
);
-use mySociety::EmailUtil;
-
sub latest_anonymity {
my $self = shift;
my $p = $self->problems->search(undef, { order_by => { -desc => 'id' } } )->first;
@@ -277,4 +286,33 @@ sub adopt {
$other->delete;
}
+# Planned reports
+
+# Override the default auto-created function as we only want one live entry per user
+around add_to_planned_reports => sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my ( $report_col ) = @_;
+ my $existing = $self->user_planned_reports->search_rs({ report_id => $report_col->{id}, removed => undef })->first;
+ return $existing if $existing;
+ return $self->$orig(@_);
+};
+
+# Override the default auto-created function as we don't want to ever delete anything
+around remove_from_planned_reports => sub {
+ my ($orig, $self, $report) = @_;
+ $self->user_planned_reports
+ ->search_rs({ report_id => $report->id, removed => undef })
+ ->update({ removed => \'current_timestamp' });
+};
+
+sub active_planned_reports {
+ my $self = shift;
+ $self->planned_reports->search({ removed => undef });
+}
+
+sub is_planned_report {
+ my ($self, $problem) = @_;
+ return $self->active_planned_reports->find({ id => $problem->id });
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm b/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm
new file mode 100644
index 000000000..1e893c7a9
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm
@@ -0,0 +1,55 @@
+use utf8;
+package FixMyStreet::DB::Result::UserPlannedReport;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
+__PACKAGE__->table("user_planned_reports");
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_auto_increment => 1,
+ is_nullable => 0,
+ sequence => "user_planned_reports_id_seq",
+ },
+ "user_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "report_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "added",
+ {
+ data_type => "timestamp",
+ default_value => \"current_timestamp",
+ is_nullable => 0,
+ original => { default_value => \"now()" },
+ },
+ "removed",
+ { data_type => "timestamp", is_nullable => 1 },
+);
+__PACKAGE__->set_primary_key("id");
+__PACKAGE__->belongs_to(
+ "report",
+ "FixMyStreet::DB::Result::Problem",
+ { id => "report_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+__PACKAGE__->belongs_to(
+ "user",
+ "FixMyStreet::DB::Result::User",
+ { id => "user_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:03:08
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mv7koDhvZSBW/4aQivtpAQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;