X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2Fpkg_category.pm;fp=FS%2FFS%2Fpkg_category.pm;h=0beaf1c117c1dc34ae3540d99a6a6958a69c28c0;hb=947c1f964f1304242f8a6ffabacccf040f1d505e;hp=69578c9cf701d10e9f9fe45caee7aea809683d9a;hpb=161eeea92a87e07d071a6c953f2dbd30daeb480c;p=freeside.git diff --git a/FS/FS/pkg_category.pm b/FS/FS/pkg_category.pm index 69578c9cf..0beaf1c11 100644 --- a/FS/FS/pkg_category.pm +++ b/FS/FS/pkg_category.pm @@ -1,11 +1,13 @@ package FS::pkg_category; use strict; -use vars qw( @ISA ); -use FS::Record qw( qsearch ); +use vars qw( @ISA $me $DEBUG ); +use FS::Record qw( qsearch dbh ); use FS::part_pkg; @ISA = qw( FS::Record ); +$DEBUG = 0; +$me = '[FS::pkg_category]'; =head1 NAME @@ -95,10 +97,39 @@ sub check { $self->ut_numbern('categorynum') or $self->ut_text('categoryname') + or $self->ut_snumber('weight') or $self->SUPER::check; } +# _ upgrade_data +# +# Used by FS::Upgrade to migrate to a new database. +# +# + +sub _upgrade_data { + my ($class, %opts) = @_; + my $dbh = dbh; + + warn "$me upgrading $class\n" if $DEBUG; + + my @pkg_category = + qsearch('pkg_category', { weight => { op => '!=', value => '' } } ); + + unless( scalar(@pkg_category) ) { + my @pkg_category = qsearch('pkg_category', {} ); + my $weight = 0; + foreach ( sort { $a->description cmp $b->description } @pkg_category ) { + $_->weight($weight); + my $error = $_->replace; + die "error setting pkg_category weight: $error\n" if $error; + $weight += 10; + } + } + ''; +} + =back =head1 BUGS