From 947c1f964f1304242f8a6ffabacccf040f1d505e Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 5 Oct 2009 00:49:34 +0000 Subject: leading summary page invoices #RT5086 --- FS/FS/pkg_category.pm | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'FS/FS/pkg_category.pm') diff --git a/FS/FS/pkg_category.pm b/FS/FS/pkg_category.pm index 69578c9..0beaf1c 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 -- cgit v1.1