aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Model/PhotoSet.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-11-27 21:38:28 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-12-16 16:58:33 +0000
commit749fe96b5b987bec29fb608acfcbdb81e57aaebf (patch)
tree80164c1305c26698c13286dd3de506198a240673 /perllib/FixMyStreet/App/Model/PhotoSet.pm
parentd28745730bf22b9447645fd6543b4a164976f761 (diff)
Remove risk of infinite loop in PhotoSet.
Use a separate attribute for data direct from a database row when creating a PhotoSet, so that data will always contain one or more photo IDs.
Diffstat (limited to 'perllib/FixMyStreet/App/Model/PhotoSet.pm')
-rw-r--r--perllib/FixMyStreet/App/Model/PhotoSet.pm20
1 files changed, 12 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm
index f1334ff38..e8396b5aa 100644
--- a/perllib/FixMyStreet/App/Model/PhotoSet.pm
+++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm
@@ -14,25 +14,30 @@ has c => (
is => 'ro',
);
+# The attached report, for using its ID
has object => (
is => 'ro',
);
-has data => ( # generic data from DB field
+# If a PhotoSet is generated from a database row, db_data is set, which then
+# fills data_items -> images -> data. If it is generated during creation,
+# data_items is set, which then similarly fills images -> data.
+
+has db_data => ( # generic data from DB field
+ is => 'ro',
+);
+
+has data => ( # List of photo hashes
is => 'ro',
lazy => 1,
default => sub {
- # yes, this is a little circular: data -> data_items -> items -> data
- # e.g. if not provided, then we're presumably uploading/etc., so calculate from
- # the stored cached fileids
- # (obviously if you provide none of these, then you'll get an infinite loop)
my $self = shift;
my $data = join ',', map { $_->[0] } $self->all_images;
return $data;
}
);
-has data_items => ( # either a) split from data or b) provided by photo upload
+has data_items => ( # either a) split from db_data or b) provided by photo upload
isa => 'ArrayRef',
is => 'rw',
traits => ['Array'],
@@ -42,8 +47,7 @@ has data_items => ( # either a) split from data or b) provided by photo upload
},
default => sub {
my $self = shift;
- my $data = $self->data
- or return [];
+ my $data = $self->db_data or return [];
return [$data] if (_jpeg_magic($data));