[Rt-commit] rt branch, custom_fields_application, updated. rt-3.8.7-195-gbf0002a

Ruslan Zakirov ruz at bestpractical.com
Tue Mar 2 18:48:47 EST 2010


The branch, custom_fields_application has been updated
       via  bf0002a3aa6ee6691280bf603ff7bb1628d7d03e (commit)
       via  3420559433dc3e2b610c257ad94a6084fb0dcc7d (commit)
      from  9bed33fe428eb6946a3cc3af17b40c63eabe6175 (commit)

Summary of changes:
 etc/upgrade/3.8.8/content                  |   38 ++++++++++++++++++++++++++++
 share/html/Admin/CustomFields/Objects.html |   38 +++++++++++++++++++---------
 2 files changed, 64 insertions(+), 12 deletions(-)
 create mode 100644 etc/upgrade/3.8.8/content

- Log -----------------------------------------------------------------
commit 3420559433dc3e2b610c257ad94a6084fb0dcc7d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Mar 2 07:39:47 2010 +0300

    add upgrade script that deals with OCFs table

diff --git a/etc/upgrade/3.8.8/content b/etc/upgrade/3.8.8/content
new file mode 100644
index 0000000..ee19433
--- /dev/null
+++ b/etc/upgrade/3.8.8/content
@@ -0,0 +1,38 @@
+ at Initial = (
+    sub {
+        # make sure global CFs are not applied to local objects
+        my $ocfs = RT::ObjectCustomFields->new( $RT::SystemUser );
+        $ocfs->Limit( FIELD => 'ObjectId', OPERATOR => '!=', VALUE => 0 );
+        my $alias = $ocfs->Join(
+            FIELD1 => 'CustomField',
+            TABLE2 => 'ObjectCustomFields',
+            FIELD2 => 'CustomField',
+        );
+        $ocfs->Limit( ALIAS => $alias, FIELD => 'ObjectId', VALUE => 0 );
+        while ( my $ocf = $ocfs->Next ) {
+            $ocf->Delete;
+        }
+    },
+    sub {
+        # sort SortOrder
+        my $sth = $RT::Handle->dbh->prepare(
+            "SELECT cfs.LookupType, ocfs.id"
+            ." FROM ObjectCustomFields ocfs, CustomFields cfs"
+            ." WHERE cfs.id = ocfs.CustomField"
+            ." ORDER BY cfs.LookupType, ocfs.SortOrder, cfs.Name"
+        );
+        $sth->execute;
+
+        my ($i, $prev_type) = (0, '');
+        while ( my ($lt, $id) = $sth->fetchrow_array ) {
+            $i = 0 if $prev_type ne $lt;
+            my $ocf = RT::ObjectCustomField->new( $RT::SystemUser );
+            $ocf->Load( $id );
+            my ($status, $msg) = $ocf->SetSortOrder( $i++ );
+            $RT::Logger->warning("Couldn't set SortOrder: $msg")
+                unless $status;
+            $prev_type = $lt;
+        }
+    },
+);
+

commit bf0002a3aa6ee6691280bf603ff7bb1628d7d03e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Mar 3 02:46:37 2010 +0300

    allow to apply globally CFs from 'Applies To' page

diff --git a/share/html/Admin/CustomFields/Objects.html b/share/html/Admin/CustomFields/Objects.html
index 7a01612..06e3739 100644
--- a/share/html/Admin/CustomFields/Objects.html
+++ b/share/html/Admin/CustomFields/Objects.html
@@ -57,6 +57,16 @@
 <form action="Objects.html" method="post">
 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
 
+% if ( $is_global ) {
+<h2><&|/l&>Applies to all objects</&></h2>
+<input type="checkbox" name="RemoveCustomField-<% $CF->id %>" value="0" />
+<&|/l&>check this box to remove this Custom Field from all objects and be able to choose specific objects.</&>
+% } else {
+<h2><&|/l&>Apply globally</&></h2>
+
+<input type="checkbox" name="AddCustomField-<% $CF->id %>" value="0" />
+<&|/l&>check this box to apply this Custom Field to all objects.</&>
+
 <h2><&|/l&>Selected objects</&></h2>
 <& /Elements/CollectionList,
     OrderBy => 'id',
@@ -90,6 +100,8 @@
     ],
 &>
 
+% }
+
 <& /Elements/Submit, Name => 'UpdateObjs' &>
 </form>
 
@@ -104,32 +116,34 @@ Abort(loc("Something wrong. Contact system administrator"))
 my (@results);
 
 if ( $UpdateObjs ) {
-    if ( my $add = $ARGS{'AddCustomField-'.$CF->id} ) {
-        foreach my $id ( ref $add? (@$add) : ($add) ) {
+    if ( defined (my $del = $ARGS{'RemoveCustomField-'.$CF->id}) ) {
+        foreach my $id ( ref $del? (@$del) : ($del) ) {
             my $object = $class->new( $session{'CurrentUser'} );
-            $object->Load( $id );
-            unless ( $object->id ) {
-                next;
+            if ( $id ) {
+                $object->Load( $id );
+                next unless $object->id;
             }
 
-            my ($status, $msg) = $CF->AddToObject( $object );
+            my ($status, $msg) = $CF->RemoveFromObject( $object );
             push @results, $msg;
         }
     }
-    if ( my $del = $ARGS{'RemoveCustomField-'.$CF->id} ) {
-        foreach my $id ( ref $del? (@$del) : ($del) ) {
+    if ( defined (my $add = $ARGS{'AddCustomField-'.$CF->id}) ) {
+        foreach my $id ( ref $add? (@$add) : ($add) ) {
             my $object = $class->new( $session{'CurrentUser'} );
-            $object->Load( $id );
-            unless ( $object->id ) {
-                next;
+            if ( $id ) {
+                $object->Load( $id );
+                next unless $object->id;
             }
 
-            my ($status, $msg) = $CF->RemoveFromObject( $object );
+            my ($status, $msg) = $CF->AddToObject( $object );
             push @results, $msg;
         }
     }
 }
 
+my $is_global = $CF->IsApplied(0);
+
 my $applied = $CF->AppliedTo;
 my $not_applied = $CF->NotAppliedTo;
 

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


More information about the Rt-commit mailing list