summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Util.pm
diff options
context:
space:
mode:
authorTiago Mello <timello@gmail.com>2011-02-11 02:31:28 +0100
committerTiago Mello <timello@gmail.com>2011-02-11 02:31:28 +0100
commitf0b6242097e487198de559d39d4169a2a0a4d8e7 (patch)
tree8e6dce90308e188c2d3656859fa319b2b8544221 /Bugzilla/Util.pm
parenta744c531a46bdd18aed3cc89ed0770a791d27475 (diff)
downloadbugzilla-f0b6242097e487198de559d39d4169a2a0a4d8e7.tar.gz
bugzilla-f0b6242097e487198de559d39d4169a2a0a4d8e7.tar.xz
Bug 620827: Refactor remove see also to use remove_from_db instead.
r/a=mkanat
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r--Bugzilla/Util.pm26
1 files changed, 19 insertions, 7 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index f9e8d12f7..058a49af3 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -55,7 +55,7 @@ use Digest;
use Email::Address;
use List::Util qw(first);
use Math::Random::Secure qw(irand);
-use Scalar::Util qw(tainted);
+use Scalar::Util qw(tainted blessed);
use Template::Filters;
use Text::Wrap;
@@ -307,25 +307,37 @@ sub use_attachbase {
}
sub diff_arrays {
- my ($old_ref, $new_ref) = @_;
+ my ($old_ref, $new_ref, $attrib) = @_;
my @old = @$old_ref;
my @new = @$new_ref;
+ $attrib ||= 'name';
# For each pair of (old, new) entries:
+ # If object arrays were passed then an attribute should be defined;
# If they're equal, set them to empty. When done, @old contains entries
# that were removed; @new contains ones that got added.
foreach my $oldv (@old) {
foreach my $newv (@new) {
- next if ($newv eq '');
- if ($oldv eq $newv) {
- $newv = $oldv = '';
+ next if ($newv eq '' or $oldv eq '');
+ if (blessed($oldv) and blessed($newv)) {
+ if ($oldv->$attrib eq $newv->$attrib) {
+ $newv = $oldv = '';
+ }
+ }
+ else {
+ if ($oldv eq $newv) {
+ $newv = $oldv = ''
+ }
}
}
}
- my @removed = grep { $_ ne '' } @old;
- my @added = grep { $_ ne '' } @new;
+ my @removed;
+ my @added;
+ @removed = grep { $_ ne '' } @old;
+ @added = grep { $_ ne '' } @new;
+
return (\@removed, \@added);
}