diff options
Diffstat (limited to 'rt/etc')
37 files changed, 2953 insertions, 260 deletions
diff --git a/rt/etc/acl.Informix b/rt/etc/acl.Informix index bca0408dd..eff232f4d 100644 --- a/rt/etc/acl.Informix +++ b/rt/etc/acl.Informix @@ -1,5 +1,6 @@ + sub acl { -return ( -"GRANT RESOURCE TO ${RT::DatabaseUser};"); + return ("GRANT RESOURCE TO ". RT->Config->Get('DatabaseUser') .";"); } + 1; diff --git a/rt/etc/acl.Sybase b/rt/etc/acl.Sybase index 6192b4ebe..7583c02e3 100644 --- a/rt/etc/acl.Sybase +++ b/rt/etc/acl.Sybase @@ -1,6 +1,10 @@ + sub acl { -return ( -"SP_ADDLOGIN ${RT::DatabaseUser}, ${RT::DatabasePassword}, ${RT::DatabaseName} ", -); + my $db_name = RT->Config->Get('DatabaseName'); + my $db_user = RT->Config->Get('DatabaseUser'); + my $db_pass = RT->Config->Get('DatabasePassword'); + + return ("SP_ADDLOGIN $db_user, $db_pass, $db_name"); } + 1; diff --git a/rt/etc/initialdata b/rt/etc/initialdata index 54fa9d195..89db2cc64 100644 --- a/rt/etc/initialdata +++ b/rt/etc/initialdata @@ -1,63 +1,18 @@ # Initial data for a fresh RT3 Installation. @Users = ( - { Name => 'Nobody', - RealName => 'Nobody in particular', - Comments => 'Do not delete or modify this user. It is integral ' - . 'to RT\'s internal data structures', - Privileged => '0', }, - { Name => 'root', Gecos => 'root', RealName => 'Enoch Root', Password => 'password', EmailAddress => "root\@localhost", Comments => 'SuperUser', - Privileged => '1', } ); + Privileged => '1', + }, +); @Groups = ( - { Name => '', - Type => 'Everyone', # loc - Domain => 'SystemInternal', - Instance => '', - Description => 'Pseudogroup for internal use', # loc - }, - { Type => 'Privileged', # loc - Domain => 'SystemInternal', - Instance => '', - Name => '', - Description => 'Pseudogroup for internal use', # loc - }, - { Name => '', - Type => 'Unprivileged', # loc - Domain => 'SystemInternal', - Instance => '', - Description => 'Pseudogroup for internal use', # loc - }, - { Name => '', - Type => 'Owner', # loc - Domain => 'RT::System-Role', - Instance => '', - Description => 'SystemRolegroup for internal use', # loc - }, - { Name => '', - Type => 'Requestor', # loc - Domain => 'RT::System-Role', - Instance => '', - Description => 'SystemRolegroup for internal use', # loc - }, - { Name => '', - Type => 'Cc', # loc - Domain => 'RT::System-Role', - Instance => '', - Description => 'SystemRolegroup for internal use', # loc - }, - { Name => '', - Type => 'AdminCc', # loc - Domain => 'RT::System-Role', - Instance => '', - Description => 'Pseudogroup for internal use', # loc - }, ); +); @Queues = ({ Name => 'General', Description => 'The default queue', @@ -113,12 +68,12 @@ ExecModule => 'Notify', Argument => 'Requestor,Cc' }, - { Name => 'Notify Requestors, Ccs and AdminCcs as Comment', # loc - Description => 'Send mail to all watchers as a "comment"', # loc + { Name => 'Notify Owner, Requestors, Ccs and AdminCcs as Comment', # loc + Description => 'Send mail to owner and all watchers as a "comment"', # loc ExecModule => 'NotifyAsComment', Argument => 'All' }, - { Name => 'Notify Requestors, Ccs and AdminCcs', # loc - Description => 'Send mail to all watchers', # loc + { Name => 'Notify Owner, Requestors, Ccs and AdminCcs', # loc + Description => 'Send mail to owner and all watchers', # loc ExecModule => 'Notify', Argument => 'All' }, { Name => 'Notify Other Recipients as Comment', # loc @@ -139,6 +94,9 @@ { Name => 'Open Tickets', # loc Description => 'Open tickets on correspondence', # loc ExecModule => 'AutoOpen' }, + { Name => 'Extract Subject Tag', # loc + Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc + ExecModule => 'ExtractSubjectTag' }, ); @ScripConditions = ( @@ -202,7 +160,13 @@ Argument => 'resolved' }, + { Name => 'On Reject', # loc + Description => 'Whenever a ticket is rejected', # loc + ApplicableTransTypes => 'Status', + ExecModule => 'StatusChange', + Argument => 'rejected' + }, { Name => 'User Defined', # loc Description => 'Whenever a user-defined condition occurs', # loc ApplicableTransTypes => 'Any', @@ -210,6 +174,17 @@ }, + { Name => 'On Close', # loc + Description => 'Whenever a ticket is closed', # loc + ApplicableTransTypes => 'Status,Set', + ExecModule => 'CloseTicket', + }, + { Name => 'On Reopen', # loc + Description => 'Whenever a ticket is reopened', # loc + ApplicableTransTypes => 'Status,Set', + ExecModule => 'ReopenTicket', + }, + ); @Templates = ( @@ -231,11 +206,11 @@ creation of a trouble ticket regarding: a summary of which appears below. There is no need to reply to this message right now. Your ticket has been -assigned an ID of [{$rtname} #{$Ticket->id()}]. +assigned an ID of [{$Ticket->QueueObj->SubjectTag || $rtname} #{$Ticket->id()}]. Please include the string: - [{$rtname} #{$Ticket->id}] + [{$Ticket->QueueObj->SubjectTag || $rtname} #{$Ticket->id}] in the subject line of all future correspondence about this issue. To do so, you may reply to this message. @@ -255,13 +230,13 @@ you may reply to this message. {$Transaction->CreatedAsString}: Request {$Ticket->id} was acted upon. -Transaction: {$Transaction->Description} + Transaction: {$Transaction->Description} Queue: {$Ticket->QueueObj->Name} Subject: {$Transaction->Subject || $Ticket->Subject || "(No subject given)"} Owner: {$Ticket->OwnerObj->Name} Requestors: {$Ticket->RequestorAddresses} Status: {$Ticket->Status} - Ticket <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} > + Ticket <URL: {RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Ticket->id} > {$Transaction->Content()} @@ -276,7 +251,7 @@ Transaction: {$Transaction->Description} Content => 'RT-Attach-Message: yes -<URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} > +<URL: {RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Ticket->id} > {$Transaction->Content()} ' @@ -295,10 +270,11 @@ Transaction: {$Transaction->Description} Name => 'Admin Comment', # loc Description => 'Default admin comment template', # loc Content => -'Subject: [Comment] {my $s=($Transaction->Subject||$Ticket->Subject); $s =~ s/\\[Comment\\]//g; $comment =~ s/^Re//i; $s;} +'Subject: [Comment] {my $s=($Transaction->Subject||$Ticket->Subject); $s =~ s/\\[Comment\\]//g; $s =~ s/^Re//i; $s;} +RT-Attach-Message: yes -{$RT::WebURL}Ticket/Display.html?id={$Ticket->id} +{RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Ticket->id} This is a comment. It is not sent to the Requestor(s): {$Transaction->Content()} @@ -311,7 +287,7 @@ This is a comment. It is not sent to the Requestor(s): Content => 'Subject: Status Changed to: {$Transaction->NewValue} -{$RT::WebURL}Ticket/Display.html?id={$Ticket->id} +{RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Ticket->id} {$Transaction->Content()} ' @@ -339,8 +315,8 @@ Greetings, There is a new item pending your approval: "{$Ticket->Subject()}", a summary of which appears below. -Please visit {$RT::WebURL}Approvals/Display.html?id={$Ticket->id} -to approve or reject this ticket, or {$RT::WebURL}Approvals/ to +Please visit {RT->Config->Get(\'WebURL\')}Approvals/Display.html?id={$Ticket->id} +to approve or reject this ticket, or {RT->Config->Get(\'WebURL\')}Approvals/ to batch-process all your pending approvals. ------------------------------------------------------------------------- @@ -350,24 +326,29 @@ batch-process all your pending approvals. { Queue => '___Approvals', Name => "Approval Passed", # loc Description => - "Notify Owner of their ticket has been approved by some approver", # loc + "Notify Requestor of their ticket has been approved by some approver", # loc Content => 'Subject: Ticket Approved: {$Ticket->Subject} Greetings, Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }. Other approvals may be pending. + +Approver\'s notes: { $Notes } ' }, { Queue => '___Approvals', Name => "All Approvals Passed", # loc Description => - "Notify Owner of their ticket has been approved by all approvers", # loc + "Notify Requestor of their ticket has been approved by all approvers", # loc Content => 'Subject: Ticket Approved: {$Ticket->Subject} Greetings, -Your ticket has been approved. Its Owner may now start to act on it. +Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }. +Its Owner may now start to act on it. + +Approver\'s notes: { $Notes } ' }, { Queue => '___Approvals', @@ -379,211 +360,190 @@ Your ticket has been approved. Its Owner may now start to act on it. Greetings, Your ticket has been rejected by { eval { $Approval->OwnerObj->Name } }. + +Approver\'s notes: { $Notes } +' + }, + { Queue => '___Approvals', + Name => "Approval Ready for Owner", # loc + Description => + "Notify Owner of their ticket has been approved and is ready to be acted on", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} + +Greetings, + +The ticket has been approved, you may now start to act on it. + ' }, + { Queue => 0, + Name => "Forward", # loc + Description => "Heading of a forwarded message", # loc + Content => q{ +This is a forward of transaction #{$Transaction->id} of ticket #{ $Ticket->id } +} + }, + { Queue => 0, + Name => "Forward Ticket", # loc + Description => "Heading of a forwarded Ticket", # loc + Content => q{ + +This is a forward of ticket #{ $Ticket->id } +} + }, + { Queue => 0, + Name => "Error: public key", # loc + Description => + "Inform user that he has problems with public key and couldn't recieve encrypted content", # loc + Content => q{Subject: We have no your public key or it's wrong + +You received this message as we have no your public PGP key or we have a problem with your key. Inform the administrator about the problem. +} + }, + { Queue => 0, + Name => "Error to RT owner: public key", # loc + Description => + "Inform RT owner that user(s) have problems with public keys", # loc + Content => q{Subject: Some users have problems with public keys + +You received this message as RT has problems with public keys of the following user: +{ + foreach my $e ( @BadRecipients ) { + $OUT .= "* ". $e->{'Message'} ."\n"; + } +}} + }, + { Queue => 0, + Name => "Error: no private key", # loc + Description => + "Inform user that we received an encrypted email and we have no private keys to decrypt", # loc + Content => q{Subject: we received message we cannot decrypt + +You sent an encrypted message with subject '{ $Message->head->get('Subject') }', +but we have no private key it's encrypted to. + +Please, check that you encrypt messages with correct keys +or contact the system administrator.} + }, + { Queue => 0, + Name => "Error: bad GnuPG data", # loc + Description => + "Inform user that a message he sent has invalid GnuPG data", # loc + Content => q{Subject: We received a message we cannot handle + +You sent us a message that we cannot handle due to corrupted GnuPG signature or encrypted block. we get the following error(s): +{ foreach my $msg ( @Messages ) { + $OUT .= "* $msg\n"; + } +}} + }, + { Queue => 0, + Name => "PasswordChange", # loc + Description => + "Inform user that his password has been reset", # loc + Content => q{Subject: [{RT->Config->Get('rtname')}] Password reset + +Greetings, + +Someone at {$ENV{'REMOTE_ADDR'}} requested a password reset for you on {RT->Config->Get('WebURL')} + +Your new password is: + {$NewPassword} +} + }, + + { Queue => '0', + Name => 'Email Digest', # loc + Description => 'Email template for periodic notification digests', # loc + Content => q[Subject: RT Email Digest + +{ $Argument } +], + }, + +{ + Queue => 0, + Name => "Error: Missing dashboard", # loc + Description => + "Inform user that a dashboard he subscribed to is missing", # loc + Content => q{Subject: [{RT->Config->Get('rtname')}] Missing dashboard! + +Greetings, + +You are subscribed to a dashboard that is currently missing. Most likely, the dashboard was deleted. + +RT will remove this subscription as it is no longer useful. Here's the information RT had about your subscription: + +DashboardID: { $SubscriptionObj->SubValue('DashboardId') } +Frequency: { $SubscriptionObj->SubValue('Frequency') } +Hour: { $SubscriptionObj->SubValue('Hour') } +{ + $SubscriptionObj->SubValue('Frequency') eq 'weekly' + ? "Day of week: " . $SubscriptionObj->SubValue('Dow') + : $SubscriptionObj->SubValue('Frequency') eq 'monthly' + ? "Day of month: " . $SubscriptionObj->SubValue('Dom') + : '' +} +} +}, ); # }}} @Scrips = ( - { ScripCondition => 'On Correspond', + { Description => 'On Correspond Open Tickets', + ScripCondition => 'On Correspond', ScripAction => 'Open Tickets', Template => 'Blank' }, - { ScripCondition => 'On Owner Change', + { Description => 'On Owner Change Notify Owner', + ScripCondition => 'On Owner Change', ScripAction => 'Notify Owner', Template => 'Transaction' }, - { ScripCondition => 'On Create', + { Description => 'On Create Autoreply To Requestors', + ScripCondition => 'On Create', ScripAction => 'AutoReply To Requestors', Template => 'AutoReply' }, - { ScripCondition => 'On Create', + { Description => 'On Create Notify AdminCcs', + ScripCondition => 'On Create', ScripAction => 'Notify AdminCcs', Template => 'Transaction' }, - { ScripCondition => 'On Correspond', + { Description => 'On Correspond Notify AdminCcs', + ScripCondition => 'On Correspond', ScripAction => 'Notify AdminCcs', Template => 'Admin Correspondence' }, - { ScripCondition => 'On Correspond', + { Description => 'On Correspond Notify Requestors and Ccs', + ScripCondition => 'On Correspond', ScripAction => 'Notify Requestors And Ccs', Template => 'Correspondence' }, - { ScripCondition => 'On Correspond', + { Description => 'On Correspond Notify Other Recipients', + ScripCondition => 'On Correspond', ScripAction => 'Notify Other Recipients', Template => 'Correspondence' }, - { ScripCondition => 'On Comment', + { Description => 'On Comment Notify AdminCcs as Comment', + ScripCondition => 'On Comment', ScripAction => 'Notify AdminCcs As Comment', Template => 'Admin Comment' }, - { ScripCondition => 'On Comment', + { Description => 'On Comment Notify Other Recipients as Comment', + ScripCondition => 'On Comment', ScripAction => 'Notify Other Recipients As Comment', Template => 'Correspondence' }, - { ScripCondition => 'On Resolve', + { Description => 'On Resolve Notify Requestors', + ScripCondition => 'On Resolve', ScripAction => 'Notify Requestors', Template => 'Resolved' }, - { Description => "When an approval ticket is created, notify the Owner and AdminCc of the item awaiting their approval", # loc - Queue => '___Approvals', - ScripCondition => 'User Defined', - CustomIsApplicableCode => q[ - $self->TicketObj->Type eq 'approval' and - $self->TransactionObj->Field eq 'Status' and - $self->TransactionObj->NewValue eq 'open' and - eval { $T::Approving = ($self->TicketObj->AllDependedOnBy( Type => 'ticket' ))[0] } - ], - ScripAction => 'Notify Owner', - Template => 'New Pending Approval' }, - { Description => "If an approval is rejected, reject the original and delete pending approvals", # loc - Queue => '___Approvals', - ScripCondition => 'On Status Change', - ScripAction => 'User Defined', - CustomPrepareCode => q[ -# ------------------------------------------------------------------- # -return(0) unless ( lc($self->TransactionObj->NewValue) eq "rejected" or - lc($self->TransactionObj->NewValue) eq "deleted" ); - -my $rejected = 0; -my $links = $self->TicketObj->DependedOnBy; -foreach my $link (@{ $links->ItemsArrayRef }) { - my $obj = $link->BaseObj; - if ($obj->QueueObj->IsActiveStatus($obj->Status)) { - if ($obj->Type eq 'ticket') { - $obj->Comment( - Content => $self->loc("Your request was rejected."), - ); - $obj->SetStatus( - Status => 'rejected', - Force => 1, - ); - - $T::Approval = $self->TicketObj; # so we can access it inside templates - $self->{TicketObj} = $obj; # we want the original id in the token line - $rejected = 1; - } - else { - $obj->SetStatus( - Status => 'deleted', - Force => 1, - ); - } - } -} - -$links = $self->TicketObj->DependsOn; -foreach my $link (@{ $links->ItemsArrayRef }) { - my $obj = $link->TargetObj; - if ($obj->QueueObj->IsActiveStatus($obj->Status)) { - $obj->SetStatus( - Status => 'deleted', - Force => 1, - ); - } -} - -# Now magically turn myself into a Requestor Notify object... -require RT::Action::Notify; bless($self, 'RT::Action::Notify'); -$self->{Argument} = 'Requestor'; $self->Prepare; - -return $rejected; -# ------------------------------------------------------------------- # - ], - CustomCommitCode => '"never needed"', - Template => 'Approval Rejected', }, - { Description => "When a ticket has been approved by any approver, add correspondence to the original ticket", # loc - Queue => '___Approvals', - ScripCondition => 'On Resolve', - ScripAction => 'User Defined', - CustomPrepareCode => q[ -# ------------------------------------------------------------------- # -return(0) unless ($self->TicketObj->Type eq 'approval'); - -my $note; -my $t = $self->TicketObj->Transactions; -while (my $o = $t->Next) { - $note .= $o->Content . "\n" if $o->ContentObj - and $o->Content !~ /Default Approval/; -} - -foreach my $obj ($self->TicketObj->AllDependedOnBy( Type => 'ticket' )) { - $obj->Comment( - Content => $self->loc( "Your request has been approved by [_1]. Other approvals may still be pending.", # loc - $self->TransactionObj->CreatorObj->Name, - ) . "\n" . $self->loc( "Approver's notes: [_1]", # loc - $note - ), - ); - $T::Approval = $self->TicketObj; # so we can access it inside templates - $self->{TicketObj} = $obj; # we want the original id in the token line -} - -# Now magically turn myself into a Requestor Notify object... -require RT::Action::Notify; bless($self, 'RT::Action::Notify'); -$self->{Argument} = 'Requestor'; $self->Prepare; - -return 1; -# ------------------------------------------------------------------- # - ], - CustomCommitCode => '"never needed"', - Template => 'Approval Passed' }, - { Description => "When a ticket has been approved by all approvers, add correspondence to the original ticket", # loc - Queue => '___Approvals', - ScripCondition => 'On Resolve', - ScripAction => 'User Defined', - CustomPrepareCode => q[ -# ------------------------------------------------------------------- # -# Find all the tickets that depend on this (that this is approving) - -my $Ticket = $self->TicketObj; -my @TOP = $Ticket->AllDependedOnBy( Type => 'ticket' ); -my $links = $Ticket->DependedOnBy; -my $passed = 0; - -while (my $link = $links->Next) { - my $obj = $link->BaseObj; - next if ($obj->HasUnresolvedDependencies( Type => 'approval' )); - - if ($obj->Type eq 'ticket') { - $obj->Comment( - Content => $self->loc("Your request has been approved."), - ); - $T::Approval = $Ticket; # so we can access it inside templates - $self->{TicketObj} = $obj; # we want the original id in the token line - $passed = 1; - } - elsif ($obj->Type eq 'approval') { - $obj->SetStatus( Status => 'open', Force => 1 ); - } - elsif ($RT::UseCodeTickets and $obj->Type eq 'code') { - my $code = $obj->Transactions->First->Content; - my $rv; - - foreach my $TOP (@TOP) { - local $@; - $rv++ if eval $code; - $RT::Logger->error("Cannot eval code: $@") if $@; - } - - if ($rv or !@TOP) { - $obj->SetStatus( Status => 'resolved', Force => 1,); - } - else { - $obj->SetStatus( Status => 'rejected', Force => 1,); - } - } -} - -# Now magically turn myself into a Requestor Notify object... -require RT::Action::Notify; bless($self, 'RT::Action::Notify'); -$self->{Argument} = 'Requestor'; $self->Prepare; - -return 0; # ignore $passed; -# ------------------------------------------------------------------- # - ], - CustomCommitCode => '"never needed"', - Template => 'All Approvals Passed', }, - + { Description => "On transaction, add any tags in the transaction's subject to the ticket's subject", + ScripCondition => 'On Transaction', + ScripAction => 'Extract Subject Tag', + Template => 'Blank' }, ); @ACL = ( - { UserId => 'Nobody', # - principalId - Right => 'OwnTicket', }, - { UserId => 'root', # - principalid Right => 'SuperUser', }, + { GroupDomain => 'SystemInternal', + GroupType => 'privileged', + Right => 'ShowApprovalsTab', }, + ); # Predefined searches @@ -592,34 +552,53 @@ return 0; # ignore $passed; { Name => 'Search - My Tickets', Description => '[_1] highest priority tickets I own', # loc Content => - { Format => "'<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__id__</a>/TITLE:#', '<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__Subject__</a>/TITLE:Subject', Priority, QueueName, ExtendedStatus", + { Format => q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',} + . q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',} + . q{Priority, QueueName, ExtendedStatus}, Query => " Owner = '__CurrentUser__' AND ( Status = 'new' OR Status = 'open')", OrderBy => 'Priority', - Order => 'DESC' }, + Order => 'DESC' + }, }, { Name => 'Search - Unowned Tickets', Description => '[_1] newest unowned tickets', # loc Content => # 'Take' #loc - { Format => "'<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__id__</a>/TITLE:#', '<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__Subject__</a>/TITLE:Subject', QueueName, ExtendedStatus, CreatedRelative, '<A HREF=\"__WebPath__/Ticket/Display.html?Action=Take&id=__id__\">__loc(Take)__</a>/TITLE: ' ", + { Format => q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',} + . q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',} + . q{QueueName, ExtendedStatus, CreatedRelative, } + . q{'<A HREF="__WebPath__/Ticket/Display.html?Action=Take&id=__id__">__loc(Take)__</a>/TITLE:NBSP'}, Query => " Owner = 'Nobody' AND ( Status = 'new' OR Status = 'open')", OrderBy => 'Created', + Order => 'DESC' + }, + }, + { Name => 'Search - Bookmarked Tickets', + Description => 'Bookmarked Tickets', #loc + Content => + { Format => q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',} + . q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',} + . q{Priority, QueueName, ExtendedStatus, Bookmark}, + Query => "id = '__Bookmarked__'", + OrderBy => 'LastUpdated', Order => 'DESC' }, }, { Name => 'HomepageSettings', Description => 'HomepageSettings', Content => { 'body' => # loc - [ { type => 'system', name => 'My Tickets' }, - { type => 'system', name => 'Unowned Tickets' }, - { type => 'component', name => 'QuickCreate'}, - ], + [ { type => 'system', name => 'My Tickets' }, + { type => 'system', name => 'Unowned Tickets' }, + { type => 'system', name => 'Bookmarked Tickets' }, + { type => 'component', name => 'QuickCreate' }, + ], 'summary' => # loc - [ - { type => 'component', name => 'MyReminders' }, + [ + { type => 'component', name => 'MyReminders' }, { type => 'component', name => 'Quicksearch' }, - { type => 'component', name => 'RefreshHomepage' }, - ] + { type => 'component', name => 'Dashboards' }, + { type => 'component', name => 'RefreshHomepage' }, + ], + }, }, -} ); diff --git a/rt/etc/schema.SQLite b/rt/etc/schema.SQLite index 8791bb47e..ce75ccc13 100644 --- a/rt/etc/schema.SQLite +++ b/rt/etc/schema.SQLite @@ -367,7 +367,7 @@ CREATE TABLE CustomFields ( Name varchar(200) NULL , Type varchar(200) NULL , # Changed -- 'Single' and 'Multiple' is moved out MaxValues integer, # New -- was 'Single'(1) and 'Multiple'(0) - Pattern varchar(255) NULL , # New -- Must validate against this + Pattern varchar(65536) NULL , # New -- Must validate against this Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry Description varchar(255) NULL , SortOrder integer NOT NULL DEFAULT 0 , diff --git a/rt/etc/schema.mysql-4.0 b/rt/etc/schema.mysql-4.0 new file mode 100755 index 000000000..c4299d472 --- /dev/null +++ b/rt/etc/schema.mysql-4.0 @@ -0,0 +1,464 @@ +# {{{ Attachments + +CREATE TABLE Attachments ( + id INTEGER NOT NULL AUTO_INCREMENT, + TransactionId integer NOT NULL , + Parent integer NOT NULL DEFAULT 0 , + MessageId varchar(160) NULL , + Subject varchar(255) NULL , + Filename varchar(255) NULL , + ContentType varchar(80) NULL , + ContentEncoding varchar(80) NULL , + Content LONGTEXT NULL , + Headers LONGTEXT NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Attachments2 ON Attachments (TransactionId) ; +CREATE INDEX Attachments3 ON Attachments (Parent, TransactionId) ; +# }}} + +# {{{ Queues +CREATE TABLE Queues ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NOT NULL , + Description varchar(255) NULL , + CorrespondAddress varchar(120) NULL , + CommentAddress varchar(120) NULL , + InitialPriority integer NOT NULL DEFAULT 0 , + FinalPriority integer NOT NULL DEFAULT 0 , + DefaultDueIn integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB; +CREATE UNIQUE INDEX Queues1 ON Queues (Name) ; +CREATE INDEX Queues2 ON Queues (Disabled) ; + +# }}} + +# {{{ Links + +CREATE TABLE Links ( + id INTEGER NOT NULL AUTO_INCREMENT, + Base varchar(240) NULL , + Target varchar(240) NULL , + Type varchar(20) NOT NULL , + LocalTarget integer NOT NULL DEFAULT 0 , + LocalBase integer NOT NULL DEFAULT 0 , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Links2 ON Links (Base, Type) ; +CREATE INDEX Links3 ON Links (Target, Type) ; +CREATE INDEX Links4 ON Links (Type,LocalBase); + +# }}} + +# {{{ Principals + +CREATE TABLE Principals ( + id INTEGER AUTO_INCREMENT not null, + PrincipalType VARCHAR(16) not null, + ObjectId integer, # foreign key to Users or Groups, depending + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Principals2 ON Principals (ObjectId); + +# }}} + +# {{{ Groups + +CREATE TABLE Groups ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + Domain varchar(64), + Type varchar(64), + Instance integer, + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Groups1 ON Groups (Domain,Instance,Type,id); +CREATE INDEX Groups2 On Groups (Type, Instance); + +# }}} + +# {{{ ScripConditions + +CREATE TABLE ScripConditions ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + ExecModule varchar(60) NULL , + Argument varchar(255) NULL , + ApplicableTransTypes varchar(60) NULL , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ Transactions +CREATE TABLE Transactions ( + id INTEGER NOT NULL AUTO_INCREMENT, + ObjectType varchar(64) NOT NULL, + ObjectId integer NOT NULL DEFAULT 0 , + TimeTaken integer NOT NULL DEFAULT 0 , + Type varchar(20) NULL , + Field varchar(40) NULL , + OldValue varchar(255) NULL , + NewValue varchar(255) NULL , + ReferenceType varchar(255) NULL, + OldReference integer NULL , + NewReference integer NULL , + Data varchar(255) NULL , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; +CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId); + +# }}} + +# {{{ Scrips + +CREATE TABLE Scrips ( + id INTEGER NOT NULL AUTO_INCREMENT, + Description varchar(255), + ScripCondition integer NOT NULL DEFAULT 0 , + ScripAction integer NOT NULL DEFAULT 0 , + ConditionRules text NULL , + ActionRules text NULL , + CustomIsApplicableCode text NULL , + CustomPrepareCode text NULL , + CustomCommitCode text NULL , + Stage varchar(32) NULL , + Queue integer NOT NULL DEFAULT 0 , + Template integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ ACL +CREATE TABLE ACL ( + id INTEGER NOT NULL AUTO_INCREMENT, + PrincipalType varchar(25) NOT NULL, #"User" "Group", "Owner", "Cc" "AdminCc", "Requestor", "Requestor" + + PrincipalId integer NOT NULL , #Foreign key to principals + RightName varchar(25) NOT NULL , + ObjectType varchar(25) NOT NULL , + ObjectId integer NOT NULL default 0, + DelegatedBy integer NOT NULL default 0, #foreign key to principals with a userid + DelegatedFrom integer NOT NULL default 0, #foreign key to ACL + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX ACL1 on ACL(RightName, ObjectType, ObjectId,PrincipalType,PrincipalId); + +# }}} + +# {{{ GroupMembers + +CREATE TABLE GroupMembers ( + id INTEGER NOT NULL AUTO_INCREMENT, + GroupId integer NOT NULL DEFAULT 0, + MemberId integer NOT NULL DEFAULT 0, #Foreign key to Principals + PRIMARY KEY (id) +) TYPE=InnoDB; +CREATE UNIQUE INDEX GroupMembers1 on GroupMembers (GroupId, MemberId); + + +# }}} + +# {{{ GroupMembersCache + +create table CachedGroupMembers ( + id int auto_increment, + GroupId int, # foreign key to Principals + MemberId int, # foreign key to Principals + Via int, #foreign key to CachedGroupMembers. (may point to $self->id) + ImmediateParentId int, #foreign key to prinicpals. + # this points to the group that the member is + # a member of, for ease of deletes. + Disabled int2 NOT NULL DEFAULT 0 , # if this cached group member is a member of this group by way of a disabled + # group or this group is disabled, this will be set to 1 + # this allows us to not find members of disabled subgroups when listing off + # group members recursively. + # Also, this allows us to have the ACL system elide members of disabled groups + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX DisGrouMem on CachedGroupMembers (GroupId,MemberId,Disabled); +CREATE INDEX CachedGroupMembers3 on CachedGroupMembers (MemberId, ImmediateParentId); + +# }}} + +# {{{ Users + +CREATE TABLE Users ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NOT NULL , + Password varchar(40) NULL , + Comments blob NULL , + Signature blob NULL , + EmailAddress varchar(120) NULL , + FreeformContactInfo blob NULL , + Organization varchar(200) NULL , + RealName varchar(120) NULL , + NickName varchar(16) NULL , + Lang varchar(16) NULL , + EmailEncoding varchar(16) NULL , + WebEncoding varchar(16) NULL , + ExternalContactInfoId varchar(100) NULL , + ContactInfoSystem varchar(30) NULL , + ExternalAuthId varchar(100) NULL , + AuthSystem varchar(30) NULL , + Gecos varchar(16) NULL , + HomePhone varchar(30) NULL , + WorkPhone varchar(30) NULL , + MobilePhone varchar(30) NULL , + PagerPhone varchar(30) NULL , + Address1 varchar(200) NULL , + Address2 varchar(200) NULL , + City varchar(100) NULL , + State varchar(100) NULL , + Zip varchar(16) NULL , + Country varchar(50) NULL , + Timezone varchar(50) NULL , + PGPKey text NULL, + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + + +CREATE UNIQUE INDEX Users1 ON Users (Name) ; +CREATE INDEX Users4 ON Users (EmailAddress); + + +# }}} + +# {{{ Tickets + +CREATE TABLE Tickets ( + id INTEGER NOT NULL AUTO_INCREMENT, + EffectiveId integer NOT NULL DEFAULT 0 , + Queue integer NOT NULL DEFAULT 0 , + Type varchar(16) NULL , + IssueStatement integer NOT NULL DEFAULT 0 , + Resolution integer NOT NULL DEFAULT 0 , + Owner integer NOT NULL DEFAULT 0 , + Subject varchar(200) NULL DEFAULT '[no subject]' , + InitialPriority integer NOT NULL DEFAULT 0 , + FinalPriority integer NOT NULL DEFAULT 0 , + Priority integer NOT NULL DEFAULT 0 , + TimeEstimated integer NOT NULL DEFAULT 0 , + TimeWorked integer NOT NULL DEFAULT 0 , + Status varchar(10) NULL , + TimeLeft integer NOT NULL DEFAULT 0 , + Told DATETIME NULL , + Starts DATETIME NULL , + Started DATETIME NULL , + Due DATETIME NULL , + Resolved DATETIME NULL , + + + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Tickets1 ON Tickets (Queue, Status) ; +CREATE INDEX Tickets2 ON Tickets (Owner) ; +CREATE INDEX Tickets6 ON Tickets (EffectiveId, Type) ; + +# }}} + +# {{{ ScripActions + +CREATE TABLE ScripActions ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + ExecModule varchar(60) NULL , + Argument varchar(255) NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ Templates + +CREATE TABLE Templates ( + id INTEGER NOT NULL AUTO_INCREMENT, + Queue integer NOT NULL DEFAULT 0 , + Name varchar(200) NOT NULL , + Description varchar(255) NULL , + Type varchar(16) NULL , + Language varchar(16) NULL , + TranslationOf integer NOT NULL DEFAULT 0 , + Content blob NULL , + LastUpdated DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ ObjectCustomFieldValues + +CREATE TABLE ObjectCustomFieldValues ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField int NOT NULL , + ObjectType varchar(255) NOT NULL, # Final target of the Object + ObjectId int NOT NULL , # New -- Replaces Ticket + SortOrder integer NOT NULL DEFAULT 0 , # New -- ordering for multiple values + + Content varchar(255) NULL , + LargeContent LONGTEXT NULL, # New -- to hold 255+ strings + ContentType varchar(80) NULL, # New -- only text/* gets searched + ContentEncoding varchar(80) NULL , # New -- for binary Content + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , # New -- whether the value was current + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX ObjectCustomFieldValues1 ON ObjectCustomFieldValues (Content); +CREATE INDEX ObjectCustomFieldValues2 ON ObjectCustomFieldValues (CustomField,ObjectType,ObjectId); + +# }}} + +# {{{ CustomFields + +CREATE TABLE CustomFields ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Type varchar(200) NULL , # Changed -- 'Single' and 'Multiple' is moved out + MaxValues integer, # New -- was 'Single'(1) and 'Multiple'(0) + Pattern TEXT NULL , # New -- Must validate against this + Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry + Description varchar(255) NULL , + SortOrder integer NOT NULL DEFAULT 0 , + LookupType varchar(255) NOT NULL, + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ ObjectCustomFields + +CREATE TABLE ObjectCustomFields ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField int NOT NULL , + ObjectId integer NOT NULL, + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +# }}} + +# {{{ CustomFieldValues + +CREATE TABLE CustomFieldValues ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField int NOT NULL , + Name varchar(200) NULL , + Description varchar(255) NULL , + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX CustomFieldValues1 ON CustomFieldValues (CustomField); + +# }}} + + +# {{{ Attributes + +CREATE TABLE Attributes ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(255) NULL , + Description varchar(255) NULL , + Content text, + ContentType varchar(16), + ObjectType varchar(64), + ObjectId integer, # foreign key to anything + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB; + +CREATE INDEX Attributes1 on Attributes(Name); +CREATE INDEX Attributes2 on Attributes(ObjectType, ObjectId); + +# }}} + +# {{{ Sessions + +# sessions is used by Apache::Session to keep sessions in the database. +# We should have a reaper script somewhere. + +CREATE TABLE sessions ( + id char(32) NOT NULL, + a_session LONGTEXT, + LastUpdated TIMESTAMP, + PRIMARY KEY (id) +); + +# }}} diff --git a/rt/etc/schema.mysql-4.1 b/rt/etc/schema.mysql-4.1 new file mode 100755 index 000000000..172e477c1 --- /dev/null +++ b/rt/etc/schema.mysql-4.1 @@ -0,0 +1,466 @@ +# {{{ Attachments + +CREATE TABLE Attachments ( + id INTEGER NOT NULL AUTO_INCREMENT, + TransactionId integer NOT NULL , + Parent integer NOT NULL DEFAULT 0 , + MessageId varchar(160) CHARACTER SET ascii NULL , + Subject varchar(255) NULL , + Filename varchar(255) NULL , + ContentType varchar(80) CHARACTER SET ascii NULL , + ContentEncoding varchar(80) CHARACTER SET ascii NULL , + Content LONGBLOB NULL , + Headers LONGTEXT NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX Attachments2 ON Attachments (TransactionId) ; +CREATE INDEX Attachments3 ON Attachments (Parent, TransactionId) ; +# }}} + +# {{{ Queues +CREATE TABLE Queues ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NOT NULL , + Description varchar(255) NULL , + CorrespondAddress varchar(120) CHARACTER SET ascii NULL, + CommentAddress varchar(120) CHARACTER SET ascii NULL, + InitialPriority integer NOT NULL DEFAULT 0 , + FinalPriority integer NOT NULL DEFAULT 0 , + DefaultDueIn integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE UNIQUE INDEX Queues1 ON Queues (Name) ; +CREATE INDEX Queues2 ON Queues (Disabled) ; + +# }}} + +# {{{ Links + +CREATE TABLE Links ( + id INTEGER NOT NULL AUTO_INCREMENT, + Base varchar(240) NULL, + Target varchar(240) NULL, + Type varchar(20) NOT NULL, + LocalTarget integer NOT NULL DEFAULT 0 , + LocalBase integer NOT NULL DEFAULT 0 , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET ascii; + +CREATE INDEX Links2 ON Links (Base, Type) ; +CREATE INDEX Links3 ON Links (Target, Type) ; +CREATE INDEX Links4 ON Links (Type,LocalBase); + +# }}} + +# {{{ Principals + +CREATE TABLE Principals ( + id INTEGER AUTO_INCREMENT not null, + PrincipalType VARCHAR(16) not null, + ObjectId integer, # foreign key to Users or Groups, depending + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET ascii; + +CREATE INDEX Principals2 ON Principals (ObjectId); + +# }}} + +# {{{ Groups + +CREATE TABLE Groups ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + Domain varchar(64) CHARACTER SET ascii NULL, + Type varchar(64) CHARACTER SET ascii NULL, + Instance integer, + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX Groups1 ON Groups (Domain,Instance,Type,id); +CREATE INDEX Groups2 On Groups (Type, Instance); + +# }}} + +# {{{ ScripConditions + +CREATE TABLE ScripConditions ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + ExecModule varchar(60) CHARACTER SET ascii NULL, + Argument VARBINARY(255) NULL , + ApplicableTransTypes varchar(60) CHARACTER SET ascii NULL , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ Transactions +CREATE TABLE Transactions ( + id INTEGER NOT NULL AUTO_INCREMENT, + ObjectType varchar(64) CHARACTER SET ascii NOT NULL, + ObjectId integer NOT NULL DEFAULT 0 , + TimeTaken integer NOT NULL DEFAULT 0 , + Type varchar(20) CHARACTER SET ascii NULL, + Field varchar(40) CHARACTER SET ascii NULL, + OldValue varchar(255) NULL , + NewValue varchar(255) NULL , + ReferenceType varchar(255) CHARACTER SET ascii NULL, + OldReference integer NULL , + NewReference integer NULL , + Data varchar(255) NULL , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId); + +# }}} + +# {{{ Scrips + +CREATE TABLE Scrips ( + id INTEGER NOT NULL AUTO_INCREMENT, + Description varchar(255), + ScripCondition integer NOT NULL DEFAULT 0 , + ScripAction integer NOT NULL DEFAULT 0 , + ConditionRules text NULL , + ActionRules text NULL , + CustomIsApplicableCode text NULL , + CustomPrepareCode text NULL , + CustomCommitCode text NULL , + Stage varchar(32) CHARACTER SET ascii NULL , + Queue integer NOT NULL DEFAULT 0 , + Template integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ ACL +CREATE TABLE ACL ( + id INTEGER NOT NULL AUTO_INCREMENT, + PrincipalType varchar(25) CHARACTER SET ascii NOT NULL, #"User" "Group", "Owner", "Cc" "AdminCc", "Requestor" + + PrincipalId integer NOT NULL , #Foreign key to principals + RightName varchar(25) CHARACTER SET ascii NOT NULL, + ObjectType varchar(25) CHARACTER SET ascii NOT NULL, + ObjectId integer NOT NULL default 0, + DelegatedBy integer NOT NULL default 0, #foreign key to principals with a userid + DelegatedFrom integer NOT NULL default 0, #foreign key to ACL + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX ACL1 on ACL(RightName, ObjectType, ObjectId,PrincipalType,PrincipalId); + +# }}} + +# {{{ GroupMembers + +CREATE TABLE GroupMembers ( + id INTEGER NOT NULL AUTO_INCREMENT, + GroupId integer NOT NULL DEFAULT 0, + MemberId integer NOT NULL DEFAULT 0, #Foreign key to Principals + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; +CREATE UNIQUE INDEX GroupMembers1 on GroupMembers (GroupId, MemberId); + + +# }}} + +# {{{ GroupMembersCache + +create table CachedGroupMembers ( + id int auto_increment, + GroupId int, # foreign key to Principals + MemberId int, # foreign key to Principals + Via int, #foreign key to CachedGroupMembers. (may point to $self->id) + ImmediateParentId int, #foreign key to prinicpals. + # this points to the group that the member is + # a member of, for ease of deletes. + Disabled int2 NOT NULL DEFAULT 0 , # if this cached group member is a member of this group by way of a disabled + # group or this group is disabled, this will be set to 1 + # this allows us to not find members of disabled subgroups when listing off + # group members recursively. + # Also, this allows us to have the ACL system elide members of disabled groups + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX DisGrouMem on CachedGroupMembers (GroupId,MemberId,Disabled); +CREATE INDEX CachedGroupMembers3 on CachedGroupMembers (MemberId, ImmediateParentId); + +# }}} + +# {{{ Users + +CREATE TABLE Users ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NOT NULL , + Password VARBINARY(40) NULL , + Comments TEXT NULL , + Signature TEXT NULL , + EmailAddress varchar(120) NULL , + FreeformContactInfo TEXT NULL , + Organization varchar(200) NULL , + RealName varchar(120) NULL , + NickName varchar(16) NULL , + Lang varchar(16) NULL , + EmailEncoding varchar(16) NULL , + WebEncoding varchar(16) NULL , + ExternalContactInfoId varchar(100) NULL , + ContactInfoSystem varchar(30) NULL , + ExternalAuthId varchar(100) NULL , + AuthSystem varchar(30) NULL , + Gecos varchar(16) NULL , + HomePhone varchar(30) NULL , + WorkPhone varchar(30) NULL , + MobilePhone varchar(30) NULL , + PagerPhone varchar(30) NULL , + Address1 varchar(200) NULL , + Address2 varchar(200) NULL , + City varchar(100) NULL , + State varchar(100) NULL , + Zip varchar(16) NULL , + Country varchar(50) NULL , + Timezone varchar(50) NULL , + PGPKey text NULL, + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + + +CREATE UNIQUE INDEX Users1 ON Users (Name) ; +CREATE INDEX Users4 ON Users (EmailAddress); + + +# }}} + +# {{{ Tickets + +CREATE TABLE Tickets ( + id INTEGER NOT NULL AUTO_INCREMENT, + EffectiveId integer NOT NULL DEFAULT 0 , + Queue integer NOT NULL DEFAULT 0 , + Type varchar(16) CHARACTER SET ascii NULL , + IssueStatement integer NOT NULL DEFAULT 0 , + Resolution integer NOT NULL DEFAULT 0 , + Owner integer NOT NULL DEFAULT 0 , + Subject varchar(200) NULL DEFAULT '[no subject]' , + InitialPriority integer NOT NULL DEFAULT 0 , + FinalPriority integer NOT NULL DEFAULT 0 , + Priority integer NOT NULL DEFAULT 0 , + TimeEstimated integer NOT NULL DEFAULT 0 , + TimeWorked integer NOT NULL DEFAULT 0 , + Status varchar(10) NULL , + TimeLeft integer NOT NULL DEFAULT 0 , + Told DATETIME NULL , + Starts DATETIME NULL , + Started DATETIME NULL , + Due DATETIME NULL , + Resolved DATETIME NULL , + + + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX Tickets1 ON Tickets (Queue, Status) ; +CREATE INDEX Tickets2 ON Tickets (Owner) ; +CREATE INDEX Tickets6 ON Tickets (EffectiveId, Type) ; + +# }}} + +# {{{ ScripActions + +CREATE TABLE ScripActions ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Description varchar(255) NULL , + ExecModule varchar(60) CHARACTER SET ascii NULL, + Argument VARBINARY(255) NULL , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ Templates + +CREATE TABLE Templates ( + id INTEGER NOT NULL AUTO_INCREMENT, + Queue integer NOT NULL DEFAULT 0 , + Name varchar(200) NOT NULL , + Description varchar(255) NULL , + Type varchar(16) CHARACTER SET ascii NULL , + Language varchar(16) CHARACTER SET ascii NULL , + TranslationOf integer NOT NULL DEFAULT 0 , + Content TEXT NULL , + LastUpdated DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ ObjectCustomFieldValues + +CREATE TABLE ObjectCustomFieldValues ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField int NOT NULL , + ObjectType varchar(255) CHARACTER SET ascii NOT NULL, # Final target of the Object + ObjectId int NOT NULL , # New -- Replaces Ticket + SortOrder integer NOT NULL DEFAULT 0 , # New -- ordering for multiple values + + Content varchar(255) NULL , + LargeContent LONGBLOB NULL, # New -- to hold 255+ strings + ContentType varchar(80) CHARACTER SET ascii NULL, # New -- only text/* gets searched + ContentEncoding varchar(80) CHARACTER SET ascii NULL , # New -- for binary Content + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , # New -- whether the value was current + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX ObjectCustomFieldValues1 ON ObjectCustomFieldValues (Content); +CREATE INDEX ObjectCustomFieldValues2 ON ObjectCustomFieldValues (CustomField,ObjectType,ObjectId); + +# }}} + +# {{{ CustomFields + +CREATE TABLE CustomFields ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(200) NULL , + Type varchar(200) CHARACTER SET ascii NULL , # Changed -- 'Single' and 'Multiple' is moved out + MaxValues integer, # New -- was 'Single'(1) and 'Multiple'(0) + Pattern TEXT NULL , # New -- Must validate against this + Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry + Description varchar(255) NULL , + SortOrder integer NOT NULL DEFAULT 0 , + LookupType varchar(255) CHARACTER SET ascii NOT NULL, + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + Disabled int2 NOT NULL DEFAULT 0 , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ ObjectCustomFields + +CREATE TABLE ObjectCustomFields ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField integer NOT NULL , + ObjectId integer NOT NULL, + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +# }}} + +# {{{ CustomFieldValues + +CREATE TABLE CustomFieldValues ( + id INTEGER NOT NULL AUTO_INCREMENT, + CustomField int NOT NULL , + Name varchar(200) NULL , + Description varchar(255) NULL , + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX CustomFieldValues1 ON CustomFieldValues (CustomField); + +# }}} + + +# {{{ Attributes + +CREATE TABLE Attributes ( + id INTEGER NOT NULL AUTO_INCREMENT, + Name varchar(255) NULL , + Description varchar(255) NULL , + Content BLOB, + ContentType varchar(16) CHARACTER SET ascii, + ObjectType varchar(64) CHARACTER SET ascii, + ObjectId integer, # foreign key to anything + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) TYPE=InnoDB CHARACTER SET utf8; + +CREATE INDEX Attributes1 on Attributes(Name); +CREATE INDEX Attributes2 on Attributes(ObjectType, ObjectId); + +# }}} + +# {{{ Sessions + +# sessions is used by Apache::Session to keep sessions in the database. +# We should have a reaper script somewhere. + +CREATE TABLE sessions ( + id char(32) NOT NULL, + a_session LONGBLOB, + LastUpdated TIMESTAMP, + PRIMARY KEY (id) +); + +# }}} diff --git a/rt/etc/upgrade/3.1.0/acl.Pg b/rt/etc/upgrade/3.1.0/acl.Pg index 809e99ab3..9c8878260 100755 --- a/rt/etc/upgrade/3.1.0/acl.Pg +++ b/rt/etc/upgrade/3.1.0/acl.Pg @@ -11,7 +11,7 @@ sub acl { foreach my $table (@tables) { push @acls, "GRANT SELECT, INSERT, UPDATE, DELETE ON $table to " - . $RT::DatabaseUser . ";"; + . RT->Config->Get('DatabaseUser') . ";"; } return (@acls); diff --git a/rt/etc/upgrade/3.3.0/acl.Pg b/rt/etc/upgrade/3.3.0/acl.Pg index 2069a198e..bd2e36c48 100644 --- a/rt/etc/upgrade/3.3.0/acl.Pg +++ b/rt/etc/upgrade/3.3.0/acl.Pg @@ -12,7 +12,7 @@ sub acl { foreach my $table (@tables) { push @acls, "GRANT SELECT, INSERT, UPDATE, DELETE ON $table to " - . $RT::DatabaseUser . ";"; + . RT->Config->Get('DatabaseUser') . ";"; } return (@acls); diff --git a/rt/etc/upgrade/3.5.1/content b/rt/etc/upgrade/3.5.1/content index e3898a7cc..02d6a0cac 100644 --- a/rt/etc/upgrade/3.5.1/content +++ b/rt/etc/upgrade/3.5.1/content @@ -2,7 +2,7 @@ { Name => 'Search - My Tickets', Description => '[_1] highest priority tickets I own', Content => - { Format => "'<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__id__</a>/TITLE:#', '<a href=\"__WebPath__/Ticket/Display.html?id=__id__\">__Subject__</a>/TITLE:Subject', Priority, QueueName, ExtendedStatus", + { Format => q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#', '<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject', Priority, QueueName, ExtendedStatus}, Query => " Owner = '__CurrentUser__' AND ( Status = 'new' OR Status = 'open')", OrderBy => 'Priority', Order => 'DESC' }, diff --git a/rt/etc/upgrade/3.7.1/content b/rt/etc/upgrade/3.7.1/content new file mode 100644 index 000000000..fdd506144 --- /dev/null +++ b/rt/etc/upgrade/3.7.1/content @@ -0,0 +1,14 @@ +@ScripConditions = ( + { Name => 'On Close', # loc + Description => 'Whenever a ticket is closed', # loc + ApplicableTransTypes => 'Status,Set', + ExecModule => 'CloseTicket', + }, + { Name => 'On Reopen', # loc + Description => 'Whenever a ticket is reopened', # loc + ApplicableTransTypes => 'Status,Set', + ExecModule => 'ReopenTicket', + }, +); + + diff --git a/rt/etc/upgrade/3.7.10/content b/rt/etc/upgrade/3.7.10/content new file mode 100644 index 000000000..d19f9e6fa --- /dev/null +++ b/rt/etc/upgrade/3.7.10/content @@ -0,0 +1,49 @@ + +@Templates = ( + { Queue => 0, + Name => "Error: public key", # loc + Description => + "Inform user that he has problems with public key and couldn't recieve encrypted content", # loc + Content => q{Subject: We have no your public key or it's wrong + +You received this message as we have no your public PGP key or we have a problem with your key. Inform the administrator about the problem. +} + }, + { Queue => 0, + Name => "Error to RT owner: public key", # loc + Description => + "Inform RT owner that user(s) have problems with public keys", # loc + Content => q{Subject: Some users have problems with public keys + +You received this message as RT has problems with public keys of the following user: +{ + foreach my $e ( @BadRecipients ) { + $OUT .= "* ". $e->{'Message'} ."\n"; + } +}} + }, + { Queue => 0, + Name => "Error: no private key", # loc + Description => + "Inform user that we received an encrypted email and we have no private keys to decrypt", # loc + Content => q{Subject: we received message we cannot decrypt + +You sent an encrypted message with subject '{ $Message->head->get('Subject') }', +but we have no private key it's encrypted to. + +Please, check that you encrypt messages with correct keys +or contact the system administrator.} + }, + { Queue => 0, + Name => "Error: bad GnuPG data", # loc + Description => + "Inform user that a message he sent has invalid GnuPG data", # loc + Content => q{Subject: We received a message we cannot handle + +You sent us a message that we cannot handle due to corrupted GnuPG signature or encrypted block. we get the following error(s): +{ foreach my $msg ( @Messages ) { + $OUT .= "* $msg\n"; + } +}} + }, +); diff --git a/rt/etc/upgrade/3.7.15/content b/rt/etc/upgrade/3.7.15/content new file mode 100644 index 000000000..9d97c356c --- /dev/null +++ b/rt/etc/upgrade/3.7.15/content @@ -0,0 +1,12 @@ + +@Templates = ( + { Queue => 0, + Name => "Forward", # loc + Description => "Heading of a forwarded message", # loc + Content => q{ + +This is forward of transaction #{ $Transaction->id } of a ticket #{ $Ticket->id } +} + }, +); + diff --git a/rt/etc/upgrade/3.7.19/content b/rt/etc/upgrade/3.7.19/content new file mode 100644 index 000000000..ac34ebeb5 --- /dev/null +++ b/rt/etc/upgrade/3.7.19/content @@ -0,0 +1,37 @@ + +{ use strict; +add_description_to_all_scrips(); + +sub add_description_to_all_scrips { + require RT::Scrips; + my $scrips = RT::Scrips->new( $RT::SystemUser ); + $scrips->Limit( FIELD => 'Description', OPERATOR => 'IS', VALUE => 'NULL' ); + $scrips->Limit( FIELD => 'Description', VALUE => '' ); + while ( my $scrip = $scrips->Next ) { + my $desc = $scrip->Description; + next if defined $desc && length $desc; + + $desc = gen_scrip_description( $scrip ); + + my ($status, $msg) = $scrip->SetDescription( $desc ); + unless ( $status ) { + print STDERR "Couldn't set description of a scrip: $msg"; + } else { + print "Added description to scrip #". $scrip->id ."\n"; + } + } +} + +sub gen_scrip_description { + my $scrip = shift; + my $condition = $scrip->ConditionObj->Name + || $scrip->ConditionObj->Description + || ('On Condition #'. $scrip->Condition); + my $action = $scrip->ActionObj->Name + || $scrip->ActionObj->Description + || ('Run Action #'. $scrip->Action); + return join ' ', $condition, $action; +} +} + +1; diff --git a/rt/etc/upgrade/3.7.3/schema.Oracle b/rt/etc/upgrade/3.7.3/schema.Oracle new file mode 100644 index 000000000..6136efae7 --- /dev/null +++ b/rt/etc/upgrade/3.7.3/schema.Oracle @@ -0,0 +1,5 @@ +alter table CustomFields add Pattern_TMP clob; +update CustomFields set Pattern_TMP = Pattern; +commit; +alter table CustomFields drop column Pattern; +alter table CustomFields rename column Pattern_TMP to Pattern; diff --git a/rt/etc/upgrade/3.7.3/schema.Pg b/rt/etc/upgrade/3.7.3/schema.Pg new file mode 100644 index 000000000..5d0312e92 --- /dev/null +++ b/rt/etc/upgrade/3.7.3/schema.Pg @@ -0,0 +1 @@ +ALTER TABLE customfields ALTER COLUMN pattern TYPE VARCHAR(65536); diff --git a/rt/etc/upgrade/3.7.3/schema.mysql b/rt/etc/upgrade/3.7.3/schema.mysql new file mode 100644 index 000000000..51c376d81 --- /dev/null +++ b/rt/etc/upgrade/3.7.3/schema.mysql @@ -0,0 +1 @@ +ALTER TABLE CustomFields CHANGE Pattern Pattern TEXT NULL; diff --git a/rt/etc/upgrade/3.7.81/schema.Oracle b/rt/etc/upgrade/3.7.81/schema.Oracle new file mode 100644 index 000000000..02da4ece9 --- /dev/null +++ b/rt/etc/upgrade/3.7.81/schema.Oracle @@ -0,0 +1,2 @@ +CREATE INDEX CachedGroupMembers3 on CachedGroupMembers (MemberId, ImmediateParentId); + diff --git a/rt/etc/upgrade/3.7.81/schema.mysql b/rt/etc/upgrade/3.7.81/schema.mysql new file mode 100644 index 000000000..02da4ece9 --- /dev/null +++ b/rt/etc/upgrade/3.7.81/schema.mysql @@ -0,0 +1,2 @@ +CREATE INDEX CachedGroupMembers3 on CachedGroupMembers (MemberId, ImmediateParentId); + diff --git a/rt/etc/upgrade/3.7.82/content b/rt/etc/upgrade/3.7.82/content new file mode 100644 index 000000000..a1c555f78 --- /dev/null +++ b/rt/etc/upgrade/3.7.82/content @@ -0,0 +1,13 @@ +@Attributes = ( + { Name => 'Search - Bookmarked Tickets', + Description => 'Bookmarked Tickets', #loc + Content => + { Format => q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',} + . q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',} + . q{Priority, QueueName, ExtendedStatus, Bookmark}, + Query => "__Bookmarks__", + OrderBy => 'LastUpdated', + Order => 'DESC' }, + }, +); + diff --git a/rt/etc/upgrade/3.7.85/content b/rt/etc/upgrade/3.7.85/content new file mode 100644 index 000000000..49ab2860f --- /dev/null +++ b/rt/etc/upgrade/3.7.85/content @@ -0,0 +1,11 @@ +@Templates = ( + + { Queue => '0', + Name => 'Email Digest', # loc + Description => 'Email template for periodic notification digests', # loc + Content => q[Subject: RT Email Digest + +{ $Argument } +], + }, +); diff --git a/rt/etc/upgrade/3.7.86/content b/rt/etc/upgrade/3.7.86/content new file mode 100644 index 000000000..da087ed75 --- /dev/null +++ b/rt/etc/upgrade/3.7.86/content @@ -0,0 +1,23 @@ +@Final = ( + sub { + $RT::Logger->debug("Adding search for bookmarked tickets to defaults"); + my $sys = RT::System->new($RT::SystemUser); + + my $attrs = RT::Attributes->new( $RT::SystemUser ); + $attrs->LimitToObject( $sys ); + my ($attr) = $attrs->Named( 'HomepageSettings' ); + unless ($attr) { + $RT::Logger->error("You have no global home page settings"); + return; + } + my $content = $attr->Content; + unshift @{ $content->{'body'} ||= [] }, + { type => 'system', name => 'Bookmarked Tickets' }; + + my ($status, $msg) = $attr->SetContent( $content ); + $RT::Logger->error($msg) unless $status; + + $RT::Logger->debug("done."); + return 1; + }, +); diff --git a/rt/etc/upgrade/3.7.87/content b/rt/etc/upgrade/3.7.87/content new file mode 100644 index 000000000..0c677c4a1 --- /dev/null +++ b/rt/etc/upgrade/3.7.87/content @@ -0,0 +1,28 @@ +@Templates = ( +{ + Queue => 0, + Name => "Error: Missing dashboard", # loc + Description => + "Inform user that a dashboard he subscribed to is missing", # loc + Content => q{Subject: [{RT->Config->Get('rtname')}] Missing dashboard! + +Greetings, + +You are subscribed to a dashboard that is currently missing. Most likely, the dashboard was deleted. + +RT will remove this subscription as it is no longer useful. Here's the information RT had about your subscription: + +DashboardID: { $SubscriptionObj->SubValue('DashboardId') } +Frequency: { $SubscriptionObj->SubValue('Frequency') } +Hour: { $SubscriptionObj->SubValue('Hour') } +{ + $SubscriptionObj->SubValue('Frequency') eq 'weekly' + ? "Day of week: " . $SubscriptionObj->SubValue('Dow') + : $SubscriptionObj->SubValue('Frequency') eq 'monthly' + ? "Day of month: " . $SubscriptionObj->SubValue('Dom') + : '' +} +} +}, +); + diff --git a/rt/etc/upgrade/3.8-branded-queues-extension b/rt/etc/upgrade/3.8-branded-queues-extension new file mode 100755 index 000000000..6a0ea48b6 --- /dev/null +++ b/rt/etc/upgrade/3.8-branded-queues-extension @@ -0,0 +1,95 @@ +#!/usr/bin/perl +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "local/lib"; +use lib "lib"; + + +use RT; +RT::LoadConfig(); +RT::Init(); + +use RT::Queues; + +my $queues = RT::Queues->new( $RT::SystemUser ); +$queues->UnLimit(); +while ( my $queue = $queues->Next ) { + print "Processing queue ". ($queue->Name || $queue->id) ."...\n"; + my $old_attr = $queue->FirstAttribute('BrandedSubjectTag'); + unless ( $old_attr ) { + print "\thas no old-style subject tag. skipping\n"; + next; + } + my $old_value = $old_attr->Content; + unless ( $old_value ) { + print "\thas empty old-style subject tag\n"; + } else { + my ($status, $msg) = $queue->SetSubjectTag( $old_value ); + unless ( $status ) { + print STDERR "\tERROR. Couldn't set tag: $msg\n"; + next; + } else { + print "\thave set new-style subject tag to '$old_value'\n"; + } + } + + my ($status, $msg) = $queue->DeleteAttribute('BrandedSubjectTag'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't delete old-style tag: $msg\n"; + next; + } else { + print "\tdeleted old-style tag entry\n"; + } + print "\tDONE\n"; +} + +exit 0; + diff --git a/rt/etc/upgrade/3.8-branded-queues-extension.in b/rt/etc/upgrade/3.8-branded-queues-extension.in new file mode 100755 index 000000000..2f07d6e60 --- /dev/null +++ b/rt/etc/upgrade/3.8-branded-queues-extension.in @@ -0,0 +1,95 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + + +use RT; +RT::LoadConfig(); +RT::Init(); + +use RT::Queues; + +my $queues = RT::Queues->new( $RT::SystemUser ); +$queues->UnLimit(); +while ( my $queue = $queues->Next ) { + print "Processing queue ". ($queue->Name || $queue->id) ."...\n"; + my $old_attr = $queue->FirstAttribute('BrandedSubjectTag'); + unless ( $old_attr ) { + print "\thas no old-style subject tag. skipping\n"; + next; + } + my $old_value = $old_attr->Content; + unless ( $old_value ) { + print "\thas empty old-style subject tag\n"; + } else { + my ($status, $msg) = $queue->SetSubjectTag( $old_value ); + unless ( $status ) { + print STDERR "\tERROR. Couldn't set tag: $msg\n"; + next; + } else { + print "\thave set new-style subject tag to '$old_value'\n"; + } + } + + my ($status, $msg) = $queue->DeleteAttribute('BrandedSubjectTag'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't delete old-style tag: $msg\n"; + next; + } else { + print "\tdeleted old-style tag entry\n"; + } + print "\tDONE\n"; +} + +exit 0; + diff --git a/rt/etc/upgrade/3.8-ical-extension b/rt/etc/upgrade/3.8-ical-extension new file mode 100755 index 000000000..9561b9735 --- /dev/null +++ b/rt/etc/upgrade/3.8-ical-extension @@ -0,0 +1,96 @@ +#!/usr/bin/perl +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "local/lib"; +use lib "lib"; + + +use RT; +RT::LoadConfig(); +RT::Init(); + +use RT::Attributes; +my $attrs = RT::Attributes->new( $RT::SystemUser ); +$attrs->Limit(FIELD => 'ObjectType', OPERATOR=> '=', VALUE => 'RT::User'); +$attrs->Limit(FIELD => 'Name', OPERATOR=> '=', VALUE => 'ical-auth-token'); +while ( my $attr = $attrs->Next ) { + my $uid = $attr->ObjectId; + print "Processing auth token of user #". $uid ."...\n"; + + my $user = RT::User->new( $RT::SystemUser ); + $user->Load( $uid ); + unless ( $user->id ) { + print STDERR "\tERROR. Couldn't load user record\n"; + next; + } + + my ($status, $msg); + + ($status, $msg) = $user->DeleteAttribute('AuthToken') + if $user->FirstAttribute('AuthToken'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't delete duplicated attribute: $msg\n"; + next; + } else { + print "\tdeleted duplicate attribute\n"; + } + + ($status, $msg) = $attr->SetName('AuthToken'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't rename attribute: $msg\n"; + next; + } else { + print "\trenamed attribute\n"; + } + print "\tDONE\n"; +} + +exit 0; diff --git a/rt/etc/upgrade/3.8-ical-extension.in b/rt/etc/upgrade/3.8-ical-extension.in new file mode 100644 index 000000000..510419c5a --- /dev/null +++ b/rt/etc/upgrade/3.8-ical-extension.in @@ -0,0 +1,96 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + + +use RT; +RT::LoadConfig(); +RT::Init(); + +use RT::Attributes; +my $attrs = RT::Attributes->new( $RT::SystemUser ); +$attrs->Limit(FIELD => 'ObjectType', OPERATOR=> '=', VALUE => 'RT::User'); +$attrs->Limit(FIELD => 'Name', OPERATOR=> '=', VALUE => 'ical-auth-token'); +while ( my $attr = $attrs->Next ) { + my $uid = $attr->ObjectId; + print "Processing auth token of user #". $uid ."...\n"; + + my $user = RT::User->new( $RT::SystemUser ); + $user->Load( $uid ); + unless ( $user->id ) { + print STDERR "\tERROR. Couldn't load user record\n"; + next; + } + + my ($status, $msg); + + ($status, $msg) = $user->DeleteAttribute('AuthToken') + if $user->FirstAttribute('AuthToken'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't delete duplicated attribute: $msg\n"; + next; + } else { + print "\tdeleted duplicate attribute\n"; + } + + ($status, $msg) = $attr->SetName('AuthToken'); + unless ( $status ) { + print STDERR "\tERROR. Couldn't rename attribute: $msg\n"; + next; + } else { + print "\trenamed attribute\n"; + } + print "\tDONE\n"; +} + +exit 0; diff --git a/rt/etc/upgrade/3.8.0/content b/rt/etc/upgrade/3.8.0/content new file mode 100644 index 000000000..f4e389b90 --- /dev/null +++ b/rt/etc/upgrade/3.8.0/content @@ -0,0 +1,22 @@ +@Final = ( + # by incident we've changed 'My Bookmarks' to 'Bookmarked Tickets' when + # 3.7.82 upgrade script still was creating 'My Bookmarks', try to fix it + sub { + $RT::Logger->debug("Going to rename 'My Bookmarks' to 'Bookmarked Tickets'"); + my $sys = RT::System->new($RT::SystemUser); + + my $attrs = RT::Attributes->new( $RT::SystemUser ); + $attrs->LimitToObject( $sys ); + my ($attr) = $attrs->Named( 'Search - My Bookmarks' ); + unless ($attr) { + $RT::Logger->debug("You have no global search 'My Bookmarks'. Skipped."); + return 1; + } + my ($status, $msg) = $attr->SetName( 'Search - Bookmarked Tickets' ); + $RT::Logger->error($msg) and return undef unless $status; + + $RT::Logger->debug("Renamed."); + return 1; + }, +); + diff --git a/rt/etc/upgrade/3.8.1/content b/rt/etc/upgrade/3.8.1/content new file mode 100644 index 000000000..89db596ec --- /dev/null +++ b/rt/etc/upgrade/3.8.1/content @@ -0,0 +1,24 @@ +@Final = ( + sub { + $RT::Logger->debug("Going to adjust 'Bookmarked Tickets'"); + my $sys = RT::System->new($RT::SystemUser); + + my $attrs = RT::Attributes->new( $RT::SystemUser ); + $attrs->LimitToObject( $sys ); + my ($attr) = $attrs->Named( 'Search - Bookmarked Tickets' ); + unless ($attr) { + $RT::Logger->debug("You have no global search 'Bookmarked Tickets'. Skipped."); + return 1; + } + my $props = $attr->Content; + $props->{'Query'} =~ s/__Bookmarks__/id = '__Bookmarked__'/g; + + my ($status, $msg) = $attr->SetContent( $props ); + $RT::Logger->error($msg) and return undef unless $status; + + $RT::Logger->debug("Fixed."); + return 1; + }, +); + + diff --git a/rt/etc/upgrade/3.8.2/content b/rt/etc/upgrade/3.8.2/content new file mode 100644 index 000000000..9bd92be21 --- /dev/null +++ b/rt/etc/upgrade/3.8.2/content @@ -0,0 +1,186 @@ +@Initial = ( + sub { + $RT::Logger->warning( + "Going to add [OLD] prefix to all temlates in approvals queue." + ." If you never used approvals then you can delete all these" + ." templates with [OLD] prefix. Leave new there may be you will" + ." want to use approvals some time." + ); + + my $approvals_q = RT::Queue->new( $RT::SystemUser ); + $approvals_q->Load('___Approvals'); + unless ( $approvals_q->id ) { + $RT::Logger->error("You have no approvals queue."); + return 1; + } + + my $templates = RT::Templates->new( $RT::SystemUser ); + $templates->LimitToQueue( $approvals_q->id ); + while ( my $tmpl = $templates->Next ) { + my ($status, $msg) = $tmpl->SetName( "[OLD] ". $tmpl->Name ); + unless ( $status ) { + $RT::Logger->error("Couldn't rename template #". $tmpl->id .": $msg"); + } + } + return 1; + }, +); +@ACL = ( + { GroupDomain => 'SystemInternal', + GroupType => 'privileged', + Right => 'ShowApprovalsTab', }, +); + +@Templates = ( + { Queue => '___Approvals', + Name => "New Pending Approval", # loc + Description => + "Notify Owners and AdminCcs of new items pending their approval", # loc + Content => 'Subject: New Pending Approval: {$Ticket->Subject} + +Greetings, + +There is a new item pending your approval: "{$Ticket->Subject()}", +a summary of which appears below. + +Please visit {RT->Config->Get(\'WebURL\')}Approvals/Display.html?id={$Ticket->id} +to approve or reject this ticket, or {RT->Config->Get(\'WebURL\')}Approvals/ to +batch-process all your pending approvals. + +------------------------------------------------------------------------- +{$Transaction->Content()} +' + }, + { Queue => '___Approvals', + Name => "Approval Passed", # loc + Description => + "Notify Requestor of their ticket has been approved by some approver", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} + +Greetings, + +Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }. +Other approvals may be pending. + +Approver\'s notes: { $Notes } +' + }, + { Queue => '___Approvals', + Name => "All Approvals Passed", # loc + Description => + "Notify Requestor of their ticket has been approved by all approvers", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} + +Greetings, + +Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }. +Its Owner may now start to act on it. + +Approver\'s notes: { $Notes } +' + }, + { Queue => '___Approvals', + Name => "Approval Rejected", # loc + Description => + "Notify Owner of their rejected ticket", # loc + Content => 'Subject: Ticket Rejected: {$Ticket->Subject} + +Greetings, + +Your ticket has been rejected by { eval { $Approval->OwnerObj->Name } }. + +Approver\'s notes: { $Notes } +' + }, + { Queue => '___Approvals', + Name => "Approval Ready for Owner", # loc + Description => + "Notify Owner of their ticket has been approved and is ready to be acted on", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} + +Greetings, + +The ticket has been approved, you may now start to act on it. + +' + }, +); + +@Final = ( + sub { + $RT::Logger->debug("Going to adjust dashboards"); + my $sys = RT::System->new($RT::SystemUser); + + my $attrs = RT::Attributes->new( $RT::SystemUser ); + $attrs->UnLimit; + my @dashboards = $attrs->Named('Dashboard'); + + if (@dashboards == 0) { + $RT::Logger->debug("You have no dashboards. Skipped."); + return 1; + } + + for my $attr (@dashboards) { + my $props = $attr->Content; + if (exists $props->{Searches}) { + $props->{Panes} = { + body => [ + map { + my ($privacy, $id, $desc) = @$_; + + { + portlet_type => 'search', + privacy => $privacy, + id => $id, + description => $desc, + pane => 'body', + } + } @{ delete $props->{Searches} } + ], + }; + } + my ($status, $msg) = $attr->SetContent( $props ); + $RT::Logger->error($msg) unless $status; + } + + $RT::Logger->debug("Fixed."); + return 1; + }, + sub { + my $approvals_q = RT::Queue->new( $RT::SystemUser ); + $approvals_q->Load('___Approvals'); + unless ( $approvals_q->id ) { + $RT::Logger->error("You have no approvals queue."); + return 1; + } + + require File::Temp; + my ($tmp_fh, $tmp_fn) = File::Temp::tempfile( 'rt-approvals-scrips-XXXX', CLEANUP => 0 ); + unless ( $tmp_fh ) { + $RT::Logger->error("Couldn't create temporary file."); + return 0; + } + + $RT::Logger->warning( + "IMPORTANT: We're going to delete all scrips in Approvals queue" + ." and save them in '$tmp_fn' file." + ); + + require Data::Dumper; + + my $scrips = RT::Scrips->new( $RT::SystemUser ); + $scrips->LimitToQueue( $approvals_q->id ); + while ( my $scrip = $scrips->Next ) { + my %tmp = + map { $tmp->{ $_ } = $scrip->_Value( $_ ) } + $scrip->ReadableAttributes; + + print $tmp_fh Data::Dumper::Dumper( \%tmp ); + + my ($status, $msg) = $scrip->Delete; + unless ( $status ) { + $RT::Logger->error( "Couldn't delete scrip: $msg"); + } + } + }, +); diff --git a/rt/etc/upgrade/3.8.3/content b/rt/etc/upgrade/3.8.3/content new file mode 100644 index 000000000..8538e4287 --- /dev/null +++ b/rt/etc/upgrade/3.8.3/content @@ -0,0 +1,91 @@ +@ScripConditions = ( + { Name => 'On Reject', # loc + Description => 'Whenever a ticket is rejected', # loc + ApplicableTransTypes => 'Status', + ExecModule => 'StatusChange', + Argument => 'rejected' + + }, +); + +@Final = ( + sub { + $RT::Logger->debug("Going to correct descriptions of notify actions in the DB"); + + my $actions = RT::ScripActions->new( $RT::SystemUser ); + $actions->Limit( + FIELD => 'ExecModule', + VALUE => 'Notify', + ); + $actions->Limit( + FIELD => 'Argument', + VALUE => 'All', + ); + while ( my $action = $actions->Next ) { + my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs' ); + $RT::Logger->warning( "Couldn't change action name: $msg" ) + unless $status; + + ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers' ); + $RT::Logger->warning( "Couldn't change action description: $msg" ) + unless $status; + } + + $actions = RT::ScripActions->new( $RT::SystemUser ); + $actions->Limit( + FIELD => 'ExecModule', + VALUE => 'NotifyAsComment', + ); + $actions->Limit( + FIELD => 'Argument', + VALUE => 'All', + ); + while ( my $action = $actions->Next ) { + my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs as Comment' ); + $RT::Logger->warning( "Couldn't change action name: $msg" ) + unless $status; + + ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers as a "comment"' ); + $RT::Logger->warning( "Couldn't change action description: $msg" ) + unless $status; + } + + $RT::Logger->debug("Corrected descriptions of notify actions in the DB."); + return 1; + }, +); + + +{ +$RT::Logger->debug("Going to add in Extract Subject Tag actions if they were missed during a previous upgrade"); + +$actions = RT::ScripActions->new( $RT::SystemUser ); +$actions->Limit( + FIELD => 'ExecModule', + VALUE => 'ExtractSubjectTag', +); +my $extract_action = $actions->First; + +if ( $extract_action && $extract_action->Id ) { + $RT::Logger->debug("You appear to already have an Extract Subject Tag action, skipping"); + return 1; +} else { + $RT::Logger->debug("Didn't find an existing Extract Subject Tag action, adding it"); + push @ScripActions, ( + { Name => 'Extract Subject Tag', # loc + Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc + ExecModule => 'ExtractSubjectTag' + }, + ); + + $RT::Logger->debug("Adding Extract Subject Tag Scrip"); + push @Scrips, ( + { Description => "On transaction, add any tags in the transaction's subject to the ticket's subject", + ScripCondition => 'On Transaction', + ScripAction => 'Extract Subject Tag', + Template => 'Blank' + }, + ); +} +} + diff --git a/rt/etc/upgrade/3.8.3/schema.Pg b/rt/etc/upgrade/3.8.3/schema.Pg new file mode 100644 index 000000000..bbe55365d --- /dev/null +++ b/rt/etc/upgrade/3.8.3/schema.Pg @@ -0,0 +1,3 @@ + +CREATE UNIQUE INDEX GroupMembers1 ON GroupMembers(GroupId, MemberId); + diff --git a/rt/etc/upgrade/3.8.4/content b/rt/etc/upgrade/3.8.4/content new file mode 100644 index 000000000..be5a6bf39 --- /dev/null +++ b/rt/etc/upgrade/3.8.4/content @@ -0,0 +1,59 @@ + +@Final = ( + sub { + $RT::Logger->debug("Going to correct arguments of NotifyGroup actions if you have any"); + use strict; + + my $actions = RT::ScripActions->new( $RT::SystemUser ); + $actions->Limit( + FIELD => 'ExecModule', + VALUE => 'NotifyGroup', + ); + $actions->Limit( + FIELD => 'ExecModule', + VALUE => 'NotifyGroupAsComment', + ); + + my $converter = sub { + my $arg = shift; + my @res; + foreach my $r ( @{ $arg } ) { + my $obj; + next unless $r->{'Type'}; + if( lc $r->{'Type'} eq 'user' ) { + $obj = RT::User->new( $RT::SystemUser ); + } elsif ( lc $r->{'Type'} eq 'group' ) { + $obj = RT::Group->new( $RT::SystemUser ); + } else { + next; + } + $obj->Load( $r->{'Instance'} ); + my $id = $obj->id; + next unless( $id ); + + push @res, $id; + } + + return join ',', @res; + }; + + require Storable; + while ( my $action = $actions->Next ) { + my $argument = $action->Argument; + my $new = ''; + local $@; + if ( my $struct = eval { Storable::thaw( $argument ) } ) { + $new = $converter->( $struct ); + } else { + $new = join /, /, grep length, split /[^0-9]+/, $argument; + } + next if $new eq $argument; + + my ($status, $msg) = $action->__Set( Field => 'Argument', Value => $new ); + $RT::Logger->warning( "Couldn't change argument value of the action: $msg" ) + unless $status; + } + }, +); + + diff --git a/rt/etc/upgrade/3.8.6/content b/rt/etc/upgrade/3.8.6/content new file mode 100644 index 000000000..a9793c6e1 --- /dev/null +++ b/rt/etc/upgrade/3.8.6/content @@ -0,0 +1,10 @@ +@Templates = ( + { Queue => 0, + Name => "Forward Ticket", # loc + Description => "Heading of a forwarded Ticket", # loc + Content => q{ + +This is a forward of ticket #{ $Ticket->id } +} + }, +); diff --git a/rt/etc/upgrade/shrink_cgm_table.pl b/rt/etc/upgrade/shrink_cgm_table.pl new file mode 100644 index 000000000..3d153c709 --- /dev/null +++ b/rt/etc/upgrade/shrink_cgm_table.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +use 5.8.3; +use strict; +use warnings; + +use RT; +RT::LoadConfig(); +RT->Config->Set('LogToScreen' => 'debug'); +RT::Init(); + +use RT::CachedGroupMembers; +my $cgms = RT::CachedGroupMembers->new( $RT::SystemUser ); +$cgms->Limit( + FIELD => 'id', + OPERATOR => '!=', + VALUE => 'main.Via', + QUOTEVALUE => 0, + ENTRYAGGREGATOR => 'AND', +); +$cgms->FindAllRows; + +my $alias = $cgms->Join( + TYPE => 'LEFT', + FIELD1 => 'Via', + TABLE2 => 'CachedGroupMembers', + FIELD2 => 'id', +); +$cgms->Limit( + ALIAS => $alias, + FIELD => 'MemberId', + OPERATOR => '=', + VALUE => $alias .'.GroupId', + QUOTEVALUE => 0, + ENTRYAGGREGATOR => 'AND', +); +$cgms->Limit( + ALIAS => $alias, + FIELD => 'id', + OPERATOR => '=', + VALUE => $alias .'.Via', + QUOTEVALUE => 0, + ENTRYAGGREGATOR => 'AND', +); + +FetchNext( $cgms, 'init' ); +while ( my $rec = FetchNext( $cgms ) ) { + $RT::Handle->BeginTransaction; + my ($status) = $rec->Delete; + unless ($status) { + print STDERR "Couldn't delete CGM #". $rec->id; + exit 1; + } + $RT::Handle->Commit; +} + +use constant PAGE_SIZE => 1000; +sub FetchNext { + my ($objs, $init) = @_; + if ( $init ) { + $objs->RowsPerPage( PAGE_SIZE ); + $objs->FirstPage; + return; + } + + my $obj = $objs->Next; + return $obj if $obj; + $objs->RedoSearch; + $objs->FirstPage; + return $objs->Next; +} + diff --git a/rt/etc/upgrade/split-out-cf-categories b/rt/etc/upgrade/split-out-cf-categories new file mode 100755 index 000000000..d4077ce54 --- /dev/null +++ b/rt/etc/upgrade/split-out-cf-categories @@ -0,0 +1,171 @@ +#!/usr/bin/perl +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "local/lib"; +use lib "lib"; + +use RT; +RT::LoadConfig(); +RT->Config->Set('LogToScreen' => 'debug'); +RT::Init(); + +$| = 1; + +$RT::Handle->BeginTransaction(); + +use RT::CustomFields; +my $CFs = RT::CustomFields->new( $RT::SystemUser ); +$CFs->UnLimit; +$CFs->Limit( FIELD => 'Type', VALUE => 'Select' ); + +my $seen; +while (my $cf = $CFs->Next ) { + next if $cf->BasedOnObj->Id; + my @categories; + my %mapping; + my $values = $cf->Values; + while (my $value = $values->Next) { + next unless defined $value->Category and length $value->Category; + push @categories, $value->Category unless grep {$_ eq $value->Category} @categories; + $mapping{$value->Name} = $value->Category; + } + next unless @categories; + + $seen++; + print "Found CF '@{[$cf->Name]}' with categories:\n"; + print " $_\n" for @categories; + + print "Split this CF's categories into a hierarchical custom field (Y/n)? "; + my $dothis = <>; + next if $dothis =~ /n/i; + + print "Enter name of CF to create as category ('@{[$cf->Name]} category'): "; + my $newname = <>; + chomp $newname; + $newname = $cf->Name . " category" unless length $newname; + + # bump the CF's sort oder up by one + $cf->SetSortOrder( ($cf->SortOrder || 0) + 1 ); + + # ..and add a new CF before it + my $new = RT::CustomField->new( $RT::SystemUser ); + my ($id, $msg) = $new->Create( + Name => $newname, + Type => 'Select', + MaxValues => 1, + LookupType => $cf->LookupType, + SortOrder => $cf->SortOrder - 1, + ); + die "Can't create custom field '$newname': $msg" unless $id; + + # Set the CF to be based on what we just made + $cf->SetBasedOn( $new->Id ); + + # Apply it to all of the same things + { + my $ocfs = RT::ObjectCustomFields->new( $RT::SystemUser ); + $ocfs->LimitToCustomField( $cf->Id ); + while (my $ocf = $ocfs->Next) { + my $newocf = RT::ObjectCustomField->new( $RT::SystemUser ); + ($id, $msg) = $newocf->Create( + SortOrder => $ocf->SortOrder, + CustomField => $new->Id, + ObjectId => $ocf->ObjectId, + ); + die "Can't create ObjectCustomField: $msg" unless $id; + } + } + + # Copy over all of the rights + { + my $acl = RT::ACL->new( $RT::SystemUser ); + $acl->LimitToObject( $cf ); + while (my $ace = $acl->Next) { + my $newace = RT::ACE->new( $RT::SystemUser ); + ($id, $msg) = $newace->Create( + PrincipalId => $ace->PrincipalId, + PrincipalType => $ace->PrincipalType, + RightName => $ace->RightName, + Object => $new, + ); + die "Can't assign rights: $msg" unless $id; + } + } + + # Add values for all of the categories + for my $i (0..$#categories) { + ($id, $msg) = $new->AddValue( + Name => $categories[$i], + SortOrder => $i + 1, + ); + die "Can't create custom field value: $msg" unless $id; + } + + # Grovel through all ObjectCustomFieldValues, and add the + # appropriate category + { + my $ocfvs = RT::ObjectCustomFieldValues->new( $RT::SystemUser ); + $ocfvs->LimitToCustomField( $cf->Id ); + while (my $ocfv = $ocfvs->Next) { + next unless exists $mapping{$ocfv->Content}; + my $newocfv = RT::ObjectCustomFieldValue->new( $RT::SystemUser ); + ($id, $msg) = $newocfv->Create( + CustomField => $new->Id, + ObjectType => $ocfv->ObjectType, + ObjectId => $ocfv->ObjectId, + Content => $mapping{$ocfv->Content}, + ); + } + } +} + +$RT::Handle->Commit; +print "No custom fields with categories found\n" unless $seen; diff --git a/rt/etc/upgrade/split-out-cf-categories.in b/rt/etc/upgrade/split-out-cf-categories.in new file mode 100644 index 000000000..f34a1b616 --- /dev/null +++ b/rt/etc/upgrade/split-out-cf-categories.in @@ -0,0 +1,171 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC +# <jesse@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use strict; +use warnings; + +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + +use RT; +RT::LoadConfig(); +RT->Config->Set('LogToScreen' => 'debug'); +RT::Init(); + +$| = 1; + +$RT::Handle->BeginTransaction(); + +use RT::CustomFields; +my $CFs = RT::CustomFields->new( $RT::SystemUser ); +$CFs->UnLimit; +$CFs->Limit( FIELD => 'Type', VALUE => 'Select' ); + +my $seen; +while (my $cf = $CFs->Next ) { + next if $cf->BasedOnObj->Id; + my @categories; + my %mapping; + my $values = $cf->Values; + while (my $value = $values->Next) { + next unless defined $value->Category and length $value->Category; + push @categories, $value->Category unless grep {$_ eq $value->Category} @categories; + $mapping{$value->Name} = $value->Category; + } + next unless @categories; + + $seen++; + print "Found CF '@{[$cf->Name]}' with categories:\n"; + print " $_\n" for @categories; + + print "Split this CF's categories into a hierarchical custom field (Y/n)? "; + my $dothis = <>; + next if $dothis =~ /n/i; + + print "Enter name of CF to create as category ('@{[$cf->Name]} category'): "; + my $newname = <>; + chomp $newname; + $newname = $cf->Name . " category" unless length $newname; + + # bump the CF's sort oder up by one + $cf->SetSortOrder( ($cf->SortOrder || 0) + 1 ); + + # ..and add a new CF before it + my $new = RT::CustomField->new( $RT::SystemUser ); + my ($id, $msg) = $new->Create( + Name => $newname, + Type => 'Select', + MaxValues => 1, + LookupType => $cf->LookupType, + SortOrder => $cf->SortOrder - 1, + ); + die "Can't create custom field '$newname': $msg" unless $id; + + # Set the CF to be based on what we just made + $cf->SetBasedOn( $new->Id ); + + # Apply it to all of the same things + { + my $ocfs = RT::ObjectCustomFields->new( $RT::SystemUser ); + $ocfs->LimitToCustomField( $cf->Id ); + while (my $ocf = $ocfs->Next) { + my $newocf = RT::ObjectCustomField->new( $RT::SystemUser ); + ($id, $msg) = $newocf->Create( + SortOrder => $ocf->SortOrder, + CustomField => $new->Id, + ObjectId => $ocf->ObjectId, + ); + die "Can't create ObjectCustomField: $msg" unless $id; + } + } + + # Copy over all of the rights + { + my $acl = RT::ACL->new( $RT::SystemUser ); + $acl->LimitToObject( $cf ); + while (my $ace = $acl->Next) { + my $newace = RT::ACE->new( $RT::SystemUser ); + ($id, $msg) = $newace->Create( + PrincipalId => $ace->PrincipalId, + PrincipalType => $ace->PrincipalType, + RightName => $ace->RightName, + Object => $new, + ); + die "Can't assign rights: $msg" unless $id; + } + } + + # Add values for all of the categories + for my $i (0..$#categories) { + ($id, $msg) = $new->AddValue( + Name => $categories[$i], + SortOrder => $i + 1, + ); + die "Can't create custom field value: $msg" unless $id; + } + + # Grovel through all ObjectCustomFieldValues, and add the + # appropriate category + { + my $ocfvs = RT::ObjectCustomFieldValues->new( $RT::SystemUser ); + $ocfvs->LimitToCustomField( $cf->Id ); + while (my $ocfv = $ocfvs->Next) { + next unless exists $mapping{$ocfv->Content}; + my $newocfv = RT::ObjectCustomFieldValue->new( $RT::SystemUser ); + ($id, $msg) = $newocfv->Create( + CustomField => $new->Id, + ObjectType => $ocfv->ObjectType, + ObjectId => $ocfv->ObjectId, + Content => $mapping{$ocfv->Content}, + ); + } + } +} + +$RT::Handle->Commit; +print "No custom fields with categories found\n" unless $seen;
\ No newline at end of file diff --git a/rt/etc/upgrade/upgrade-mysql-schema.pl b/rt/etc/upgrade/upgrade-mysql-schema.pl new file mode 100755 index 000000000..bc59c97a1 --- /dev/null +++ b/rt/etc/upgrade/upgrade-mysql-schema.pl @@ -0,0 +1,390 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use DBI; +use DBD::mysql 4.002; + +unless (@ARGV) { + print STDERR "usage: $0 db_name[:server_name] db_user db_password\n"; + exit 1; +} + +# pretty correct support of charsets has been introduced in mysql 4.1 +# as RT doesn't use it may result in issues: +# 1) data corruptions when default charset of mysql server has data restrictions like utf8 +# 2) wrong ordering (collations) + +# we have to define correct types for all columns. RT uses UTF-8, ascii and binary. +# * ascii is subset of many mysql's charsets except may be one or two rare where some ascii +# characters replaced with local +# * for many charsets mysql allows us to store any octets sequences even when those are +# invalid for this particula set, for example we can store UTF-8 data in latin1 +# column and fetch it as UTF-8, however sorting will be wrong + +# here is tricky algorithm to change column to desired charset: +# * text to binary convertion is pretty straight forward except that text types +# have length definitions in terms of characters and in some cases we must +# use longer binary types to satisfy space requirements +# * binary to text is much easier as we know that there is ascii or UTF-8 then +# we just make convertion, also 32 chars are long enough to store 32 bytes, so +# length changes is not required +# * text to text convertion is trickier. no matter what is the current character set +# of the column we know that there is either ascii or UTF-8, so we can not use +# direct convertion, instead we do text to binary plus binary to text convertion +# instead +# * as well we add charset definition for all tables and for the DB as well, +# so all new columns by default will be in UTF-8 charset + +my @tables = qw( + ACL + Attachments + Attributes + CustomFields + CustomFieldValues + GroupMembers + Groups + Links + ObjectCustomFields + ObjectCustomFieldValues + Principals + Queues + ScripActions + ScripConditions + Scrips + sessions + Templates + Tickets + Transactions + Users +); + +my %charset = ( + ACL => { + RightName => 'ascii', + ObjectType => 'ascii', + PrincipalType => 'ascii', + }, + Attachments => { + MessageId => 'ascii', + Subject => 'utf8', + Filename => 'utf8', + ContentType => 'ascii', + ContentEncoding => 'ascii', + Content => 'binary', + Headers => 'utf8', + }, + Attributes => { + Name => 'utf8', + Description => 'utf8', + Content => 'binary', + ContentType => 'ascii', + ObjectType => 'ascii', + }, + CustomFields => { + Name => 'utf8', + Type => 'ascii', + Pattern => 'utf8', + Description => 'utf8', + LookupType => 'ascii', + }, + CustomFieldValues => { + Name => 'utf8', + Description => 'utf8', + }, + Groups => { + Name => 'utf8', + Description => 'utf8', + Domain => 'ascii', + Type => 'ascii', + }, + Links => { + Base => 'ascii', + Target => 'ascii', + Type => 'ascii', + }, + ObjectCustomFieldValues => { + ObjectType => 'ascii', + Content => 'utf8', + LargeContent => 'binary', + ContentType => 'ascii', + ContentEncoding => 'ascii', + }, + Principals => { + PrincipalType => 'ascii', + }, + Queues => { + Name => 'utf8', + Description => 'utf8', + CorrespondAddress => 'ascii', + CommentAddress => 'ascii', + }, + ScripActions => { + Name => 'utf8', + Description => 'utf8', + ExecModule => 'ascii', + Argument => 'binary', + }, + ScripConditions => { + Name => 'utf8', + Description => 'utf8', + ExecModule => 'ascii', + Argument => 'binary', + ApplicableTransTypes => 'ascii', + }, + Scrips => { + Description => 'utf8', + ConditionRules => 'utf8', + ActionRules => 'utf8', + CustomIsApplicableCode => 'utf8', + CustomPrepareCode => 'utf8', + CustomCommitCode => 'utf8', + Stage => 'ascii', + }, + sessions => { + id => 'binary', # ascii? + a_session => 'binary', + }, + Templates => { + Name => 'utf8', + Description => 'utf8', + Type => 'ascii', + Language => 'ascii', + Content => 'utf8', + }, + Tickets => { + Type => 'ascii', + Subject => 'utf8', + Status => 'ascii', + }, + Transactions => { + ObjectType => 'ascii', + Type => 'ascii', + Field => 'ascii', + OldValue => 'utf8', + NewValue => 'utf8', + ReferenceType => 'ascii', + Data => 'utf8', + }, + Users => { + Name => 'utf8', + Password => 'binary', + Comments => 'utf8', + Signature => 'utf8', + EmailAddress => 'ascii', + FreeformContactInfo => 'utf8', + Organization => 'utf8', + RealName => 'utf8', + NickName => 'utf8', + Lang => 'ascii', + EmailEncoding => 'ascii', + WebEncoding => 'ascii', + ExternalContactInfoId => 'utf8', + ContactInfoSystem => 'utf8', + ExternalAuthId => 'utf8', + AuthSystem => 'utf8', + Gecos => 'utf8', + HomePhone => 'utf8', + WorkPhone => 'utf8', + MobilePhone => 'utf8', + PagerPhone => 'utf8', + Address1 => 'utf8', + Address2 => 'utf8', + City => 'utf8', + State => 'utf8', + Zip => 'utf8', + Country => 'utf8', + Timezone => 'ascii', + PGPKey => 'binary', + }, +); + +my %max_type_length = ( + char => int 1<<8, + varchar => int 1<<8, + tinytext => int 1<<8, + mediumtext => int 1<<16, + text => int 1<<24, + longtext => int 1<<32, +); + +my @sql_commands; + +my ($db_datasource, $db_user, $db_pass) = (shift, shift, shift); +my $dbh = DBI->connect("dbi:mysql:$db_datasource", $db_user, $db_pass, { RaiseError => 1 }); +my $db_name = $db_datasource; +$db_name =~ s/:.*$//; + +my $version = ($dbh->selectrow_array("show variables like 'version'"))[1]; +($version) = $version =~ /^(\d+\.\d+)/; + +push @sql_commands, qq{ALTER DATABASE $db_name DEFAULT CHARACTER SET utf8}; +convert_table($_) foreach @tables; + +print join "\n", map(/;$/? $_ : "$_;", @sql_commands), ""; +my $use_p = $db_pass ? " -p" : ''; +print STDERR <<ENDREMINDER; +-- ** NOTICE: No database changes have been made. ** +-- Please review the generated SQL, ensure you have a full backup of your database +-- and apply it to your database using a command like: +-- mysql -u ${db_user}${use_p} $db_name < queries.sql"; +ENDREMINDER +exit 0; + +my %alter_aggregator; +sub convert_table { + my $table = shift; + @alter_aggregator{'char_to_binary','binary_to_char'} = (['DEFAULT CHARACTER SET utf8'],[]); + + my $sth = $dbh->column_info( undef, $db_name, $table, undef ); + $sth->execute; + while ( my $info = $sth->fetchrow_hashref ) { + convert_column(%$info); + } + for my $conversiontype (qw(char_to_binary binary_to_char)) { + next unless @{$alter_aggregator{$conversiontype}}; + push @sql_commands, qq{ALTER TABLE $table\n }. + join(",\n ",@{$alter_aggregator{$conversiontype}}); + } +} + +sub convert_column { + my %info = @_; + my $table = $info{'TABLE_NAME'}; + my $column = $info{'COLUMN_NAME'}; + my $type = $info{'TYPE_NAME'}; + return unless $type =~ /(CHAR|TEXT|BLOB|BINARY)$/i; + + my $required_charset = $charset{$table}{$column}; + unless ( $required_charset ) { + print STDERR join(".", @info{'TABLE_SCHEMA', 'TABLE_NAME', 'COLUMN_NAME'}) + ." has type $type however mapping is missing.\n"; + return; + } + + my $collation = column_info($table, $column)->{'collation'}; + # mysql 4.1 returns literal NULL instead of undef + my $current_charset = $collation && $collation ne 'NULL'? (split /_/, $collation)[0]: 'binary'; + return if $required_charset eq $current_charset; + + if ( $required_charset eq 'binary' ) { + char_to_binary(%info); + } + elsif ( $current_charset eq 'binary' ) { + binary_to_char( $required_charset, %info); + } else { + char_to_char( $required_charset, %info); + } +} + +sub char_to_binary { + my %info = @_; + + my $table = $info{'TABLE_NAME'}; + my $column = $info{'COLUMN_NAME'}; + my $new_type = calc_suitable_binary_type(%info); + push @{$alter_aggregator{char_to_binary}}, + "MODIFY $column $new_type ".build_column_definition(%info); + +} + +sub binary_to_char { + my ($charset, %info) = @_; + + my $table = $info{'TABLE_NAME'}; + my $column = $info{'COLUMN_NAME'}; + my $new_type = lc $info{'TYPE_NAME'}; + if ( $new_type =~ /binary/ ) { + $new_type =~ s/binary/char/; + $new_type .= '('. $info{'COLUMN_SIZE'} .')'; + } else { + $new_type =~ s/blob/text/; + } + + push @{$alter_aggregator{binary_to_char}}, + "MODIFY $column ". uc($new_type) ." CHARACTER SET ". $charset + ." ". build_column_definition(%info); +} + +sub char_to_char { + my ($charset, %info) = @_; + + my $table = $info{'TABLE_NAME'}; + my $column = $info{'COLUMN_NAME'}; + my $new_type = $info{'mysql_type_name'}; + + char_to_binary(%info); + push @{$alter_aggregator{binary_to_char}}, + "MODIFY $column ". uc($new_type)." CHARACTER SET ". $charset + ." ". build_column_definition(%info); +} + +sub calc_suitable_binary_type { + my %info = @_; + my $type = lc $info{'TYPE_NAME'}; + return 'LONGBLOB' if $type eq 'longtext'; + + my $current_max_byte_length = column_byte_length(@info{qw(TABLE_NAME COLUMN_NAME)}) || 0; + if ( $max_type_length{ $type } > $current_max_byte_length ) { + if ( $type eq 'varchar' || $type eq 'char' ) { + my $new_type = $type; + $new_type =~ s/char/binary/; + $new_type .= $info{'COLUMN_SIZE'} >= $current_max_byte_length + ? '('. $info{'COLUMN_SIZE'} .')' + : '('. $current_max_byte_length .')'; + return uc $new_type; + } else { + my $new_type = $type; + $new_type =~ s/text/blob/; + return uc $new_type; + } + } else { + my $new_type; + foreach ( sort { $max_type_length{$a} <=> $max_type_length{$b} } keys %max_type_length ) { + next if $max_type_length{ $_ } <= $current_max_byte_length; + + $new_type = $_; last; + } + $new_type =~ s/text/blob/; + return uc $new_type; + } +} + +sub build_column_definition { + my %info = @_; + + my $res = ''; + $res .= 'NOT ' unless $info{'NULLABLE'}; + $res .= 'NULL'; + my $default = column_info(@info{qw(TABLE_NAME COLUMN_NAME)})->{default}; + if ( defined $default ) { + $res .= ' DEFAULT '. $dbh->quote($default); + } elsif ( $info{'NULLABLE'} ) { + $res .= ' DEFAULT NULL'; + } + $res .= ' AUTO_INCREMENT' if $info{'mysql_is_auto_increment'}; + return $res; +} + +sub column_byte_length { + my ($table, $column) = @_; + if ( $version >= 5.0 ) { + my ($char, $octet) = @{ $dbh->selectrow_arrayref( + "SELECT CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH FROM information_schema.COLUMNS WHERE" + ." TABLE_SCHEMA = ". $dbh->quote($db_name) + ." AND TABLE_NAME = ". $dbh->quote($table) + ." AND COLUMN_NAME = ". $dbh->quote($column) + ) }; + return $octet if $octet == $char; + } + return $dbh->selectrow_arrayref("SELECT MAX(LENGTH(". $dbh->quote_identifier($column) .")) FROM $table")->[0]; +} + +sub column_info { + my ($table, $column) = @_; + # XXX: DBD::mysql doesn't provide this info, may be will do in 4.0007 if I'll write a patch + local $dbh->{FetchHashKeyName} = 'NAME_lc'; + return $dbh->selectrow_hashref("SHOW FULL COLUMNS FROM $table LIKE " . $dbh->quote($column)); +} + |