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