/usr/share/otrs/Kernel/System/Lock.pm is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::Lock;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Cache',
'Kernel::System::DB',
'Kernel::System::Log',
'Kernel::System::Valid',
);
=head1 NAME
Kernel::System::Lock - lock lib
=head1 DESCRIPTION
All lock functions.
The whole lock API is just for "reading" lock states. By default, there is "unlock", "lock" and "lock-tmp".
Usually you would not modify those lock states, because there is no use case for this.
=head1 PUBLIC INTERFACE
=head2 new()
create an object
my $LockObject = $Kernel::OM->Get('Kernel::System::Lock');
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
$Self->{CacheType} = 'Lock';
$Self->{CacheTTL} = 60 * 60 * 24 * 20;
$Self->{ViewableLocks} = $Kernel::OM->Get('Kernel::Config')->Get('Ticket::ViewableLocks')
|| die 'No Config entry "Ticket::ViewableLocks"!';
return $Self;
}
=head2 LockViewableLock()
get list of view-able lock types (used to show available tickets)
my @List = $LockObject->LockViewableLock(
Type => 'Name', # ID|Name
);
Returns:
@List = ( 'unlock', 'lock', 'lock-tmp' );
my @ListID = $LockObject->LockViewableLock(
Type => 'ID', # ID|Name
);
Returns:
@List = ( 1, 2, 3 );
=cut
sub LockViewableLock {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Type)) {
if ( !$Param{$_} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
# check cache
my $CacheKey = 'LockViewableLock::' . $Param{Type};
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => $CacheKey,
);
return @{$Cache} if $Cache;
# sql
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
SQL => "
SELECT id, name
FROM ticket_lock_type
WHERE name IN ( ${\(join ', ', @{$Self->{ViewableLocks}})} )
AND valid_id IN ( ${\(join ', ', $Kernel::OM->Get('Kernel::System::Valid')->ValidIDsGet())} )",
);
my @Name;
my @ID;
while ( my @Data = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
push @Name, $Data[1];
push @ID, $Data[0];
}
# set cache
$Kernel::OM->Get('Kernel::System::Cache')->Set(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => 'LockViewableLock::Name',
Value => \@Name,
);
$Kernel::OM->Get('Kernel::System::Cache')->Set(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => 'LockViewableLock::ID',
Value => \@ID,
);
return @Name if $Param{Type} eq 'Name';
return @ID;
}
=head2 LockLookup()
lock state lookup by ID or Name
my $LockID = $LockObject->LockLookup( Lock => 'lock' );
my $Lock = $LockObject->LockLookup( LockID => 2 );
=cut
sub LockLookup {
my ( $Self, %Param ) = @_;
# get (already cached) lock list
my %LockList = $Self->LockList(
UserID => 1,
);
my $Key;
my $Value;
my $ReturnData;
if ( $Param{LockID} ) {
$Key = 'LockID';
$Value = $Param{LockID};
$ReturnData = $LockList{ $Param{LockID} };
}
else {
$Key = 'Lock';
$Value = $Param{Lock};
my %LockListReverse = reverse %LockList;
$ReturnData = $LockListReverse{ $Param{Lock} };
}
# check if data exists
if ( !defined $ReturnData ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "No $Key for $Value found!",
);
return;
}
return $ReturnData;
}
=head2 LockList()
get lock state list
my %List = $LockObject->LockList(
UserID => 123,
);
Returns:
%List = (
1 => 'unlock',
2 => 'lock',
3 => 'tmp_lock',
);
=cut
sub LockList {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{UserID} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'UserID!'
);
return;
}
# check cache
my $CacheKey = 'LockList';
my $Cache = $Kernel::OM->Get('Kernel::System::Cache')->Get(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => $CacheKey,
);
return %{$Cache} if $Cache;
# sql
return if !$Kernel::OM->Get('Kernel::System::DB')->Prepare(
SQL => 'SELECT id, name FROM ticket_lock_type',
);
# fetch the result
my %Data;
while ( my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray() ) {
$Data{ $Row[0] } = $Row[1];
}
# set cache
$Kernel::OM->Get('Kernel::System::Cache')->Set(
Type => $Self->{CacheType},
TTL => $Self->{CacheTTL},
Key => $CacheKey,
Value => \%Data,
);
return %Data;
}
1;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
|