X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fsbin%2Ffactory;h=743d8b90ee37914e3c786d37eeb4ec6e4c025c64;hb=d4d0590bef31071e8809ec046717444b95b3f30a;hp=8abb1922fa10de274ad61c760066221deeccf564;hpb=945721f48f74d5cfffef7c7cf3a3d6bc2521f5dd;p=freeside.git diff --git a/rt/sbin/factory b/rt/sbin/factory index 8abb1922f..743d8b90e 100644 --- a/rt/sbin/factory +++ b/rt/sbin/factory @@ -1,9 +1,15 @@ -#!/usr/bin/perl -# BEGIN LICENSE BLOCK +#!/usr/bin/perl -w +# BEGIN BPS TAGGED BLOCK {{{ # -# Copyright (c) 1996-2003 Jesse Vincent +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC +# # -# (Except where explictly superceded by other copyright notices) +# (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 @@ -15,14 +21,30 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # -# Unless otherwise specified, all modifications, corrections or -# extensions to this work which alter its source code become the -# property of Best Practical Solutions, LLC when submitted for -# inclusion in the work. +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. # # -# END LICENSE BLOCK - +# 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 DBI; my $database = shift; @@ -38,11 +60,17 @@ my $password = ''; my $LicenseBlock = << '.'; -# BEGIN LICENSE BLOCK +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC +# # -# Copyright (c) 1996-2003 Jesse Vincent +# (Except where explicitly superseded by other copyright notices) # -# (Except where explictly superceded 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 @@ -54,13 +82,29 @@ my $LicenseBlock = << '.'; # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # -# Unless otherwise specified, all modifications, corrections or -# extensions to this work which alter its source code become the -# property of Best Practical Solutions, LLC when submitted for -# inclusion in the work. +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# # +# CONTRIBUTION SUBMISSION POLICY: # -# END LICENSE BLOCK +# (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 }}} . my $Attribution = << '.'; @@ -83,7 +127,17 @@ my @tables = $dbh->tables(); my ( %tablemap, $typemap, %modulemap ); foreach my $table (@tables) { + $table =~ s/\`//g; next if ($table eq 'sessions'); + $table = ucfirst($table); + $table =~ s/field/Field/; + $table =~ s/group/Group/; + $table =~ s/custom/Custom/; + $table =~ s/member/Member/; + $table =~ s/Scripaction/ScripAction/g; + $table =~ s/condition/Condition/g; + $table =~ s/value/Value/; + $table =~ s/Acl/ACL/g; $tablemap{$table} = $table; $modulemap{$table} = $table; if ( $table =~ /^(.*)s$/ ) { @@ -94,6 +148,7 @@ foreach my $table (@tables) { $tablemap{'CreatedBy'} = 'User'; $tablemap{'UpdatedBy'} = 'User'; +my %typemap; $typemap{'id'} = 'ro'; $typemap{'Creator'} = 'auto'; $typemap{'Created'} = 'auto'; @@ -130,7 +185,27 @@ foreach my $table (@tables) { my $ClassAccessible = ""; my $FieldsPod = ""; my $CreatePod = ""; + my $RecordInit = ""; my %fields; + + + my $introspection = $dbh->prepare("SELECT * from $table where id is null"); + $introspection->execute(); + my @names =@{ $introspection->{'NAME'}}; + my @types = @{$introspection->{'TYPE'}}; + my @is_blob = @{$introspection->{'mysql_is_blob'}}; + my @is_num = @{$introspection->{'mysql_is_num'}}; + + my %blobness = (); + my %sqltypes = (); + my %numeric = (); + foreach my $name (@names) { + $sqltypes{$name} = shift @types; + $blobness{$name} = (shift @is_blob || "0"); + $numeric{$name} = (shift @is_num || "0"); + } + + my $sth = $dbh->prepare("DESCRIBE $table"); $sth->execute; @@ -138,10 +213,16 @@ foreach my $table (@tables) { my $field = $row->{'Field'}; my $type = $row->{'Type'}; my $default = $row->{'Default'}; + my $length = 0; + if ($type =~ /^(?:.*?)\((\d+)\)$/) { + $length = $1; + } $fields{$field} = 1; #generate the 'accessible' datastructure + no warnings 'uninitialized'; + if ( $typemap{$field} eq 'auto' ) { $ClassAccessible .= " $field => {read => 1, auto => 1,"; @@ -155,7 +236,7 @@ foreach my $table (@tables) { {read => 1, write => 1,"; } - + $ClassAccessible .= " sql_type => $sqltypes{$field}, length => $length, is_blob => $blobness{$field}, is_numeric => $numeric{$field}, "; $ClassAccessible .= " type => '$type', default => '$default'},\n"; #generate pod for the accessible fields @@ -167,7 +248,7 @@ Returns the current value of $field. "; - unless ( $typemap{$field} eq 'auto' || $typemap{$field} eq 'ro' ) { + unless ( exists $typemap{$field} && ( $typemap{$field} eq 'auto' || $typemap{$field} eq 'ro' )) { $FieldsPod .= " =head2 Set$field VALUE @@ -222,7 +303,7 @@ sub ${field}Obj { } - $Create = " + my $Create = " sub Create { my \$self = shift; my \%args = ( @@ -274,10 +355,15 @@ sub _Init { $CollectionClass .= " - # By default, order by name - \$self->OrderBy( ALIAS => 'main', - FIELD => 'SortOrder', - ORDER => 'ASC'); + # By default, order by SortOrder + \$self->OrderByCols( + { ALIAS => 'main', + FIELD => 'SortOrder', + ORDER => 'ASC' }, + { ALIAS => 'main', + FIELD => 'id', + ORDER => 'ASC' }, + ); "; } $CollectionClass .= " @@ -347,7 +433,7 @@ $Create $FieldsPod -sub _ClassAccessible { +sub _CoreAccessible { { $ClassAccessible @@ -365,7 +451,7 @@ $ClassAccessible open( COL, ">$CollectionClassPath" ); print COL $CollectionClass; - close($COL); + close(COL); } @@ -406,7 +492,7 @@ _Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customiz These overlay files can contain new subs or subs to replace existing subs in this module. -If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line +Each of these files should begin with the line no warnings qw(redefine);