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