<% include( 'elements/process.html', 'table' => 'part_virtual_field', 'viewall_dir' => 'browse', 'message' => [ 'Your custom field has been created, but will not be available untill Apache has been restarted.=warning', ], 'precheck_callback' => sub { my ($cgi) = @_; $act = 'edit' if $cgi->param('vfieldpart'); my @permitted_tables = qw( svc_broadband router cust_main ); return 'Table not in list of permitted tables' unless $cgi->param('dbtable') && grep { $_ eq $cgi->param('dbtable') } @permitted_tables; ''; }, 'noerror_callback' => sub { my ($cgi, $object) = @_; if ( $act eq 'add' ) { use FS::Schema qw( reload_dbdef ); warn "cf add started schema modification, time=".time; my $dbh = dbh; my $sql = "ALTER TABLE ".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")"; $dbh->do($sql) or die $dbh->errstr; $sql = "ALTER TABLE h_".$object->dbtable." ADD COLUMN cf_".$object->name." varchar(".$object->length.")"; $dbh->do($sql) or die $dbh->errstr; # apparently nothing happens w/o commit here - but is this OK? $dbh->commit or die $dbh->errstr; # reload schema my $dbdef_file = "/usr/local/etc/freeside/dbdef.".datasrc; my $dbdef = new_native DBIx::DBSchema $dbh; $dbdef->save($dbdef_file); ## Stop reload of db schema as only reload current process and not others. Could be a pain to diagnose error. ## Restart Apache to reload DB Schema for all. #delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload #reload_dbdef($dbdef_file); warn "cf add done schema modification, time=".time; } # XXX: edit is going to be harder: possibly add editing length and renaming column ''; }, ) %> <%init> my $act = 'add'; ## make cgi->param("name") lowercase my $vcf_name = $cgi->param('name'); $vcf_name =~ s/\s/_/g; $vcf_name =~ s/[^A-Za-z0-9\-_]//g; $cgi->param('name' => lc $vcf_name); die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration');