[Rt-commit] rt branch, hierarchical-cf, updated. addb5821719c29056fd95b05b6ff0ca27774580e

Alex M Vandiver alexmv at bestpractical.com
Wed Aug 26 18:20:18 EDT 2009


The branch, hierarchical-cf has been updated
       via  addb5821719c29056fd95b05b6ff0ca27774580e (commit)
       via  8f25aa7ff98e235a9c551dd9a0acae1ae998e567 (commit)
       via  a4316f96d2df88053da3284cf729ce300db5b59a (commit)
       via  93c87efa9e1347aea6c60a20b0e3bcaaa757990a (commit)
       via  6f1f370a28146902391a5aa0e6aca3e6027d9b9a (commit)
       via  941165eccb3dc4d3cfd8ccd12b13095697de3117 (commit)
       via  81891062ffc6ed25a56f80351f6fc3294c19688e (commit)
       via  06fb91c59e50cdb38af35b7c1f950a0ea46aeef0 (commit)
       via  9e94e652891d020243164e34cb4fb4a4d3953321 (commit)
       via  78307ec2127a29e5f96f40ecccf401ad7fd730ac (commit)
       via  83484ef9537d5abdc1a20462715be41f3b6807d3 (commit)
       via  e98a0c969d0877be0a6d93c34f1100b40bcd591c (commit)
      from  1df624d927e81c066637b1d698adcab117eaed59 (commit)

Summary of changes:
 etc/upgrade/split-out-cf-categories.pl            |  115 +++++++++++++++++++++
 lib/RT/Attachment_Overlay.pm                      |    3 +-
 lib/RT/CustomField_Overlay.pm                     |   24 ++--
 lib/RT/Interface/Web.pm                           |   21 ++++
 share/html/Admin/CustomFields/Modify.html         |    4 +-
 share/html/Elements/CollectionAsTable/Header      |   16 +---
 share/html/Elements/CollectionAsTable/ParseFormat |   25 ++---
 share/html/Elements/CollectionAsTable/Row         |   29 ++----
 share/html/Elements/RT__Ticket/ColumnMap          |    2 +-
 share/html/Ticket/Update.html                     |   18 +++-
 10 files changed, 190 insertions(+), 67 deletions(-)
 create mode 100644 etc/upgrade/split-out-cf-categories.pl

- Log -----------------------------------------------------------------
commit 93c87efa9e1347aea6c60a20b0e3bcaaa757990a
Merge: 1df624d 6f1f370
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 26 15:04:06 2009 -0400

    Merge commit 'origin/3.8-trunk' into hierarchical-cf


commit a4316f96d2df88053da3284cf729ce300db5b59a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 26 17:24:36 2009 -0400

    Remove hint from categories, caused by copy-and-paste mistake

diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index fca44ec..c61bd30 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -115,9 +115,7 @@
     Default => $CustomFieldObj->BasedOnObj,
     Not => $CustomFieldObj->id,
 &>
-<div class="hints">
-<&|/l&>Some browsers may only load content from the same domain as your RT server.</&>
-</div></td></tr>
+</td></tr>
 % }
 
 <tr><td class="label">&nbsp;</td><td>

commit 8f25aa7ff98e235a9c551dd9a0acae1ae998e567
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 26 17:56:48 2009 -0400

    Unify codepaths for setting BasedOn

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 27ddd1a..f49f76c 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -251,15 +251,7 @@ sub Create {
     }
 
     if ( exists $args{'BasedOn'} ) {
-        my $BasedOn = RT::CustomField->new( $self->CurrentUser );
-        $BasedOn->Load($args{BasedOn});
-        if ( $BasedOn->id && $BasedOn->CurrentUserHasRight('SeeCustomField') ) {
-            $self->AddAttribute(
-                Name => "BasedOn",
-                Description => "Custom field whose CF we depend on",
-                Content => $BasedOn->id,
-            );
-        }
+        $self->SetBasedOn( $args{'BasedOn'} );
     }
 
     return ($rv, $msg) unless exists $args{'Queue'};
@@ -1266,12 +1258,20 @@ sub _URLTemplate {
 sub SetBasedOn {
     my $self = shift;
     my $value = shift;
-    $value = $value->id if ref $value;
 
-    $self->SetAttribute(
+    return $self->DeleteAttribute( "BasedOn" )
+        unless defined $value and length $value;
+
+    my $cf = RT::CustomField->new( $self->CurrentUser );
+    $cf->Load( ref $value ? $value->Id : $value );
+
+    return (0, "Permission denied")
+        unless $cf->Id && $cf->CurrentUserHasRight('SeeCustomField');
+
+    return $self->AddAttribute(
         Name => "BasedOn",
         Description => "Custom field whose CF we depend on",
-        Content => $value,
+        Content => $cf->Id,
     );
 }
 

commit addb5821719c29056fd95b05b6ff0ca27774580e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Aug 26 17:57:25 2009 -0400

    Add upgrade script

diff --git a/etc/upgrade/split-out-cf-categories.pl b/etc/upgrade/split-out-cf-categories.pl
new file mode 100644
index 0000000..27cb6d3
--- /dev/null
+++ b/etc/upgrade/split-out-cf-categories.pl
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+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' );
+
+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;
+
+    print "Found CF '@{[$cf->Name]}' with categories:\n";
+    print "  $_\n" for @categories;
+
+    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;

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


More information about the Rt-commit mailing list