Skip to content

Commit

Permalink
[#1921] on import, suppress tag creation errors and bogus tag creation
Browse files Browse the repository at this point in the history
This skips warnings for tags in @unauthorized_add when importing,
similar to what was already being done for deletion errors in
the next line.

It also addresses Azz's concern about importing bogus tags, by
not creating tags on entry import that weren't already added by
the import of all current tags, which is forced to happen first.
  • Loading branch information
kareila committed Apr 9, 2017
1 parent fd3c694 commit c676cde
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions cgi-bin/LJ/Tags.pm
Expand Up @@ -772,20 +772,26 @@ sub update_logtags {
$opts->{"${verb}_ids"} ||= [];
foreach my $kw (@{$opts->{$verb} || []}) {
my $kwid = $u->get_keyword_id( $kw, $can_control );
if ($can_control) {
# error if we failed to create
return undef unless $kwid;
} else {
# if we're not creating, who cares, just skip; also skip if the keyword
# is not really a tag (don't promote it)
unless ( $kwid && $utags->{$kwid} ) {

# error if we should have been able to create a kwid and didn't
return undef if $can_control && ! $kwid;

# skip if the tag isn't used in the journal and either
# (a) we can't add it or (b) we are using force:
# we only use force if we are clearing all tags or importing, so
# we will have already added all the canonical tags in the journal,
# and any additional tags would be bogus
unless ( $kwid && $utags->{$kwid} ) {
if ( ! $can_control || $opts->{force} ) {
push @unauthorized_add, $kw;
next;
} else {
# we need to create this tag later
push @to_create, $kw;
}
}

# add the ids to the list, and save to create later if needed
push @to_create, $kw unless $utags->{$kwid};
# add the id to the list
push @{$opts->{"${verb}_ids"}}, $kwid;
}
}
Expand Down Expand Up @@ -819,8 +825,10 @@ sub update_logtags {
delete $add{$_} foreach keys %{$tags};

my @add_delete_errors;
push @add_delete_errors, LJ::Lang::ml( "taglib.error.add", { tags => join( ", ", @unauthorized_add ) } ) if @unauthorized_add;
push @add_delete_errors, LJ::Lang::ml( "taglib.error.delete2", { tags => join( ", ", map { $utags->{$_}->{name} } keys %{$tags} ) } ) if %delete && ! $can_control && ! $opts->{force};
push @add_delete_errors, LJ::Lang::ml( "taglib.error.add", { tags => join( ", ", @unauthorized_add ) } )
if @unauthorized_add && ! $opts->{force};
push @add_delete_errors, LJ::Lang::ml( "taglib.error.delete2", { tags => join( ", ", map { $utags->{$_}->{name} } keys %{$tags} ) } )
if %delete && ! $can_control && ! $opts->{force};
return $err->( join "\n\n", @add_delete_errors ) if @add_delete_errors;

# bail out if nothing needs to be done
Expand Down

0 comments on commit c676cde

Please sign in to comment.