[Rt-commit] rt branch, 4.4/drop-cf-self-category-select, created. rt-4.2.5-208-gb4746a6

? sunnavy sunnavy at bestpractical.com
Mon Nov 24 13:04:21 EST 2014


The branch, 4.4/drop-cf-self-category-select has been created
        at  b4746a6ccce049a6cd2abac3ca1a7e22fd702fc6 (commit)

- Log -----------------------------------------------------------------
commit b4746a6ccce049a6cd2abac3ca1a7e22fd702fc6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Oct 22 07:00:21 2014 +0800

    drop cf its own category select
    
    previously, if a select cf's "categories are based on" is empty, we will show
    an extra <select> to let user filter values by category, which is kinda
    misleading as the extra select is not a real cf, so it's not searchable.
    
    if user wants to use the category select, there is an upgrade step to turn
    categories into real cfs.
    
    this function was supplied by etc/upgrade/split-out-cf-categories before, now
    it's a mandatory upgrade step.
    
    Fixes: #30426

diff --git a/etc/upgrade/4.3.4/content b/etc/upgrade/4.3.4/content
new file mode 100644
index 0000000..13e55bb
--- /dev/null
+++ b/etc/upgrade/4.3.4/content
@@ -0,0 +1,109 @@
+use strict;
+use warnings;
+
+our @Final = (
+    sub {
+        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++;
+            RT->Logger->warn("Found CF '@{[$cf->Name]}' with categories: " .  join ", ", @categories);
+            my $newname = $cf->Name . " category";
+            RT->Logger->warn("Going to create CF $newname for it");
+
+            # 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,
+            );
+            if ( $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,
+                        );
+                        RT->Logger->error("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,
+                        );
+                        RT->Logger->error("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,
+                    );
+                    RT->Logger->error("Can't create CustomFieldValue: $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->Logger->error("Can't create ObjectCustomFieldValue: $msg") unless $id;
+                    }
+                }
+            }
+            else {
+                RT->Logger->error("Can't create custom field '$newname': $msg");
+            }
+        }
+    },
+);
diff --git a/etc/upgrade/split-out-cf-categories.in b/etc/upgrade/split-out-cf-categories.in
deleted file mode 100644
index a774501..0000000
--- a/etc/upgrade/split-out-cf-categories.in
+++ /dev/null
@@ -1,171 +0,0 @@
-#!@PERL@
-# BEGIN BPS TAGGED BLOCK {{{
-#
-# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
-#                                          <sales at 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('LogToSTDERR' => '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/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index fb0a6f2..6afed6a 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -314,7 +314,7 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
             map { 
                 $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
                 $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
-                $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
+                $_ => $ARGS{ $paramtag ."-new-$_" } } grep { defined $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
         );
         push (@results, $msg);
         $added_cfv = 1 if $id;
diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Admin/Elements/AddCustomFieldValue
index ec1a34b..eaeba33 100644
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/AddCustomFieldValue
@@ -73,8 +73,6 @@
 % while (my $Value = $Categories->Next) {
 <option value="<% $Value->Name %>"><% $Value->Name %></option>
 % }
-%   } else {
-<input type="text" size="10" class="editcategory" name="<% $paramtag %>-Category" value="" />
 %   }
 </td>
 % }
diff --git a/share/html/Admin/Elements/EditCustomFieldValues b/share/html/Admin/Elements/EditCustomFieldValues
index 5a81ec7..7ae6159 100644
--- a/share/html/Admin/Elements/EditCustomFieldValues
+++ b/share/html/Admin/Elements/EditCustomFieldValues
@@ -79,8 +79,6 @@
 % while (my $Value = $Categories->Next) {
 <option value="<% $Value->Name %>"<% $selected eq $Value->Name ? q[ selected="selected"] : "" |n%>><% $Value->Name %></option>
 % }
-%   } else {
-<input type="text" size="10" class="editcategory" name="<% $paramtag %>-Category" value="<% $value->Category || '' %>" />
 %   }
 </td>
 % }
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index e1c010b..0b9ebc5 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -51,16 +51,7 @@
 % my $selected = 0;
 % my @category;
 % my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
-% if (!$HideCategory and @category and not $CustomField->BasedOnObj->id) {
-%# XXX - Hide this select from w3m?
-  <select onchange="filter_cascade_by_id(<% $name |n,j %>, this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
-    <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
-%   foreach my $cat (@category) {
-%     my ($depth, $name) = @$cat;
-      <option value="<% $name %>"><% ' ' x $depth |n %><% $name %></option>
-%   }
-    </select><br />
-% } elsif ($CustomField->BasedOnObj->id) {
+% if ($CustomField->BasedOnObj->id) {
 
 <script type="text/javascript"><!--
 jQuery(  function () {
diff --git a/share/static/js/cascaded.js b/share/static/js/cascaded.js
index c5ea64a..70d6ef8 100644
--- a/share/static/js/cascaded.js
+++ b/share/static/js/cascaded.js
@@ -1,19 +1,18 @@
-function filter_cascade_by_id (id, vals, is_hierarchical) {
+function filter_cascade_by_id (id, vals) {
     var element = document.getElementById(id);
     if (!element) { return };
 
     if ( element.tagName == 'SELECT' ) {
         var complete_select = document.getElementById(id + "-Complete" );
-        return filter_cascade_select(element, complete_select, vals, is_hierarchical);
+        return filter_cascade_select(element, complete_select, vals );
     }
     else {
         if ( !( vals instanceof Array ) ) {
             vals = [vals];
         }
 
-        if ( is_hierarchical && (vals.length == 0 || (vals.length == 1 && vals[0] == '')) ) {
-            // no category, and the category is from a hierchical cf;
-            // leave it empty
+        if ( vals.length == 0 || (vals.length == 1 && vals[0] == '') ) {
+            // no category, leave it empty
             jQuery(element).find('div').hide();
         }
         else {
@@ -27,7 +26,7 @@ function filter_cascade_by_id (id, vals, is_hierarchical) {
     }
 }
 
-function filter_cascade_select (select, complete_select, vals, is_hierarchical) {
+function filter_cascade_select (select, complete_select, vals) {
     if ( !( vals instanceof Array ) ) {
         vals = [vals];
     }
@@ -45,13 +44,8 @@ function filter_cascade_select (select, complete_select, vals, is_hierarchical)
         var cloned_empty_label;
         for ( var j = 0; j < vals.length; j++ ) {
             var val = vals[j];
-            if ( val == '' && is_hierarchical ) {
-                // no category, and the category is from a hierchical cf;
-                // leave this set of options empty
-            } else if ( val == '' ) {
-                // no category, let's clone all node
-                jQuery(select).append(jQuery(complete_children).clone());
-                break;
+            if ( val == '' ) {
+                // no category, leave this set of options empty
             }
             else {
                 var labels_to_clone = {};
@@ -90,7 +84,7 @@ function filter_cascade_select (select, complete_select, vals, is_hierarchical)
 // for back compatibility
         for (i = 0; i < children.length; i++) {
             if (!children[i].label) { continue };
-            if ( val == '' && is_hierarchical ) {
+            if ( val == '' ) {
                 hide(children[i]);
                 continue;
             }

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


More information about the rt-commit mailing list