[Rt-commit] rt branch, 5.0/articles-unique-only-within-own-class, updated. rt-5.0.1-2-gdda7e71209

Steve Burr steve at bestpractical.com
Tue May 18 09:54:49 EDT 2021


The branch, 5.0/articles-unique-only-within-own-class has been updated
       via  dda7e71209bb4ecef2fb1f8293686b3411ad06dd (commit)
      from  5dcbf9879d2c8aa27d62fee3133f5ea609479220 (commit)

Summary of changes:
 lib/RT/Article.pm | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

- Log -----------------------------------------------------------------
commit dda7e71209bb4ecef2fb1f8293686b3411ad06dd
Author: Steven Burr <steve at bestpractical.com>
Date:   Tue May 18 09:54:10 2021 -0400

    Refactor class argument to ValidateName

diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index 4b90bd0284..636d6ce227 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -110,12 +110,13 @@ sub Create {
         return ( 0, $self->loc('Invalid Class') );
     }
 
-    $self->{->'_creating_class'} = $class->id;
-
     unless ( $class->CurrentUserHasRight('CreateArticle') ) {
         return ( 0, $self->loc("Permission Denied") );
     }
 
+    # only here for ValidateName, on create, being called in the context of DBIx::SB
+    $self->{'_creating_class'} = $class->id;
+
     return ( undef, $self->loc('Name in use') )
       unless $self->ValidateName( $args{'Name'}, $class->id );
 
@@ -244,16 +245,16 @@ Empty names are permitted.
 sub ValidateName {
     my $self = shift;
     my $name = shift;
-    my $class = shift || ($self->ClassObj && $self->ClassObj->id) || $self->{'_creating_class'};
+    my $class_id = shift || ($self->ClassObj && $self->ClassObj->id) || $self->{'_creating_class'};
 
     if ( !$name ) {
         return (1);
     }
 
-    if ( $class ) {
+    if ( $class_id ) {
         my $articles = RT::Articles->new($RT::SystemUser);
         $articles->Limit( FIELD => 'Name', OPERATOR => '=', VALUE => $name );  # cannot use LimitName() as it hardcodes 'LIKE'
-        $articles->Limit( FIELD => 'Class', OPERATOR => '=', VALUE => $class );
+        $articles->Limit( FIELD => 'Class', OPERATOR => '=', VALUE => $class_id );
         while ( my $article = $articles->Next ) {
             if ( $article->id && ( !$self->id || ($article->id))) {
                 return (undef);

-----------------------------------------------------------------------


More information about the rt-commit mailing list