diff options
author | levinse <levinse> | 2011-07-22 18:59:27 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-07-22 18:59:27 +0000 |
commit | c405e80203f323a83b447d6fc899dbba32d52f2a (patch) | |
tree | aa7cc7ad31c43eb012ad3d9b787ee0a51bb6b4ac /httemplate/edit/process/part_virtual_field.html | |
parent | 99e8e2006117bd4b97ebb1daf897cc257265dc3f (diff) |
custom fields, RT11714
Diffstat (limited to 'httemplate/edit/process/part_virtual_field.html')
-rw-r--r-- | httemplate/edit/process/part_virtual_field.html | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/httemplate/edit/process/part_virtual_field.html b/httemplate/edit/process/part_virtual_field.html new file mode 100644 index 000000000..e734d9616 --- /dev/null +++ b/httemplate/edit/process/part_virtual_field.html @@ -0,0 +1,48 @@ +<% include( 'elements/process.html', + 'table' => 'part_virtual_field', + 'viewall_dir' => 'browse', + '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 # XXX: fix this + my $dbdef = new_native DBIx::DBSchema $dbh; + $dbdef->save($dbdef_file); + 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'; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +</%init> |