[Rt-commit] rt branch 5.0/validator-skip-deleted-with-contenthistory created. rt-5.0.2-61-geb06b9aba1

BPS Git Server git at git.bestpractical.com
Mon Feb 7 14:15:50 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/validator-skip-deleted-with-contenthistory has been created
        at  eb06b9aba1599d57c2acccc75ccc4709da9e8309 (commit)

- Log -----------------------------------------------------------------
commit eb06b9aba1599d57c2acccc75ccc4709da9e8309
Author: Brian Conry <bconry at bestpractical.com>
Date:   Fri Feb 4 15:57:54 2022 -0600

    No validator flagging of properly deleted attributes
    
    Saved searches and dashboards are implemented as attributes, and
    attributes are deleted from the database rather than being disabled.
    This leaves some "dangling" references to them in the Transactions and
    Attributes tables ('ContentHistory' records in Attributes).
    
    These references are not issues and should not be flagged as such.

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index ac686af5d3..90d805a54e 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -761,14 +761,52 @@ END
     return $res;
 };
 
+# Attributes are currently deleted rather than disabled, this leaves
+# dangling references, both in Transactions and in Attributes.
+# These are expected and should not be flagged.
+# So rather than try to create complicated joins to filter them out
+# in both places, we're going to create a list of the deleted
+# Attribute ids up front and create a NOT IN clause that can
+# be included where it is needed.
+my @deleted_attributes_binds;
+my $deleted_attributes_not_in = '';
+
+{
+    my $query = "SELECT DISTINCT s.objectid"
+        ." FROM ".m2t("Transaction")." s JOIN ".m2t("Attribute")." t"
+        ." ON ( s.objecttype = ? AND s.objectid = t.objectid AND t.name = ? )"
+        ." WHERE s.type = ?";
+
+    my $sth = execute_query( $query, 'RT::Attribute', 'ContentHistory', 'Delete' );
+
+    my @deleted_attributes;
+
+    while ( my ($deleted_attribute) = $sth->fetchrow_array ) {
+        push @deleted_attributes, $deleted_attribute;
+    }
+
+    while (@deleted_attributes) {
+        my @batch = splice( @deleted_attributes, 0, 1000 );
+        push @deleted_attributes_binds, @batch;
+
+        $deleted_attributes_not_in .= ' AND s.objectid NOT IN (' . join( ',', ('?') x @batch ) . ')';
+    }
+}
 
 push @CHECKS, 'Transactions -> other' => sub {
     my $res = 1;
     foreach my $model ( @models ) {
         $res *= check_integrity(
             'Transactions', 'ObjectId' => m2t($model), 'id',
-            condition   => 's.ObjectType = ?',
-            bind_values => [ "RT::$model" ],
+            condition   => 's.ObjectType = ?' . (
+                # Attribute needs special handling because we actually
+                # delete rows out of it rather than just disabling them
+                $model eq 'Attribute' ? $deleted_attributes_not_in : ''
+            ),
+            bind_values => [
+                "RT::$model",
+                ($model eq 'Attribute' ? @deleted_attributes_binds : ())
+            ],
             action => sub {
                 my $id = shift;
                 return unless prompt(
@@ -987,8 +1025,15 @@ push @CHECKS, Attributes => sub {
     foreach my $model ( @models ) {
         $res *= check_integrity(
             'Attributes', 'ObjectId' => m2t($model), 'id',
-            condition   => 's.ObjectType = ?',
-            bind_values => [ "RT::$model" ],
+            condition   => 's.ObjectType = ?' . (
+                # Attribute needs special handling because we actually
+                # delete rows out of it rather than just disabling them
+                $model eq 'Attribute' ? $deleted_attributes_not_in : ''
+            ),
+            bind_values => [
+                "RT::$model",
+                ($model eq 'Attribute' ? @deleted_attributes_binds : ())
+            ],
         );
     }
     return $res;

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list