[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.1 - (view) (download) (as text)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3