Skip to content

Commit 9527e20

Browse files
authored
MBS-11405: Don't show ended URL rels in DeprecatedRelationship reports (metabrainz#1933)
This generalizes MBS-11336 to not only hide ended URL rels in DeprecatedRelationshipURLs, but also on all other DeprecatedRelationship reports. URL rels set as 'ended' are just kept for historical reasons, so we do not want people to remove them or change them.
1 parent 1c9dfef commit 9527e20

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/MusicBrainz/Server/Report/DeprecatedRelationshipReport.pm

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,32 @@ sub query {
1010
my ($self) = @_;
1111
my $entity_type = $self->entity_type;
1212
my $name_sort = $entity_type ne 'url' ? 'entity.name COLLATE musicbrainz' : 'entity.url';
13-
my $extra_conditions = $entity_type eq 'url' ? ' AND link.ended IS FALSE' : '';
1413
my @tables = $self->c->model('Relationship')->generate_table_list($entity_type);
14+
my @url_table_names = map { $_->[0] } $self->c->model('Relationship')->generate_table_list('url');
1515
my $query = "SELECT l.name AS link_name, l.gid AS link_gid, entity.id AS ${entity_type}_id, row_number() OVER (ORDER BY l.name, $name_sort)" .
1616
"FROM $entity_type AS entity JOIN (";
1717
my $first = 1;
1818
foreach my $t (@tables) {
1919
my ($table, $type_column) = @$t;
20+
2021
if ($first) {
2122
$first = 0;
2223
} else {
2324
$query .= " UNION ";
2425
}
26+
2527
$query .= "SELECT link_type.name AS name, link_type.gid AS gid, $type_column AS entity
2628
FROM link_type
2729
JOIN link ON link.link_type = link_type.id
2830
JOIN $table l_table ON l_table.link = link.id
29-
WHERE (link_type.is_deprecated OR link_type.description = '')
30-
$extra_conditions";
31+
WHERE (link_type.is_deprecated OR link_type.description = '')";
32+
33+
# For URL relationships, ignore ended ones (that means the link is no longer
34+
# valid, yet being kept for history)
35+
if (grep(/^$table/, @url_table_names)) {
36+
$query .= ' AND link.ended IS FALSE';
37+
}
38+
3139
}
3240
$query .= ") l ON l.entity = entity.id";
3341
return $query;

0 commit comments

Comments
 (0)