[Bio] / WebApplication / scripts / set_user_preference.pl Repository:
ViewVC logotype

Annotation of /WebApplication/scripts/set_user_preference.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : paczian 1.1 #!/usr/bin/env perl
2 :    
3 :     use strict;
4 :     use warnings;
5 :    
6 : paczian 1.2 use WebApplicationDBHandle;
7 : paczian 1.1
8 :     use FIG;
9 :    
10 :     use Getopt::Long;
11 :    
12 :     sub usage {
13 :     print "set_user_preference.pl >>> set a user preference\n";
14 :     print "user_set_password.pl -login <login> -application <application> -preference <preference> -value <value>\n";
15 :     }
16 :    
17 :     # read in parameters
18 :     my $login = '';
19 :     my $app = '';
20 :     my $preference = '';
21 :     my $value = '';
22 :    
23 :     GetOptions ( 'application=s' => \$app,
24 :     'login=s' => \$login,
25 :     'preference=s' => \$preference,
26 :     'value=s' => \$value,
27 :     );
28 :    
29 :    
30 :     unless ($app and $login and $preference and $value) {
31 :     &usage();
32 :     exit 0;
33 :     }
34 :    
35 :     # initialize db-master
36 : paczian 1.2 my ($dbmaster, $error) = WebApplicationDBHandle->new();
37 :    
38 :     # check if we got a dbmaster
39 :     if ($error) {
40 :     print $error."\n";
41 :     exit 0;
42 :     }
43 :    
44 : paczian 1.1 my $application = $dbmaster->Backend->init( { name => $app } );
45 :     unless ( ref( $application ) ) {
46 :     print STDERR "Application $app not found ! \n";
47 :     exit(0);
48 :     }
49 :    
50 :     # get user
51 :     my $user = $dbmaster->User->init( { 'login' => $login } );
52 :     unless (ref $user) {
53 :     print "User $login not found in database, aborting.\n";
54 :     exit 0;
55 :     }
56 :    
57 :     my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
58 :     name => $preference,
59 :     application => $application } );
60 :    
61 :     unless ( scalar( @$preferences ) ) {
62 :     my $preferenceobj = $dbmaster->Preferences->create( { user => $user,
63 :     name => $preference,
64 :     value => $value,
65 :     application => $application } );
66 :     print STDERR "Preference set.\n";
67 :     }
68 :     else {
69 :     if ( $preferences->[0]->value eq $value ) {
70 :     print STDERR "The user already has this preference.\n";
71 :     }
72 :     else {
73 :     $preferences->[0]->value( $value );
74 :     print STDERR "Preference set from ".$preferences->[0]->value." to $value\n";
75 :     }
76 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3