Fixes to disable-ticketless + TakeAction
[usit-rt.git] / local / bin / rt-disable-ticketless
... / ...
CommitLineData
1#!/usr/bin/perl
2
3use lib '/www/data/rt/rt-perl/current-perl10/share/perl5';
4use lib '/www/data/rt/rt-perl/current-perl10/lib/perl5';
5use lib '/www/data/rt/rt-perl/current-perl10/lib64/perl5';
6
7use lib ("/www/var/rt/local/lib", "/www/var/rt/lib");
8use strict;
9use warnings;
10
11use RT;
12
13RT::LoadConfig();
14RT::Init();
15
16my $priv = new RT::Group($RT::SystemUser);
17$priv->LoadSystemInternalGroup('Privileged');
18
19# This is a more efficient way to do my $users = new RT::Users($SystemUser);while (my $user = $users->next) {...}
20my $Handle = $RT::Handle->SimpleQuery("SELECT DISTINCT main.id FROM Users main JOIN Principals Principals_1 ON ( Principals_1.id = main.id ) WHERE (Principals_1.Disabled = '0') AND (LOWER(Principals_1.PrincipalType) = 'user') ORDER BY main.id");
21
22while (my @r = $Handle->fetchrow) {
23my $id = $r[0];
24next if $priv->HasMember($id);
25next if ($id==10); # Nobody has a bunch of tickets.
26# This is really slow but after the first run it will be smooth sailing.
27my @result = $RT::Handle->FetchResult("SELECT DISTINCT main.* FROM Tickets main JOIN Groups Groups_1 ON ( Groups_1.Domain = 'RT::Ticket-Role' ) AND ( Groups_1.Instance = main.id ) JOIN CachedGroupMembers CachedGroupMembers_2 ON ( CachedGroupMembers_2.GroupId = Groups_1.id ) JOIN Users Users_3 ON ( Users_3.id = CachedGroupMembers_2.MemberId ) WHERE (CachedGroupMembers_2.Disabled = '0') AND ( ( Users_3.id = $id ) ) AND (main.Type = 'ticket') AND (main.EffectiveId = main.id) LIMIT 1");
28unless (@result) {
29my $User = new RT::User($RT::SystemUser);
30 $User->Load($id);
31 next if ($User->Name !~ /\@/);
32 my $delta = Delta_Format(DateCalc($User->Created,"2013-05-23 12:10"), 0, '%dh');
33 my $msg = "$id - ".$User->Name." - Delta: $delta ";
34 if ($delta <= 30) {$msg .= " - NOT DISABLE!!!\n"}
35 else {$msg .= $User->SetDisabled(1)."\n"};
36 $RT::Logger->info("$msg");
37 print $msg;
38}
39
40}