[Rt-commit] rt branch, 4.2/fix-organization-for-all-links, created. rt-4.2.3-9-g83341f3

Jim Brandt jbrandt at bestpractical.com
Tue Feb 25 16:45:20 EST 2014


The branch, 4.2/fix-organization-for-all-links has been created
        at  83341f3662421d4f3058aff7556f3ea69268050a (commit)

- Log -----------------------------------------------------------------
commit 068cf0c39e15b2b82449b50da66d6a7f4f7ec799
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Feb 25 15:23:04 2014 -0500

    Validate article and other types of links
    
    Check non-ticket links for a changed Organization and
    for links to missing objects like Articles. Use %INC
    to find loaded RT::URI subclasses to catch link types that
    might be loaded from an extension like Assets.
    
    Add Article to the models checked since Articles are part of
    RT now.

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
old mode 100644
new mode 100755
index db89dce..33a8ef3
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -115,6 +115,7 @@ my %TYPE = (
 
 my @models = qw(
     ACE
+    Article
     Attachment
     Attribute
     CachedGroupMember
@@ -930,7 +931,10 @@ push @CHECKS, 'Links: wrong organization' => sub {
         { model => 'Link', column => 'Base' },
     );
 
-    my $rt_uri = RT::URI::fsck_com_rt->new( $RT::SystemUser );
+    my @rt_uris = rt_uri_modules();
+    foreach my $package (@rt_uris) {
+
+    my $rt_uri = $package->new( $RT::SystemUser );
     my $scheme = $rt_uri->Scheme;
     my $prefix = $rt_uri->LocalURIPrefix;
 
@@ -972,6 +976,7 @@ push @CHECKS, 'Links: wrong organization' => sub {
             last; # plenty of chances we covered all cases with one update
         }
     }
+    } # end foreach my $package (@rt_uris)
     return $res;
 };
 
@@ -1055,7 +1060,10 @@ push @CHECKS, 'Links: missing object' => sub {
         { model => 'Link', column => 'Base' },
     );
 
-    my $rt_uri = RT::URI::fsck_com_rt->new( $RT::SystemUser );
+    my @rt_uris = rt_uri_modules();
+    foreach my $package (@rt_uris) {
+
+    my $rt_uri = $package->new( $RT::SystemUser );
     my $scheme = $rt_uri->Scheme;
     my $prefix = $rt_uri->LocalURIPrefix;
 
@@ -1096,6 +1104,7 @@ push @CHECKS, 'Links: missing object' => sub {
             }
         }
     }
+    } # end foreach my $package (@rt_uris)
     return $res;
 };
 
@@ -1375,6 +1384,20 @@ sub prompt_integer {
     return $cached_answer{ $token } = $a;
 } }
 
+# Find all RT::URI modules RT has loaded
+
+sub rt_uri_modules {
+    my @uris = grep /^RT\/URI\/.+\.pm$/, keys %INC;
+    my @uri_modules;
+    foreach my $uri_path (@uris){
+        next if $uri_path =~ /base\.pm$/; # Skip base RT::URI object
+        $uri_path = substr $uri_path, 0, -3; # chop off .pm
+        push @uri_modules, join '::', split '/', $uri_path;
+    }
+
+    return @uri_modules;
+}
+
 1;
 
 __END__

commit 83341f3662421d4f3058aff7556f3ea69268050a
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Feb 25 16:44:11 2014 -0500

    Add indent for new foreach loops

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index 33a8ef3..c4b2d3c 100755
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -934,48 +934,48 @@ push @CHECKS, 'Links: wrong organization' => sub {
     my @rt_uris = rt_uri_modules();
     foreach my $package (@rt_uris) {
 
-    my $rt_uri = $package->new( $RT::SystemUser );
-    my $scheme = $rt_uri->Scheme;
-    my $prefix = $rt_uri->LocalURIPrefix;
-
-    foreach my $use ( @URI_USES ) {
-        my $table = m2t( $use->{'model'} );
-        my $column = $use->{'column'};
-
-        my $query = "SELECT id, $column FROM $table WHERE"
-            . " $column LIKE ? AND $column NOT LIKE ?";
-        my @binds = ($scheme ."://%", $prefix ."%");
+        my $rt_uri = $package->new( $RT::SystemUser );
+        my $scheme = $rt_uri->Scheme;
+        my $prefix = $rt_uri->LocalURIPrefix;
 
-        while ( my ($k, $v) = each %{ $use->{'Additional'} || {} } ) {
-            $query .= " AND $k = ?";
-            push @binds, $v;
-        }
-        my $sth = execute_query( $query, @binds );
-        while ( my ($id, $value) = $sth->fetchrow_array ) {
-            $res = 0;
-            print STDERR "Record #$id in $table. Value of $column column most probably is an incorrect link\n";
-            my ($wrong_org) = ( $value =~ m{^\Q$scheme\E://(.+)/[^/]+/[0-9]*$} );
-            next unless my $replace_with = prompt(
-                'Replace',
-                "Column $column in $table is a link. Local links has scheme '$scheme'"
-                ." followed by organization name from the config file. There is record"
-                ." #$id that has scheme '$scheme', but organization is '$wrong_org'."
-                ." Most probably you changed organization, but didn't update links."
-                ." It's ok to replace these wrong links.\n",
-                "Links: wrong organization $wrong_org"
-            );
+        foreach my $use ( @URI_USES ) {
+            my $table = m2t( $use->{'model'} );
+            my $column = $use->{'column'};
 
-            print "Updating record(s) in $table\n" if $opt{'verbose'};
-            my $wrong_prefix = $scheme . '://'. $wrong_org;
-            my $query = "UPDATE $table SET $column = ". sql_concat('?', "SUBSTR($column, ?)")
-                ." WHERE $column LIKE ?";
-            execute_query( $query, $prefix, length($wrong_prefix)+1, $wrong_prefix .'/%' );
+            my $query = "SELECT id, $column FROM $table WHERE"
+              . " $column LIKE ? AND $column NOT LIKE ?";
+            my @binds = ($scheme ."://%", $prefix ."%");
 
-            $redo_check{'Links: wrong organization'} = 1;
-            $redo_check{'Links: LocalX for non-ticket'} = 1;
-            last; # plenty of chances we covered all cases with one update
+            while ( my ($k, $v) = each %{ $use->{'Additional'} || {} } ) {
+                $query .= " AND $k = ?";
+                push @binds, $v;
+            }
+            my $sth = execute_query( $query, @binds );
+            while ( my ($id, $value) = $sth->fetchrow_array ) {
+                $res = 0;
+                print STDERR "Record #$id in $table. Value of $column column most probably is an incorrect link\n";
+                my ($wrong_org) = ( $value =~ m{^\Q$scheme\E://(.+)/[^/]+/[0-9]*$} );
+                next unless my $replace_with = prompt(
+                    'Replace',
+                    "Column $column in $table is a link. Local links has scheme '$scheme'"
+                    ." followed by organization name from the config file. There is record"
+                    ." #$id that has scheme '$scheme', but organization is '$wrong_org'."
+                    ." Most probably you changed organization, but didn't update links."
+                    ." It's ok to replace these wrong links.\n",
+                    "Links: wrong organization $wrong_org"
+                                                     );
+
+                print "Updating record(s) in $table\n" if $opt{'verbose'};
+                my $wrong_prefix = $scheme . '://'. $wrong_org;
+                my $query = "UPDATE $table SET $column = ". sql_concat('?', "SUBSTR($column, ?)")
+                  ." WHERE $column LIKE ?";
+                execute_query( $query, $prefix, length($wrong_prefix)+1, $wrong_prefix .'/%' );
+
+                $redo_check{'Links: wrong organization'} = 1;
+                $redo_check{'Links: LocalX for non-ticket'} = 1;
+                last; # plenty of chances we covered all cases with one update
+            }
         }
-    }
     } # end foreach my $package (@rt_uris)
     return $res;
 };
@@ -1063,47 +1063,47 @@ push @CHECKS, 'Links: missing object' => sub {
     my @rt_uris = rt_uri_modules();
     foreach my $package (@rt_uris) {
 
-    my $rt_uri = $package->new( $RT::SystemUser );
-    my $scheme = $rt_uri->Scheme;
-    my $prefix = $rt_uri->LocalURIPrefix;
+        my $rt_uri = $package->new( $RT::SystemUser );
+        my $scheme = $rt_uri->Scheme;
+        my $prefix = $rt_uri->LocalURIPrefix;
 
-    foreach my $use ( @URI_USES ) {
-        my $stable = m2t( $use->{'model'} );
-        my $scolumn = $use->{'column'};
+        foreach my $use ( @URI_USES ) {
+            my $stable = m2t( $use->{'model'} );
+            my $scolumn = $use->{'column'};
 
-        foreach my $tmodel ( @models ) {
-            my $tclass = 'RT::'. $tmodel;
-            my $ttable = m2t($tmodel);
+            foreach my $tmodel ( @models ) {
+                my $tclass = 'RT::'. $tmodel;
+                my $ttable = m2t($tmodel);
 
-            my $tprefix = $prefix .'/'. ($tclass eq 'RT::Ticket'? 'ticket' : $tclass) .'/';
+                my $tprefix = $prefix .'/'. ($tclass eq 'RT::Ticket'? 'ticket' : $tclass) .'/';
 
-            my $query = "SELECT s.id FROM $stable s LEFT JOIN $ttable t "
-                ." ON t.id = ". sql_str2int("SUBSTR(s.$scolumn, ?)")
-                ." WHERE s.$scolumn LIKE ? AND t.id IS NULL";
-            my @binds = (length($tprefix) + 1, $tprefix.'%');
+                my $query = "SELECT s.id FROM $stable s LEFT JOIN $ttable t "
+                  ." ON t.id = ". sql_str2int("SUBSTR(s.$scolumn, ?)")
+                    ." WHERE s.$scolumn LIKE ? AND t.id IS NULL";
+                my @binds = (length($tprefix) + 1, $tprefix.'%');
 
-            while ( my ($k, $v) = each %{ $use->{'Additional'} || {} } ) {
-                $query .= " AND s.$k = ?";
-                push @binds, $v;
-            }
-
-            my $sth = execute_query( $query, @binds );
-            while ( my ($sid) = $sth->fetchrow_array ) {
-                $res = 0;
-                print STDERR "Link in $scolumn column in record #$sid in $stable table points"
-                    ." to not existing object.\n";
-                next unless prompt(
-                    'Delete',
-                    "Column $scolumn in $stable table is a link to an object that doesn't exist."
-                    ." You can delete such records, however make sure there is no other"
-                    ." errors with links.\n",
-                    'Link to a missing object in $ttable'
-                );
+                while ( my ($k, $v) = each %{ $use->{'Additional'} || {} } ) {
+                    $query .= " AND s.$k = ?";
+                    push @binds, $v;
+                }
 
-                delete_record($stable, $sid);
+                my $sth = execute_query( $query, @binds );
+                while ( my ($sid) = $sth->fetchrow_array ) {
+                    $res = 0;
+                    print STDERR "Link in $scolumn column in record #$sid in $stable table points"
+                      ." to not existing object.\n";
+                    next unless prompt(
+                        'Delete',
+                        "Column $scolumn in $stable table is a link to an object that doesn't exist."
+                        ." You can delete such records, however make sure there is no other"
+                        ." errors with links.\n",
+                        'Link to a missing object in $ttable'
+                                      );
+
+                    delete_record($stable, $sid);
+                }
             }
         }
-    }
     } # end foreach my $package (@rt_uris)
     return $res;
 };

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


More information about the rt-commit mailing list