[Rt-commit] rt branch, 3.9-attributes_as_columns, created. rt-3.9.4-492-g4c6e634

Ruslan Zakirov ruz at bestpractical.com
Wed Nov 17 17:50:01 EST 2010


The branch, 3.9-attributes_as_columns has been created
        at  4c6e634f7357aa462c77688281a5a88d6e42cf15 (commit)

- Log -----------------------------------------------------------------
commit 945c8e24ae10f2285518f7e0079754f2fdee1bb1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 12:45:49 2010 +0300

    add AuthToken column in schemas

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 93d1660..8a34f60 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -202,6 +202,7 @@ CREATE TABLE Users (
   	Name 			VARCHAR2(200) CONSTRAINT Users_Name_Unique 
 		unique  NOT NULL,
   	Password 		VARCHAR2(40),
+  	AuthToken 		VARCHAR2(16),
   	Comments 		CLOB,
   	Signature 		CLOB,
   	EmailAddress 		VARCHAR2(120),
diff --git a/etc/schema.Pg b/etc/schema.Pg
index c6bd1af..05d27fd 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -338,6 +338,7 @@ CREATE TABLE Users (
   id INTEGER DEFAULT nextval('users_id_seq'),
   Name varchar(200) NOT NULL  ,
   Password varchar(40) NULL  ,
+  AuthToken varchar(16) NULL  ,
   Comments text NULL  ,
   Signature text NULL  ,
   EmailAddress varchar(120) NULL  ,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index 40367de..f911ffe 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -219,6 +219,7 @@ CREATE TABLE Users (
   id INTEGER ,
   Name varchar(200) NOT NULL  ,
   Password varchar(40) NULL  ,
+  AuthToken varchar(16) NULL  ,
   Comments blob NULL  ,
   Signature blob NULL  ,
   EmailAddress varchar(120) NULL  ,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index dcaa500..d021945 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -210,6 +210,7 @@ CREATE TABLE Users (
   id INTEGER NOT NULL  AUTO_INCREMENT,
   Name varchar(200) NOT NULL  ,
   Password VARBINARY(40) NULL  ,
+  AuthToken VARCHAR(16) CHARACTER SET ascii NULL  ,
   Comments TEXT NULL  ,
   Signature TEXT NULL  ,
   EmailAddress varchar(120) NULL  ,

commit 9f6d74efe29d346f0bf71ca8207a333bcb6feeea
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 12:46:13 2010 +0300

    use AuthToken from DB not, from attributes

diff --git a/lib/RT/User_Overlay.pm b/lib/RT/User_Overlay.pm
index 2aa3ac9..bccc165 100755
--- a/lib/RT/User_Overlay.pm
+++ b/lib/RT/User_Overlay.pm
@@ -954,14 +954,14 @@ readers and other.
 
 sub AuthToken {
     my $self = shift;
-    my $secret = $self->FirstAttribute("AuthToken");
-    return $secret->Content if $secret;
+    my $secret = $self->_Value( AuthToken => @_ );
+    return $secret if $secret;
 
-    my $id = $self->id;
-    $self = RT::User->new( RT->SystemUser );
-    $self->Load( $id );
     $secret = substr(Digest::MD5::md5_hex(time . {} . rand()),0,16);
-    my ($status, $msg) = $self->SetAttribute( Name => "AuthToken", Content => $secret );
+
+    my $tmp = RT::User->new( RT->SystemUser );
+    $tmp->Load( $self->id );
+    my ($status, $msg) = $tmp->SetAuthToken( $secret );
     unless ( $status ) {
         $RT::Logger->error( "Couldn't set auth token: $msg" );
         return undef;
@@ -978,7 +978,7 @@ Generate a random authentication string for the user.
 sub GenerateAuthToken {
     my $self = shift;
     my $token = substr(Digest::MD5::md5_hex(time . {} . rand()),0,16);
-    return $self->SetAttribute( Name => "AuthToken", Content => $token );
+    return $self->SetAuthToken( $token );
 }
 
 =head3 GenerateAuthString

commit fa8a4e54cd4e6613f1869ff3df0b7ffe49568f8d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 12:52:14 2010 +0300

    upgrade for schemas

diff --git a/etc/upgrade/3.9.7/schema.Oracle b/etc/upgrade/3.9.7/schema.Oracle
new file mode 100644
index 0000000..3c69b3b
--- /dev/null
+++ b/etc/upgrade/3.9.7/schema.Oracle
@@ -0,0 +1 @@
+ALTER TABLE Users ADD COLUMN AuthToken VARCHAR2(16) NULL;
diff --git a/etc/upgrade/3.9.7/schema.Pg b/etc/upgrade/3.9.7/schema.Pg
new file mode 100644
index 0000000..3c78228
--- /dev/null
+++ b/etc/upgrade/3.9.7/schema.Pg
@@ -0,0 +1 @@
+ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
diff --git a/etc/upgrade/3.9.7/schema.SQLite b/etc/upgrade/3.9.7/schema.SQLite
new file mode 100644
index 0000000..3c78228
--- /dev/null
+++ b/etc/upgrade/3.9.7/schema.SQLite
@@ -0,0 +1 @@
+ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
diff --git a/etc/upgrade/3.9.7/schema.mysql b/etc/upgrade/3.9.7/schema.mysql
new file mode 100644
index 0000000..f3b94b1
--- /dev/null
+++ b/etc/upgrade/3.9.7/schema.mysql
@@ -0,0 +1 @@
+ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) CHARACTER SET ascii NULL;

commit bb55b180cd60ebe8bab4719e7134835eb1962605
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 13:02:33 2010 +0300

    move AuthToken from Attributes into the column on upgrade

diff --git a/etc/upgrade/3.9.7/content b/etc/upgrade/3.9.7/content
new file mode 100644
index 0000000..e517e5e
--- /dev/null
+++ b/etc/upgrade/3.9.7/content
@@ -0,0 +1,20 @@
+ at Initial = (
+    sub {
+        my $query = 'UPDATE Users SET AuthToken = (SELECT Content FROM Attributes WHERE'
+            .' Name = ? AND ObjectType = ? AND Users.id = Attributes.ObjectId)';
+
+        my $res = $RT::Handle->SimpleQuery( $query, 'AuthToken', 'RT::User');
+        unless ( $res ) {
+            $RT::Logger->error("Failed move AuthTokens from Attributes into Users table");
+            return;
+        }
+
+        $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
+        $res = $RT::Handle->SimpleQuery( $query, 'AuthToken', 'RT::User');
+        unless ( $res ) {
+            $RT::Logger->error("Failed to delete AuthTokens Attributes");
+            return;
+        }
+        return 1;
+    },
+);

commit 621b54e2351d09c7957caad1313fdea1f49547af
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 13:36:14 2010 +0300

    regen User.pm

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index da66fa8..8397b2a 100755
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -88,6 +88,7 @@ Create takes a hash of values and creates a row in the database:
 
   varchar(200) 'Name'.
   varbinary(40) 'Password'.
+  varchar(16) 'AuthToken'.
   text 'Comments'.
   text 'Signature'.
   varchar(120) 'EmailAddress'.
@@ -126,6 +127,7 @@ sub Create {
     my %args = ( 
                 Name => '',
                 Password => '',
+                AuthToken => '',
                 Comments => '',
                 Signature => '',
                 EmailAddress => '',
@@ -158,6 +160,7 @@ sub Create {
     $self->SUPER::Create(
                          Name => $args{'Name'},
                          Password => $args{'Password'},
+                         AuthToken => $args{'AuthToken'},
                          Comments => $args{'Comments'},
                          Signature => $args{'Signature'},
                          EmailAddress => $args{'EmailAddress'},
@@ -236,6 +239,24 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 =cut
 
 
+=head2 AuthToken
+
+Returns the current value of AuthToken. 
+(In the database, AuthToken is stored as varchar(16).)
+
+
+
+=head2 SetAuthToken VALUE
+
+
+Set AuthToken to VALUE. 
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, AuthToken will be stored as a varchar(16).)
+
+
+=cut
+
+
 =head2 Comments
 
 Returns the current value of Comments. 
@@ -768,6 +789,8 @@ sub _CoreAccessible {
 		{read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
         Password => 
 		{read => 1, write => 1, sql_type => 12, length => 40,  is_blob => 0,  is_numeric => 0,  type => 'varbinary(40)', default => ''},
+        AuthToken => 
+		{read => 1, write => 1, sql_type => 12, length => 16,  is_blob => 0,  is_numeric => 0,  type => 'varchar(16)', default => ''},
         Comments => 
 		{read => 1, write => 1, sql_type => -4, length => 0,  is_blob => 1,  is_numeric => 0,  type => 'text', default => ''},
         Signature => 

commit b1434a70314f15a5546fa8cf3ff9ca6ec0e53931
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 13:36:44 2010 +0300

    delete some spaces from factory script to match the current state

diff --git a/devel/factory b/devel/factory
index 11f02cf..446b067 100755
--- a/devel/factory
+++ b/devel/factory
@@ -65,42 +65,42 @@ my $password = '';
 
 my $LicenseBlock = << '.';
 # BEGIN BPS TAGGED BLOCK {{{
-# 
+#
 # COPYRIGHT:
-# 
+#
 # This software is Copyright (c) 1996-2010 Best Practical Solutions, LLC
 #                                          <jesse 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
@@ -109,7 +109,7 @@ my $LicenseBlock = << '.';
 # 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 }}}
 .
 

commit 6630cb094278a00bbe7618eb596b02edf4ca4387
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 18:15:22 2010 +0300

    BasedOn column

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 8a34f60..ad2a63a 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -355,6 +355,7 @@ CREATE TABLE CustomFields (
 	MaxValues	NUMBER(11,0) DEFAULT 0 NOT NULL,
 	Pattern		CLOB,
         Repeated        NUMBER(11,0) DEFAULT 0 NOT NULL,
+        BasedOn         NUMBER(11,0) NULL,
 	Description	VARCHAR2(255),
 	SortOrder	NUMBER(11,0) DEFAULT 0 NOT NULL,
 	LookupType	VARCHAR2(255),
diff --git a/etc/schema.Pg b/etc/schema.Pg
index 05d27fd..d0d70f9 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -540,6 +540,7 @@ CREATE TABLE CustomFields (
   Type varchar(200) NULL  ,
   MaxValues integer NOT NULL DEFAULT 0  ,
   Repeated integer NOT NULL DEFAULT 0 , 
+  BasedOn integer NULL, 
   Pattern varchar(65536) NULL  ,
   LookupType varchar(255) NOT NULL  ,
   Description varchar(255) NULL  ,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index f911ffe..7778f36 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -377,6 +377,7 @@ CREATE TABLE CustomFields (
   MaxValues integer,		# New -- was 'Single'(1) and 'Multiple'(0)
   Pattern varchar(65536) NULL  ,	# New -- Must validate against this
   Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry
+  BasedOn INTEGER NULL,
   Description varchar(255) NULL  ,
   SortOrder integer NOT NULL DEFAULT 0  ,
   LookupType varchar(255) NOT NULL,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index d021945..6cf5039 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -355,6 +355,7 @@ CREATE TABLE CustomFields (
   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
+  BasedOn INTEGER NULL,
   Description varchar(255) NULL  ,
   SortOrder integer NOT NULL DEFAULT 0  ,
   LookupType varchar(255) CHARACTER SET ascii NOT NULL,

commit 9b712c14081b583ede2d20dcc64fbd418e38dd45
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 18:16:08 2010 +0300

    use BasedOn from columns, not attributes

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 06fef2e..d3ab80e 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -1606,33 +1606,28 @@ sub SetBasedOn {
     my $self = shift;
     my $value = shift;
 
-    return $self->DeleteAttribute( "BasedOn" )
+    return $self->_Set( Field => 'BasedOn', Value => $value, @_ )
         unless defined $value and length $value;
 
     my $cf = RT::CustomField->new( $self->CurrentUser );
-    $cf->Load( ref $value ? $value->Id : $value );
+    $cf->Load( ref $value ? $value->id : $value );
 
     return (0, "Permission denied")
-        unless $cf->Id && $cf->CurrentUserHasRight('SeeCustomField');
+        unless $cf->id && $cf->CurrentUserHasRight('SeeCustomField');
 
     # XXX: Remove this restriction once we support lists and cascaded selects
     if ( $self->RenderType =~ /List/ ) {
         return (0, $self->loc("We can't currently render as a List when basing categories on another custom field.  Please use another render type."));
     }
 
-    return $self->AddAttribute(
-        Name => "BasedOn",
-        Description => "Custom field whose CF we depend on",
-        Content => $cf->Id,
-    );
+    return $self->_Set( Field => 'BasedOn', Value => $value, @_ )
 }
 
 sub BasedOnObj {
     my $self = shift;
-    my $obj = RT::CustomField->new( $self->CurrentUser );
 
-    my $attribute = $self->FirstAttribute("BasedOn");
-    $obj->Load($attribute->Content) if defined $attribute;
+    my $obj = RT::CustomField->new( $self->CurrentUser );
+    $obj->Load( $self->BasedOn );
     return $obj;
 }
 

commit e7c894ac192316ad3dfb6be4db3ff348581e7235
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 18:26:10 2010 +0300

    upgrade schema properly

diff --git a/etc/upgrade/3.9.7/schema.Oracle b/etc/upgrade/3.9.7/schema.Oracle
index 3c69b3b..143d74b 100644
--- a/etc/upgrade/3.9.7/schema.Oracle
+++ b/etc/upgrade/3.9.7/schema.Oracle
@@ -1 +1,2 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR2(16) NULL;
+ALTER TABLE CustomFields ADD COLUMN BasedOn NUMBER(11,0) NULL;
diff --git a/etc/upgrade/3.9.7/schema.Pg b/etc/upgrade/3.9.7/schema.Pg
index 3c78228..1ff23f5 100644
--- a/etc/upgrade/3.9.7/schema.Pg
+++ b/etc/upgrade/3.9.7/schema.Pg
@@ -1 +1,2 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
+ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
diff --git a/etc/upgrade/3.9.7/schema.SQLite b/etc/upgrade/3.9.7/schema.SQLite
index 3c78228..1ff23f5 100644
--- a/etc/upgrade/3.9.7/schema.SQLite
+++ b/etc/upgrade/3.9.7/schema.SQLite
@@ -1 +1,2 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
+ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
diff --git a/etc/upgrade/3.9.7/schema.mysql b/etc/upgrade/3.9.7/schema.mysql
index f3b94b1..0ea2bf3 100644
--- a/etc/upgrade/3.9.7/schema.mysql
+++ b/etc/upgrade/3.9.7/schema.mysql
@@ -1 +1,2 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) CHARACTER SET ascii NULL;
+ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;

commit af5753153070ac815547fed23ca19ca66063e281
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 18:38:03 2010 +0300

    move BasedOn from Attributes on upgrade

diff --git a/etc/upgrade/3.9.7/content b/etc/upgrade/3.9.7/content
index e517e5e..58a1403 100644
--- a/etc/upgrade/3.9.7/content
+++ b/etc/upgrade/3.9.7/content
@@ -17,4 +17,22 @@
         }
         return 1;
     },
+    sub {
+        my $query = 'UPDATE CustomFields SET BasedOn = (SELECT Content FROM Attributes WHERE'
+            .' Name = ? AND ObjectType = ? AND CustomFields.id = Attributes.ObjectId)';
+
+        my $res = $RT::Handle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField');
+        unless ( $res ) {
+            $RT::Logger->error("Failed move BasedOn from Attributes into CustomFields table");
+            return;
+        }
+
+        $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
+        $res = $RT::Handle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField');
+        unless ( $res ) {
+            $RT::Logger->error("Failed to delete BasedOn Attributes");
+            return;
+        }
+        return 1;
+    },
 );

commit 894c82dd05b5e81df301794e5ce0c79bffc1b895
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 18:50:56 2010 +0300

    regenerate CustomField.pm

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index d91eea2..990aa5c 100755
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -91,6 +91,7 @@ Create takes a hash of values and creates a row in the database:
   int(11) 'MaxValues'.
   text 'Pattern'.
   smallint(6) 'Repeated'.
+  int(11) 'BasedOn'.
   varchar(255) 'Description'.
   int(11) 'SortOrder'.
   varchar(255) 'LookupType'.
@@ -109,6 +110,7 @@ sub Create {
                 MaxValues => '',
                 Pattern => '',
                 Repeated => '0',
+                BasedOn => '',
                 Description => '',
                 SortOrder => '0',
                 LookupType => '',
@@ -121,6 +123,7 @@ sub Create {
                          MaxValues => $args{'MaxValues'},
                          Pattern => $args{'Pattern'},
                          Repeated => $args{'Repeated'},
+                         BasedOn => $args{'BasedOn'},
                          Description => $args{'Description'},
                          SortOrder => $args{'SortOrder'},
                          LookupType => $args{'LookupType'},
@@ -230,6 +233,24 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 =cut
 
 
+=head2 BasedOn
+
+Returns the current value of BasedOn. 
+(In the database, BasedOn is stored as int(11).)
+
+
+
+=head2 SetBasedOn VALUE
+
+
+Set BasedOn to VALUE. 
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, BasedOn will be stored as a int(11).)
+
+
+=cut
+
+
 =head2 Description
 
 Returns the current value of Description. 
@@ -354,6 +375,8 @@ sub _CoreAccessible {
 		{read => 1, write => 1, sql_type => -4, length => 0,  is_blob => 1,  is_numeric => 0,  type => 'text', default => ''},
         Repeated => 
 		{read => 1, write => 1, sql_type => 5, length => 6,  is_blob => 0,  is_numeric => 1,  type => 'smallint(6)', default => '0'},
+        BasedOn => 
+		{read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
         Description => 
 		{read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
         SortOrder => 

commit 0d2f02fa81d37ec1c589d87b255fc79b4676f9bf
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Nov 16 19:00:39 2010 +0300

    handle BasedOn in Create properly

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index d3ab80e..4361bfc 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -333,6 +333,7 @@ sub Create {
         Type        => $args{'Type'},
         MaxValues   => $args{'MaxValues'},
         Pattern     => $args{'Pattern'},
+        BasedOn     => $args{'BasedOn'},
         Description => $args{'Description'},
         Disabled    => $args{'Disabled'},
         LookupType  => $args{'LookupType'},
@@ -351,10 +352,6 @@ sub Create {
         $self->SetValuesClass( $args{'ValuesClass'} );
     }
 
-    if ( exists $args{'BasedOn'} ) {
-        $self->SetBasedOn( $args{'BasedOn'} );
-    }
-
     return ($rv, $msg) unless exists $args{'Queue'};
 
     # Compat code -- create a new ObjectCustomField mapping

commit 71df59f0457cdf15ae30f26be5afd6c2dcb41a47
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 14:57:12 2010 +0300

    move HasRenderType closer to its friends

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 4361bfc..587c696 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -575,23 +575,6 @@ sub Types {
 }
 
 
-=head2 HasRenderTypes [TYPE_COMPOSITE]
-
-Returns a boolean value indicating whether the L</RenderTypes> and
-L</RenderType> methods make sense for this custom field.
-
-Currently true only for type C<Select>.
-
-=cut
-
-sub HasRenderTypes {
-    my $self = shift;
-    my ($type, $max) = split /-/, (@_ ? shift : $self->TypeComposite), 2;
-    return undef unless $type;
-    return defined $FieldTypes{$type}->{render_types}->{ $max == 1 ? 'single' : 'multiple' };
-}
-
-
 =head2 IsSelectionType 
 
 Retuns a boolean value indicating whether the C<Values> method makes sense
@@ -989,6 +972,23 @@ sub DefaultRenderType {
     return defined $FieldTypes{$type}->{render_types}->{ $max == 1 ? 'single' : 'multiple' }[0];
 }
 
+=head2 HasRenderTypes [TYPE_COMPOSITE]
+
+Returns a boolean value indicating whether the L</RenderTypes> and
+L</RenderType> methods make sense for this custom field.
+
+Currently true only for type C<Select>.
+
+=cut
+
+sub HasRenderTypes {
+    my $self = shift;
+    my ($type, $max) = split /-/, (@_ ? shift : $self->TypeComposite), 2;
+    return undef unless $type;
+    return defined $FieldTypes{$type}->{render_types}
+        ->{ $max == 1 ? 'single' : 'multiple' };
+}
+
 =head2 RenderTypes [TYPE COMPOSITE]
 
 Returns the valid render types for this custom field's type or the TYPE

commit dce00fe53c4f197b4bbd300891fe1f84bcd50836
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 14:59:49 2010 +0300

    use RenderType from column instead of attributes

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 587c696..7e1b229 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -925,9 +925,8 @@ sub RenderType {
     my $self = shift;
     return '' unless $self->HasRenderTypes;
 
-    my $type = $self->FirstAttribute( 'RenderType' );
-    $type = $type->Content if $type;
-    return $type || $self->DefaultRenderType;
+    return $self->_Value( 'RenderType', @_ )
+        || $self->DefaultRenderType;
 }
 
 =head2 SetRenderType TYPE
@@ -937,11 +936,13 @@ Sets this custom field's render type.
 =cut
 
 sub SetRenderType {
-    my ($self, $type) = @_;
-    return unless $self->HasRenderTypes;
+    my $self = shift;
+    my $type = shift;
+    return (0, $self->loc("This custom field has no Render Types"))
+        unless $self->HasRenderTypes;
 
-    if ( not defined $type ) {
-        return $self->DeleteAttribute( 'RenderType' );
+    if ( !$type || $type eq $self->DefaultRenderType ) {
+        return $self->_Set( Field => 'RenderType', Value => undef, @_ );
     }
 
     if ( not grep { $_ eq $type } $self->RenderTypes ) {
@@ -954,7 +955,7 @@ sub SetRenderType {
         return (0, $self->loc("We can't currently render as a List when basing categories on another custom field.  Please use another render type."));
     }
 
-    return $self->SetAttribute( Name => 'RenderType', Content => $type );
+    return $self->_Set( Field => 'RenderType', Value => $type, @_ );
 }
 
 =head2 DefaultRenderType [TYPE COMPOSITE]

commit dc54603912d10d54ce70607586fbdae4ee216fd0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 15:26:03 2010 +0300

    check render type on Create

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 7e1b229..44a9d86 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -328,9 +328,24 @@ sub Create {
         $args{'MaxValues'} = 1;
     }
 
+    if ( $args{'RenderType'} ||= undef ) {
+        my $composite = join '-', @args{'Type', 'MaxValues'};
+        return (0, $self->loc("This custom field has no Render Types"))
+            unless $self->HasRenderTypes( $composite );
+
+        if ( $args{'RenderType'} eq $self->DefaultRenderType( $composite ) ) {
+            $args{'RenderType'} = undef;
+        } else {
+            return (0, $self->loc("Invalid Render Type") )
+                unless grep $_ eq  $args{'RenderType'}, $self->RenderTypes( $composite );
+        }
+
+    }
+
     (my $rv, $msg) = $self->SUPER::Create(
         Name        => $args{'Name'},
         Type        => $args{'Type'},
+        RenderType  => $args{'RenderType'},
         MaxValues   => $args{'MaxValues'},
         Pattern     => $args{'Pattern'},
         BasedOn     => $args{'BasedOn'},

commit e5d30aa1cf2098d38520afb6fe7b5cb38c25eb0a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 15:26:26 2010 +0300

    actually add RenderType column on CustomFields

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index ad2a63a..0c22422 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -352,6 +352,7 @@ CREATE TABLE CustomFields (
 		CONSTRAINT CustomFields_Key PRIMARY KEY,
 	Name		VARCHAR2(200),
 	Type		VARCHAR2(200),
+	RenderType	VARCHAR2(64),
 	MaxValues	NUMBER(11,0) DEFAULT 0 NOT NULL,
 	Pattern		CLOB,
         Repeated        NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index d0d70f9..2e1d870 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -538,6 +538,7 @@ CREATE TABLE CustomFields (
   id INTEGER DEFAULT nextval('customfields_id_seq'),
   Name varchar(200) NULL  ,
   Type varchar(200) NULL  ,
+  RenderType varchar(64) NULL  ,
   MaxValues integer NOT NULL DEFAULT 0  ,
   Repeated integer NOT NULL DEFAULT 0 , 
   BasedOn integer NULL, 
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index 7778f36..861b885 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -374,6 +374,7 @@ CREATE TABLE CustomFields (
   id INTEGER NOT NULL  ,
   Name varchar(200) NULL  ,
   Type varchar(200) NULL  ,	# Changed -- 'Single' and 'Multiple' is moved out
+  RenderType varchar(64) NULL  ,
   MaxValues integer,		# New -- was 'Single'(1) and 'Multiple'(0)
   Pattern varchar(65536) NULL  ,	# New -- Must validate against this
   Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry
diff --git a/etc/schema.mysql b/etc/schema.mysql
index 6cf5039..ef6d3f1 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -352,6 +352,7 @@ 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
+  RenderType varchar(64) CHARACTER SET ascii NULL  ,
   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

commit b7d9f9157cd93d5682cb10152420d27c03276b3c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 15:37:23 2010 +0300

    upgrade schema with RenderType

diff --git a/etc/upgrade/3.9.7/schema.Oracle b/etc/upgrade/3.9.7/schema.Oracle
index 143d74b..697d810 100644
--- a/etc/upgrade/3.9.7/schema.Oracle
+++ b/etc/upgrade/3.9.7/schema.Oracle
@@ -1,2 +1,3 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR2(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn NUMBER(11,0) NULL;
+ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR2(64) NULL;
diff --git a/etc/upgrade/3.9.7/schema.Pg b/etc/upgrade/3.9.7/schema.Pg
index 1ff23f5..2d591d9 100644
--- a/etc/upgrade/3.9.7/schema.Pg
+++ b/etc/upgrade/3.9.7/schema.Pg
@@ -1,2 +1,3 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
+ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;
diff --git a/etc/upgrade/3.9.7/schema.SQLite b/etc/upgrade/3.9.7/schema.SQLite
index 1ff23f5..2d591d9 100644
--- a/etc/upgrade/3.9.7/schema.SQLite
+++ b/etc/upgrade/3.9.7/schema.SQLite
@@ -1,2 +1,3 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
+ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;
diff --git a/etc/upgrade/3.9.7/schema.mysql b/etc/upgrade/3.9.7/schema.mysql
index 0ea2bf3..e780cdb 100644
--- a/etc/upgrade/3.9.7/schema.mysql
+++ b/etc/upgrade/3.9.7/schema.mysql
@@ -1,2 +1,3 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) CHARACTER SET ascii NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
+ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;

commit befe6a5b4e8bd02e07af1d841c3e1c2b6ccca0d1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 15:37:42 2010 +0300

    refactor upgrde script for re-use

diff --git a/etc/upgrade/3.9.7/content b/etc/upgrade/3.9.7/content
index 58a1403..d65bf94 100644
--- a/etc/upgrade/3.9.7/content
+++ b/etc/upgrade/3.9.7/content
@@ -1,38 +1,28 @@
- at Initial = (
-    sub {
-        my $query = 'UPDATE Users SET AuthToken = (SELECT Content FROM Attributes WHERE'
-            .' Name = ? AND ObjectType = ? AND Users.id = Attributes.ObjectId)';
+my $move_attributes = sub {
+    my ($table, $type, $column) = @_;
+    my $query = "UPDATE $table SET $column = (SELECT Content FROM Attributes WHERE"
+        ." Name = ? AND ObjectType = ? AND $table.id = Attributes.ObjectId)";
 
-        my $res = $RT::Handle->SimpleQuery( $query, 'AuthToken', 'RT::User');
-        unless ( $res ) {
-            $RT::Logger->error("Failed move AuthTokens from Attributes into Users table");
-            return;
-        }
+    my $res = $RT::Handle->SimpleQuery( $query, $column, $type );
+    unless ( $res ) {
+        $RT::Logger->error("Failed move $type from Attributes into $table table");
+        return;
+    }
 
-        $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
-        $res = $RT::Handle->SimpleQuery( $query, 'AuthToken', 'RT::User');
-        unless ( $res ) {
-            $RT::Logger->error("Failed to delete AuthTokens Attributes");
-            return;
-        }
-        return 1;
+    $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
+    $res = $RT::Handle->SimpleQuery( $query, $column, $type );
+    unless ( $res ) {
+        $RT::Logger->error("Failed to delete AuthTokens Attributes");
+        return;
+    }
+    return 1;
+};
+
+ at Initial = (
+    sub {
+        return $move_attributes->( 'Users', 'RT::User', 'AuthToken');
     },
     sub {
-        my $query = 'UPDATE CustomFields SET BasedOn = (SELECT Content FROM Attributes WHERE'
-            .' Name = ? AND ObjectType = ? AND CustomFields.id = Attributes.ObjectId)';
-
-        my $res = $RT::Handle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField');
-        unless ( $res ) {
-            $RT::Logger->error("Failed move BasedOn from Attributes into CustomFields table");
-            return;
-        }
-
-        $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
-        $res = $RT::Handle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField');
-        unless ( $res ) {
-            $RT::Logger->error("Failed to delete BasedOn Attributes");
-            return;
-        }
-        return 1;
+        return $move_attributes->( 'CustomFields', 'RT::CustomField', 'BasedOn');
     },
 );

commit fb091fd7ce2fdcf6a0a57a95100d60ce528bbf4e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 15:39:12 2010 +0300

    move RenderType from Attributes on upgrade

diff --git a/etc/upgrade/3.9.7/content b/etc/upgrade/3.9.7/content
index d65bf94..b739e33 100644
--- a/etc/upgrade/3.9.7/content
+++ b/etc/upgrade/3.9.7/content
@@ -25,4 +25,7 @@ my $move_attributes = sub {
     sub {
         return $move_attributes->( 'CustomFields', 'RT::CustomField', 'BasedOn');
     },
+    sub {
+        return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType');
+    },
 );

commit 88c0bae85eecb78551842a284a6bcdd43ad4a165
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 18:39:35 2010 +0300

    regen CustomField.pm

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 990aa5c..2cb5bcb 100755
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -88,6 +88,7 @@ Create takes a hash of values and creates a row in the database:
 
   varchar(200) 'Name'.
   varchar(200) 'Type'.
+  varchar(64) 'RenderType'.
   int(11) 'MaxValues'.
   text 'Pattern'.
   smallint(6) 'Repeated'.
@@ -107,6 +108,7 @@ sub Create {
     my %args = ( 
                 Name => '',
                 Type => '',
+                RenderType => '',
                 MaxValues => '',
                 Pattern => '',
                 Repeated => '0',
@@ -120,6 +122,7 @@ sub Create {
     $self->SUPER::Create(
                          Name => $args{'Name'},
                          Type => $args{'Type'},
+                         RenderType => $args{'RenderType'},
                          MaxValues => $args{'MaxValues'},
                          Pattern => $args{'Pattern'},
                          Repeated => $args{'Repeated'},
@@ -179,6 +182,24 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 =cut
 
 
+=head2 RenderType
+
+Returns the current value of RenderType. 
+(In the database, RenderType is stored as varchar(64).)
+
+
+
+=head2 SetRenderType VALUE
+
+
+Set RenderType to VALUE. 
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, RenderType will be stored as a varchar(64).)
+
+
+=cut
+
+
 =head2 MaxValues
 
 Returns the current value of MaxValues. 
@@ -369,6 +390,8 @@ sub _CoreAccessible {
 		{read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
         Type => 
 		{read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
+        RenderType => 
+		{read => 1, write => 1, sql_type => 12, length => 64,  is_blob => 0,  is_numeric => 0,  type => 'varchar(64)', default => ''},
         MaxValues => 
 		{read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
         Pattern => 

commit 4452d4fb27cdbd7ed679c0a9700d133fde303b2d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 21:24:09 2010 +0300

    SubjectTag column on Queues

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 0c22422..ad3bb3d 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -27,6 +27,7 @@ CREATE TABLE Queues (
 	Description 		VARCHAR2(255),
 	CorrespondAddress 	VARCHAR2(120),
 	CommentAddress 		VARCHAR2(120),
+	SubjectTag 		VARCHAR2(120),
 	InitialPriority 	NUMBER(11,0) DEFAULT 0 NOT NULL,
 	FinalPriority 		NUMBER(11,0) DEFAULT 0 NOT NULL,
 	DefaultDueIn 		NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index 2e1d870..6351a84 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -50,6 +50,7 @@ CREATE TABLE Queues (
   Description varchar(255) NULL  ,
   CorrespondAddress varchar(120) NULL  ,
   CommentAddress varchar(120) NULL  ,
+  SubjectTag varchar(120) NULL  ,
   InitialPriority integer NOT NULL DEFAULT 0  ,
   FinalPriority integer NOT NULL DEFAULT 0  ,
   DefaultDueIn integer NOT NULL DEFAULT 0  ,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index 861b885..88725cd 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -28,6 +28,7 @@ CREATE TABLE Queues (
   Description varchar(255) NULL  ,
   CorrespondAddress varchar(120) NULL  ,
   CommentAddress varchar(120) NULL  ,
+  SubjectTag varchar(120) NULL  ,
   InitialPriority integer NULL  ,
   FinalPriority integer NULL  ,
   DefaultDueIn integer NULL  ,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index ef6d3f1..c5aac29 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -24,6 +24,7 @@ CREATE TABLE Queues (
   Description varchar(255) NULL  ,
   CorrespondAddress varchar(120) CHARACTER SET ascii NULL,
   CommentAddress varchar(120) CHARACTER SET ascii NULL,
+  SubjectTag varchar(120) NULL,
   InitialPriority integer NOT NULL DEFAULT 0  ,
   FinalPriority integer NOT NULL DEFAULT 0  ,
   DefaultDueIn integer NOT NULL DEFAULT 0  ,

commit 81a118aab22f309c9d8610bfe16ad61be5691cc7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 21:24:47 2010 +0300

    add SubjectTag column on upgrade

diff --git a/etc/upgrade/3.9.7/schema.Oracle b/etc/upgrade/3.9.7/schema.Oracle
index 697d810..5bed834 100644
--- a/etc/upgrade/3.9.7/schema.Oracle
+++ b/etc/upgrade/3.9.7/schema.Oracle
@@ -1,3 +1,4 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR2(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn NUMBER(11,0) NULL;
 ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR2(64) NULL;
+ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR2(120) NULL;
diff --git a/etc/upgrade/3.9.7/schema.Pg b/etc/upgrade/3.9.7/schema.Pg
index 2d591d9..d6f7172 100644
--- a/etc/upgrade/3.9.7/schema.Pg
+++ b/etc/upgrade/3.9.7/schema.Pg
@@ -1,3 +1,4 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
 ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;
+ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR(120) NULL;
diff --git a/etc/upgrade/3.9.7/schema.SQLite b/etc/upgrade/3.9.7/schema.SQLite
index 2d591d9..d6f7172 100644
--- a/etc/upgrade/3.9.7/schema.SQLite
+++ b/etc/upgrade/3.9.7/schema.SQLite
@@ -1,3 +1,4 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
 ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;
+ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR(120) NULL;
diff --git a/etc/upgrade/3.9.7/schema.mysql b/etc/upgrade/3.9.7/schema.mysql
index e780cdb..48acd99 100644
--- a/etc/upgrade/3.9.7/schema.mysql
+++ b/etc/upgrade/3.9.7/schema.mysql
@@ -1,3 +1,4 @@
 ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) CHARACTER SET ascii NULL;
 ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL;
 ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL;
+ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR(120) NULL;

commit a12542ebca16f7c8abe88e86b98bd9e4e741193a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Nov 17 22:17:36 2010 +0300

    upgrade function that moves SubjectTag from attributes

diff --git a/etc/upgrade/3.9.7/content b/etc/upgrade/3.9.7/content
index b739e33..6d2d5db 100644
--- a/etc/upgrade/3.9.7/content
+++ b/etc/upgrade/3.9.7/content
@@ -28,4 +28,24 @@ my $move_attributes = sub {
     sub {
         return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType');
     },
+    sub {
+        my $attr = RT->System->FirstAttribute('BrandedSubjectTag');
+        return 1 unless $attr;
+
+        my $map = $attr->Content || {};
+        while ( my ($qid, $tag) = each %$map ) {
+            my $queue = RT::Queue->new( RT->SystemUser );
+            $queue->Load( $qid );
+            unless ( $queue->id ) {
+                $RT::Logger->warning("Couldn't load queue #$qid. Skipping...");
+                next;
+            }
+
+            my ($status, $msg) = $queue->SetSubjectTag($tag);
+            unless ( $status ) {
+                $RT::Logger->error("Couldn't set subject tag for queue #$qid: $msg");
+                next;
+            }
+        }
+    },
 );

commit 84ef8c94653b47c213dafa4c7bb899fb5b907b7a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 18 01:46:37 2010 +0300

    regen Queue.pm

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 9b02c7a..a2165ff 100755
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -90,6 +90,7 @@ Create takes a hash of values and creates a row in the database:
   varchar(255) 'Description'.
   varchar(120) 'CorrespondAddress'.
   varchar(120) 'CommentAddress'.
+  varchar(120) 'SubjectTag'.
   int(11) 'InitialPriority'.
   int(11) 'FinalPriority'.
   int(11) 'DefaultDueIn'.
@@ -107,6 +108,7 @@ sub Create {
                 Description => '',
                 CorrespondAddress => '',
                 CommentAddress => '',
+                SubjectTag => '',
                 InitialPriority => '0',
                 FinalPriority => '0',
                 DefaultDueIn => '0',
@@ -118,6 +120,7 @@ sub Create {
                          Description => $args{'Description'},
                          CorrespondAddress => $args{'CorrespondAddress'},
                          CommentAddress => $args{'CommentAddress'},
+                         SubjectTag => $args{'SubjectTag'},
                          InitialPriority => $args{'InitialPriority'},
                          FinalPriority => $args{'FinalPriority'},
                          DefaultDueIn => $args{'DefaultDueIn'},
@@ -209,6 +212,24 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 =cut
 
 
+=head2 SubjectTag
+
+Returns the current value of SubjectTag. 
+(In the database, SubjectTag is stored as varchar(120).)
+
+
+
+=head2 SetSubjectTag VALUE
+
+
+Set SubjectTag to VALUE. 
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, SubjectTag will be stored as a varchar(120).)
+
+
+=cut
+
+
 =head2 InitialPriority
 
 Returns the current value of InitialPriority. 
@@ -331,6 +352,8 @@ sub _CoreAccessible {
 		{read => 1, write => 1, sql_type => 12, length => 120,  is_blob => 0,  is_numeric => 0,  type => 'varchar(120)', default => ''},
         CommentAddress => 
 		{read => 1, write => 1, sql_type => 12, length => 120,  is_blob => 0,  is_numeric => 0,  type => 'varchar(120)', default => ''},
+        SubjectTag => 
+		{read => 1, write => 1, sql_type => 12, length => 120,  is_blob => 0,  is_numeric => 0,  type => 'varchar(120)', default => ''},
         InitialPriority => 
 		{read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         FinalPriority => 

commit 93ee8b765643b7ab1f67bb04a751ddf050682b53
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 18 01:47:18 2010 +0300

    use SubjectTag from column, not from attributes

diff --git a/lib/RT/Queue_Overlay.pm b/lib/RT/Queue_Overlay.pm
index f329c04..5d8619a 100755
--- a/lib/RT/Queue_Overlay.pm
+++ b/lib/RT/Queue_Overlay.pm
@@ -365,7 +365,7 @@ sub Create {
         CorrespondAddress => '',
         Description       => '',
         CommentAddress    => '',
-        SubjectTag        => '',
+        SubjectTag        => undef,
         InitialPriority   => 0,
         FinalPriority     => 0,
         DefaultDueIn      => 0,
@@ -575,39 +575,6 @@ sub SetEncrypt {
     return ($status, $self->loc('Encrypting disabled'));
 }
 
-sub SubjectTag {
-    my $self = shift;
-    return RT->System->SubjectTag( $self );
-}
-
-sub SetSubjectTag {
-    my $self = shift;
-    my $value = shift;
-
-    return ( 0, $self->loc('Permission Denied') )
-        unless $self->CurrentUserHasRight('AdminQueue');
-
-    my $attr = RT->System->FirstAttribute('BrandedSubjectTag');
-    my $map = $attr ? $attr->Content : {};
-    if ( defined $value && length $value ) {
-        $map->{ $self->id } = $value;
-    } else {
-        delete $map->{ $self->id };
-    }
-
-    my ($status, $msg) = RT->System->SetAttribute(
-        Name        => 'BrandedSubjectTag',
-        Description => 'Queue id => subject tag map',
-        Content     => $map,
-    );
-    return ($status, $msg) unless $status;
-    return ($status, $self->loc(
-        "SubjectTag changed to [_1]", 
-        (defined $value && length $value)? $value : $self->loc("(no value)")
-    ))
-}
-
-
 =head2 Templates
 
 Returns an RT::Templates object of all of this queue's templates.

commit 4c6e634f7357aa462c77688281a5a88d6e42cf15
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Nov 18 01:49:14 2010 +0300

    gather subject tags from column in Queues table

diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index 6a2cb57..057e053 100755
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -222,14 +222,11 @@ sub SubjectTag {
     my $self = shift;
     my $queue = shift;
 
-    my $map = $self->FirstAttribute('BrandedSubjectTag');
-    $map = $map->Content if $map;
-    return $queue ? undef : () unless $map;
+    return $queue->SubjectTag if $queue;
 
-    return $map->{ $queue->id } if $queue;
-
-    my %seen = ();
-    return grep !$seen{lc $_}++, values %$map;
+    my $queues = RT::Queues->new( $self->CurrentUser );
+    $queues->Limit( FIELD => 'SubjectTag', OPERATOR => 'IS NOT', VALUE => 'NULL' );
+    return $queues->DistinctFieldValues('SubjectTag');
 }
 
 =head2 QueueCacheNeedsUpdate ( 1 )

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


More information about the Rt-commit mailing list