line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: DB.pm,v 1.14 2005/02/03 00:06:26 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2001 Online Office Berlin. All rights reserved. |
8
|
|
|
|
|
|
|
# Copyright (C) 2002 Slaven Rezic. |
9
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
10
|
|
|
|
|
|
|
# terms of the GNU General Public License, see the file COPYING. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
14
|
|
|
|
|
|
|
# WWW: http://we-framework.sourceforge.net |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package WE::DB; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
WE::DB - root of web editor database collection |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$root = new WE::DB |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Instantiate a new root for a web.editor database. This class will |
30
|
|
|
|
|
|
|
usually be overwritten by a class doing the dirt work of opening the |
31
|
|
|
|
|
|
|
sub-databases. See L for an example. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
14
|
|
|
14
|
|
97
|
use base qw(Class::Accessor); |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
14793
|
|
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
14
|
|
38521
|
use strict; |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
522
|
|
38
|
14
|
|
|
14
|
|
74
|
use vars qw($VERSION); |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
9016
|
|
39
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/); |
40
|
|
|
|
|
|
|
|
41
|
14
|
|
|
14
|
|
81
|
use vars qw(@DBs); |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
6173
|
|
42
|
|
|
|
|
|
|
@DBs = qw(UserDB ObjDB ContentDB LinkDB OnlineUserDB NameDB); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/CurrentUser CurrentGroups/, @DBs); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 CONSTRUCTOR new([%args]) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
If C<-class =E Classname> is specified, then a specialized class |
49
|
|
|
|
|
|
|
constructor will be used (for example C). Additional |
50
|
|
|
|
|
|
|
arguments are passed to this constructor. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
0
|
|
|
0
|
1
|
0
|
my($class, %args) = @_; |
56
|
0
|
0
|
|
|
|
0
|
if ($args{-class}) { |
57
|
0
|
|
|
|
|
0
|
my $class = delete $args{-class}; |
58
|
0
|
|
|
|
|
0
|
eval "require $class"; |
59
|
0
|
0
|
|
|
|
0
|
if ($@) { |
60
|
0
|
|
|
|
|
0
|
my $err = $@; |
61
|
0
|
0
|
|
|
|
0
|
if (!$class->can("new")) { |
62
|
|
|
|
|
|
|
# There's no constructor: it is really a failure... |
63
|
0
|
|
|
|
|
0
|
die $@; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
# else the class is probably a file-less class already defined |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
0
|
$class->new(%args); |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
0
|
my $self = {}; |
70
|
0
|
|
|
|
|
0
|
bless $self, $class; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over 4 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item use_databases(@classes) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Tell the framework to L |
81
|
|
|
|
|
|
|
classes. These classes will be automatically loaded. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The classes can be specified as abbreviated names (without a ":" in |
84
|
|
|
|
|
|
|
the class name), in this case C is automatically prepended. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
The special class name C<:all> represents the classes C, C |
87
|
|
|
|
|
|
|
and C. Note that these are not really all available databases |
88
|
|
|
|
|
|
|
in a typical WE system. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub use_databases { |
93
|
15
|
|
|
15
|
1
|
61
|
my($self, @classes) = @_; |
94
|
|
|
|
|
|
|
TRY_CLASS: |
95
|
15
|
|
|
|
|
38
|
foreach my $class (@classes) { |
96
|
|
|
|
|
|
|
# allow abbreviations |
97
|
29
|
50
|
|
|
|
153
|
if (#$class !~ /^WE::DB/ && # XXX remove if harmless |
98
|
|
|
|
|
|
|
$class !~ /:/) { |
99
|
29
|
|
|
|
|
86
|
$class = "WE::DB::$class"; |
100
|
|
|
|
|
|
|
} |
101
|
29
|
50
|
|
|
|
198
|
if ($class eq ':all') { # XXX this is not "all" |
102
|
0
|
|
|
|
|
0
|
push @classes, qw(Obj User Content); |
103
|
0
|
|
|
|
|
0
|
next TRY_CLASS; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
{ |
107
|
14
|
|
|
14
|
|
75
|
no strict 'refs'; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
12632
|
|
|
29
|
|
|
|
|
48
|
|
108
|
|
|
|
|
|
|
# stolen from base.pm, has_version: |
109
|
29
|
|
|
|
|
47
|
my $vglob = ${$class.'::'}{VERSION}; |
|
29
|
|
|
|
|
203
|
|
110
|
29
|
100
|
100
|
|
|
254
|
if ($vglob && *$vglob{SCALAR}) { |
111
|
|
|
|
|
|
|
# class is already loaded |
112
|
1
|
|
|
|
|
4
|
next TRY_CLASS; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
28
|
|
|
|
|
2030
|
eval "require $class; $class->import"; |
117
|
28
|
100
|
|
|
|
15027
|
die $@ if $@; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item login($user, $password) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Identify the user and do a login to the system by putting him to the |
124
|
|
|
|
|
|
|
OnlineUser database. Return true if everything was right. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub login { |
129
|
0
|
|
|
0
|
1
|
|
my($self, $user, $password) = @_; |
130
|
0
|
|
|
|
|
|
my $r = $self->identify($user, $password); |
131
|
0
|
0
|
|
|
|
|
if ($r) { |
132
|
0
|
0
|
|
|
|
|
$self->OnlineUserDB->login($user) if $self->OnlineUserDB; |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
$r; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item logout($user) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Logout the user. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub logout { |
144
|
0
|
|
|
0
|
1
|
|
my($self, $user) = @_; |
145
|
0
|
0
|
|
|
|
|
$self->OnlineUserDB->logout($user) if $self->OnlineUserDB; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item identify($user, $password) |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Identify $user with $password and return true if the authentification |
151
|
|
|
|
|
|
|
is successful. Also set the CurrentUser member. This does not make any |
152
|
|
|
|
|
|
|
changes to the OnlineUser database. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub identify { |
157
|
0
|
|
|
0
|
1
|
|
my($self, $user, $password) = @_; |
158
|
0
|
|
|
|
|
|
my $r = $self->UserDB->identify($user, $password); |
159
|
0
|
0
|
|
|
|
|
if ($r) { |
160
|
0
|
|
|
|
|
|
$self->CurrentUser($user); |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
$r; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item is_allowed($action, $object_id) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Return a true value if the current user is allowed to do C<$action> on |
168
|
|
|
|
|
|
|
object C<$object_id>. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This method should be overridden, because it provides no access |
171
|
|
|
|
|
|
|
control in this form. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub is_allowed { |
176
|
0
|
|
|
0
|
1
|
|
my($self, $action, $obj_id) = @_; |
177
|
0
|
|
|
|
|
|
my $user = $self->CurrentUser; |
178
|
0
|
0
|
|
|
|
|
return 0 if !$user; |
179
|
0
|
|
|
|
|
|
warn "The is_allowed() method in WE::DB should be overridden!\n"; |
180
|
0
|
|
|
|
|
|
return 1; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item is_releasable_page($obj) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Return true if the given object is releasable. The default |
186
|
|
|
|
|
|
|
implementation always returns true. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub is_releasable_page { |
191
|
0
|
|
|
0
|
1
|
|
my($self, $obj) = @_; |
192
|
0
|
|
|
|
|
|
return 1; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item root_object |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Return the root object of the underlying object database |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub root_object { |
202
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
203
|
0
|
|
|
|
|
|
$self->ObjDB->root_object; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item init |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Initialize the underlying databases. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub init { |
213
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
foreach my $db (@DBs) { |
216
|
0
|
0
|
0
|
|
|
|
if (defined $self->{$db} && $self->{$db}->can("init")) { |
217
|
0
|
|
|
|
|
|
$self->{$db}->init; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item delete_db_contents |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Delete the contents from B underlying databases. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub delete_db_contents { |
229
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
foreach my $db (@DBs) { |
232
|
0
|
0
|
0
|
|
|
|
if (exists $self->{$db} && $self->{$db}->can("delete_db_contents")) { |
233
|
0
|
|
|
|
|
|
$self->{$db}->delete_db_contents; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item delete_db |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Delete B underlying databases. This will also remove the files, |
241
|
|
|
|
|
|
|
not just the contents as in C. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub delete_db { |
246
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
247
|
0
|
|
|
|
|
|
foreach my $db (@DBs) { |
248
|
0
|
0
|
0
|
|
|
|
if (exists $self->{$db} && $self->{$db}->can("delete_db")) { |
249
|
0
|
|
|
|
|
|
$self->{$db}->delete_db; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item CurrentUser |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Set or get the currently logged in user. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub CurrentUser { |
261
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
262
|
0
|
0
|
|
|
|
|
if (@_) { |
263
|
0
|
|
|
|
|
|
$self->{CurrentUser} = $_[0]; |
264
|
0
|
0
|
|
|
|
|
if ($self->UserDB) { |
265
|
0
|
|
|
|
|
|
$self->CurrentGroups([ $self->UserDB->get_groups($self->{CurrentUser}) ]); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
0
|
|
|
|
|
|
$self->{CurrentUser}; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub CurrentLang { |
272
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
273
|
0
|
0
|
|
|
|
|
if (@_) { |
274
|
0
|
|
|
|
|
|
$self->{CurrentLang} = $_[0]; |
275
|
|
|
|
|
|
|
} else { |
276
|
0
|
0
|
0
|
|
|
|
if ($self->CurrentUser && 0 #$self->CurrentUser->Lang |
277
|
|
|
|
|
|
|
) { |
278
|
0
|
|
|
|
|
|
$self->CurrentUser->Lang; |
279
|
|
|
|
|
|
|
} else { |
280
|
0
|
|
|
|
|
|
$self->{CurrentLang}; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
1; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
__END__ |