"alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können
[kivitendo-erp.git] / SL / System / InstallationLock.pm
1 package SL::System::InstallationLock;
2
3 use strict;
4
5 sub lock {
6   my ($class) = @_;
7
8   return 1 if $::lx_office_conf{debug}->{keep_installation_unlocked};
9
10   my $fh;
11   if (!open($fh, ">", $class->lock_file_name)) {
12     die $::locale->text('Lock file handling failed. Please verify that the directory "#1" is writeable by the webserver.', $::lx_office_conf{paths}->{userspath});
13   }
14
15   close $fh;
16
17   return 1;
18 }
19
20 sub unlock {
21   my ($class) = @_;
22
23   return 1 if $::lx_office_conf{debug}->{keep_installation_unlocked};
24
25   my $name = $class->lock_file_name;
26   if ((-f $name)  && !unlink($name)) {
27     die $::locale->text('Lock file handling failed. Please verify that the directory "#1" is writeable by the webserver.', $::lx_office_conf{paths}->{userspath});
28   }
29
30   return 1;
31 }
32
33 sub is_locked {
34   my ($class) = @_;
35
36   return 0 if $::lx_office_conf{debug}->{keep_installation_unlocked};
37   return -f $class->lock_file_name;
38 }
39
40 sub lock_file_name {
41   $::lx_office_conf{paths}->{userspath} . "/nologin";
42 }
43
44 1;
45
46 __END__
47
48 =pod
49
50 =encoding utf8
51
52 =head1 NAME
53
54 SL::System::InstallationLock - Handle locking the installation with a
55 global lock file
56
57 =head1 SYNOPSIS
58
59   SL::System::InstallationLock->lock;
60   # Do important and uninterruptable work!
61   SL::System::InstallationLock->unlock;
62
63
64 =head1 OVERVIEW
65
66 If the global lock file exists then no user may login. The
67 administration area is not affected.
68
69 There's a configuration setting
70 C<debug.keep_installation_unlocked>. If it is trueish then all of
71 these commands will always keep the installation unlocked: L</lock>
72 and L</unlock> won't do anything and L</is_locked> always returns 0.
73
74 =head1 FUNCTIONS
75
76 =over 4
77
78 =item C<is_locked>
79
80 Returns 1 or 0 depending on whether or not the installation is currently locked.
81
82 =item C<lock>
83
84 Creates the lock file. Throws an exception if writing to the lock file
85 location fails.
86
87 =item C<lock_file_name>
88
89 Returns the file name for the global lock file.
90
91 =item C<unlock>
92
93 Removed the lock file. Throws an exception if the lock exists and
94 removing the lock file fails.
95
96 =back
97
98 =head1 BUGS
99
100 Nothing here yet.
101
102 =head1 AUTHOR
103
104 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
105
106 =cut