[rt-devel] Feature Request: Remove Comments
Matt Knopp
mhat at netlag.com
Sun Aug 3 17:36:29 EDT 2003
Nifty. With some prodding (see diff) it can be made to work.
--
Matt
On Sun, Aug 03, 2003 at 04:51:26PM -0400, Jesse Vincent wrote:
> I believe the commandline script in /contrib/2.0/rt-addons/CensorWare/
> or thereabout should still work for this.
-------------- next part --------------
--- delete-transaction Sun Jun 17 15:57:38 2001
+++ delete-transaction-3 Sun Aug 3 16:32:52 2003
@@ -6,24 +6,22 @@
use Carp;
use Getopt::Long;
-use lib "/opt/rt2/lib";
-use lib "/opt/rt2/etc";
+use lib "/path/to/rt/lib";
+use lib "/path/to/rt/etc";
my ($tid, $transid);
-use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect
- GetCurrentUser GetMessageContent);
+use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
+CleanEnv();
+
+use RT;
use RT::Ticket;
use RT::Date;
-#Clean out all the nasties from the environment
-CleanEnv();
-
-#Load etc/config.pm and drop privs
-LoadConfig();
-
-#Connect to the database and get RT::SystemUser and RT::Nobody loaded
-DBConnect();
+#Load RT's config file
+RT::LoadConfig();
+# Connect to the database. set up loggign
+RT::Init();
#Get the current user all loaded
my $CurrentUser = GetCurrentUser();
@@ -38,8 +36,14 @@
}
if ($argument eq '--help') {
- print "delete-transaction <ticketid>/<transactionid> [reason]\nThis tool removes attachments from transactions and purges them from the system.\n[reason] is a quoted string to be inserted into the database as an explanation of why you've deleted this content";
- exit(0);
+ print qq|delete-transaction <ticketid>/<transactionid> [reason]
+
+This tool replaces the mime attachment for a the provided ticketid and
+transactionid with a message noting that the original content has been
+removed.
+
+|;
+ exit(0);
}
@@ -58,29 +62,35 @@
exit(1);
}
-unless ($CurrentUser->HasSystemRight('SuperUser')) {
- print "ERROR: only the superuser can delete transaction content\n";
- exit(1);
-}
+# XXX - Arguably something better should be done here. I'm not sure how to
+# check the "SystemRight" with RT3's ACLs? Maybe calling HasRight with an
+# argument of 'SuperUser' would be sufficent.
+#
+#unless ($CurrentUser->HasSystemRight('SuperUser')) {
+# print "ERROR: only the superuser can delete transaction content\n";
+# exit(1);
+#}
my $date = new RT::Date($CurrentUser);
$date->SetToNow();
-
my $attachments = $Transaction->Attachments();
while (my $attachment = $attachments->Next) {
- my ($val, $msg);
- print "Now deleting content and headers for attachment #".$attachment->Id."\n";
- $val,$msg = $attachment->__Set( Field => 'Headers',Value =>'');
- $val, $msg = $attachment->__Set( Field => 'ContentType',Value => 'text/plain');
- $val, $msg = $attachment->__Set( Field => 'Content', Value => "This MIME Object was purged from the database ".
- "by ".$CurrentUser->Name." (".$CurrentUser->Id.") at ".
- $date->ISO." GMT for the follwing reason:\n".$reason ."\n");
+ my ($val, $msg);
+ print "Now deleting content and headers for attachment #";
+ print $attachment->Id, "\n";
+
+ my $type = 'text/plain';
+ my $content = "";
+ $content .= "The original content has been purged from the database ";
+ $content .= "by ", $CurrentUser->Name(), " at ", $date->ISO(), " ";
+ $content .= "for the following reason:\n", $reason, "\n";
+
+ $val,$msg = $attachment->__Set(Field => 'Headers', Value =>'');
+ $val,$msg = $attachment->__Set(Field => 'ContentType', Value =>$type);
+ $val,$msg = $attachment->__Set(Field => 'Content', Value =>$content);
}
-
$Ticket->_NewTransaction('Type' => 'PurgeTransaction',
'Data' => $Transaction->Id);
-
-
$RT::Handle->Disconnect();
More information about the Rt-devel
mailing list