summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Object.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-07-31 07:20:07 +0200
committerByron Jones <bjones@mozilla.com>2013-07-31 07:20:07 +0200
commite9f07c7e2bc8dcf66381ed588ddd955d77b7d26f (patch)
tree42e9dde86748c22486f0df5c05bf16a10fdd6797 /Bugzilla/Object.pm
parent5d5597bbd642ad00f2637abbc93714b86a359641 (diff)
downloadbugzilla-e9f07c7e2bc8dcf66381ed588ddd955d77b7d26f.tar.gz
bugzilla-e9f07c7e2bc8dcf66381ed588ddd955d77b7d26f.tar.xz
Bug 877078: shift bugmail generation to the jobqueue
r=sgreen, a=sgreen
Diffstat (limited to 'Bugzilla/Object.pm')
-rw-r--r--Bugzilla/Object.pm50
1 files changed, 48 insertions, 2 deletions
diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm
index 0cecb8eca..9f305e929 100644
--- a/Bugzilla/Object.pm
+++ b/Bugzilla/Object.pm
@@ -113,7 +113,10 @@ sub _init {
"SELECT $columns FROM $table WHERE $condition", undef, @values);
}
- $class->_cache_set($param, $object) if $object;
+ if ($object) {
+ $class->_serialisation_keys($object);
+ $class->_cache_set($param, $object);
+ }
return $object;
}
@@ -144,6 +147,15 @@ sub cache_key {
}
}
+# To support serialisation, we need to capture the keys in an object's default
+# hashref.
+sub _serialisation_keys {
+ my ($class, $object) = @_;
+ my $cache = Bugzilla->request_cache->{serialisation_keys} ||= {};
+ $cache->{$class} = [ keys %$object ] if $object;
+ return @{ $cache->{$class} };
+}
+
sub check {
my ($invocant, $param) = @_;
my $class = ref($invocant) || $invocant;
@@ -199,6 +211,14 @@ sub new_from_list {
return match($invocant, { $id_field => \@detainted_ids });
}
+sub new_from_hash {
+ my $invocant = shift;
+ my $class = ref($invocant) || $invocant;
+ my $object = shift;
+ bless($object, $class);
+ return $object;
+}
+
# Note: Future extensions to this could be:
# * Add a MATCH_JOIN constant so that we can join against
# certain other tables for the WHERE criteria.
@@ -297,7 +317,8 @@ sub _do_list_select {
my @untainted = @{ $values || [] };
trick_taint($_) foreach @untainted;
my $objects = $dbh->selectall_arrayref($sql, {Slice=>{}}, @untainted);
- bless ($_, $class) foreach @$objects;
+ $class->_serialisation_keys($objects->[0]) if @$objects;
+ bless($_, $class) foreach @$objects;
return $objects
}
@@ -474,6 +495,13 @@ sub audit_log {
}
}
+sub flatten_to_hash {
+ my $self = shift;
+ my $class = blessed($self);
+ my %hash = map { $_ => $self->{$_} } $class->_serialisation_keys;
+ return \%hash;
+}
+
###############################
#### Subroutines ######
###############################
@@ -1040,6 +1068,13 @@ template.
Returns: A reference to an array of objects.
+=item C<new_from_hash($hashref)>
+
+ Description: Create an object from the given hash.
+
+ Params: $hashref - A reference to a hash which was created by
+ flatten_to_hash.
+
=item C<match>
=over
@@ -1277,6 +1312,17 @@ that should be passed to the C<set_> function that is called.
=back
+=head2 Simple Methods
+
+=over
+
+=item C<flatten_to_hash>
+
+Returns a hashref suitable for serialisation and re-inflation with C<new_from_hash>.
+
+=back
+
+
=head2 Simple Validators
You can use these in your subclass L</VALIDATORS> or L</UPDATE_VALIDATORS>.