Repository navigation
Expand file tree
/
Copy pathUserHasScope.pm
More file actions
69 lines (49 loc) · 1.4 KB
/
Copy pathUserHasScope.pm
File metadata and controls
69 lines (49 loc) · 1.4 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
package WebServerBackend::UserHasScope;
# WebServerBackend::UserHasScope - association between Users and Scopes
# $Id: UserHasScope.pm,v 1.2 2008-02-21 17:35:09 paarmann Exp $
use strict;
use warnings;
1;
=pod
=head1 NAME
WebServerBackend::UserHasScope - association between Users and Scopes
=head1 DESCRIPTION
This package contains methods to extend the automatically generated methods
of the UserHasScope object.
=head1 METHODS
=over 4
=item * B<check_database> (I<fix>)
This method checks the wether both scope and user exist and prints to STDERR if
problems are identified. If the optional I<fix> is provided and true, the method
will remove UserHasScope objects that are referencing a non-existant user or
scope. Currently this is used by the script wa_scope_check.pl.
=cut
sub check_database {
my ($self, $fix) = @_;
my $id = $self->_id();
# check if the user exists
my $user;
eval {
$user = $self->user;
};
if ($@) {
print STDERR "[FATAL] UserHasScope $id references a non existant user.\n";
$user = undef;
}
# check if the scope exists
my $scope;
eval {
$scope = $self->scope;
};
if ($@) {
print STDERR "[FATAL] UserHasScope $id references a non existant scope.\n";
$scope = undef;
}
unless($user and $scope) {
if($fix) {
print STDERR "[FIX].. deleting association UserHasScope $id.\n";
$self->delete();
}
}
return 1;
}