[Rt-commit] rt branch 5.0/validator-skip-deleted-with-contenthistory created. rt-5.0.2-61-ge250dc4593
BPS Git Server
git at git.bestpractical.com
Fri Feb 4 22:02:23 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 e250dc4593205e646193b775ad9b752b480a16b8 (commit)
- Log -----------------------------------------------------------------
commit e250dc4593205e646193b775ad9b752b480a16b8
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..175aa0657d 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -761,10 +761,44 @@ 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 transactions s JOIN attributes 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 ) {
+ # Attribute needs special handling because we actually
+ # delete rows out of it rather than just disabling them
+ next if $model eq 'Attribute';
$res *= check_integrity(
'Transactions', 'ObjectId' => m2t($model), 'id',
condition => 's.ObjectType = ?',
@@ -779,6 +813,20 @@ push @CHECKS, 'Transactions -> other' => sub {
},
);
}
+ # objecttype = Attribute
+ $res *= check_integrity(
+ 'Transactions', 'ObjectId' => m2t('Attribute'), 'id',
+ condition => 's.ObjectType = ?' . $deleted_attributes_not_in,
+ bind_values => [ 'RT::Attribute', @deleted_attributes_binds ],
+ action => sub {
+ my $id = shift;
+ return unless prompt(
+ 'Delete', "Found a transaction without object."
+ );
+
+ delete_record( 'Transactions', $id );
+ },
+ );
# type = CustomField
$res *= check_integrity(
'Transactions', 'Field' => 'CustomFields', 'id',
@@ -985,12 +1033,21 @@ push @CHECKS, Scrips => sub {
push @CHECKS, Attributes => sub {
my $res = 1;
foreach my $model ( @models ) {
+ # Attribute needs special handling because we actually
+ # delete rows out of it rather than just disabling them
+ next if $model eq 'Attribute';
$res *= check_integrity(
'Attributes', 'ObjectId' => m2t($model), 'id',
condition => 's.ObjectType = ?',
bind_values => [ "RT::$model" ],
);
}
+ # objecttype = Attribute
+ $res *= check_integrity(
+ 'Attributes', 'ObjectId' => m2t('Attribute'), 'id',
+ condition => 's.ObjectType = ?' . $deleted_attributes_not_in,
+ bind_values => [ 'RT::Attribute', @deleted_attributes_binds ],
+ );
return $res;
};
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list