Lines 102-107
use ZOOM;
Link Here
|
102 |
use XML::Simple; |
102 |
use XML::Simple; |
103 |
use C4::Boolean; |
103 |
use C4::Boolean; |
104 |
use C4::Debug; |
104 |
use C4::Debug; |
|
|
105 |
use C4::Members; |
105 |
use POSIX (); |
106 |
use POSIX (); |
106 |
use DateTime::TimeZone; |
107 |
use DateTime::TimeZone; |
107 |
use Module::Load::Conditional qw(can_load); |
108 |
use Module::Load::Conditional qw(can_load); |
Lines 1293-1298
sub IsSuperLibrarian {
Link Here
|
1293 |
return ($userenv->{flags}//0) % 2; |
1294 |
return ($userenv->{flags}//0) % 2; |
1294 |
} |
1295 |
} |
1295 |
|
1296 |
|
|
|
1297 |
=head2 setCommandlineEnvironment |
1298 |
|
1299 |
Sets the Koha environment for command line scripts. |
1300 |
|
1301 |
=cut |
1302 |
|
1303 |
sub setCommandlineEnvironment { |
1304 |
my ($class) = @_; |
1305 |
|
1306 |
C4::Context->interface('commandline'); #Set interface for logger and friends |
1307 |
C4::Context->_new_userenv('commandline'); |
1308 |
my $clisu = _enforceCommandlineSuperuserBorrowerExists(); |
1309 |
C4::Context::set_userenv($clisu->{borrowernumber},$clisu->{userid},$clisu->{cardnumber},$clisu->{firstname},$clisu->{surname}, $clisu->{branchcode}, '', {}, '', '', ''); |
1310 |
} |
1311 |
|
1312 |
sub _enforceCommandlineSuperuserBorrowerExists { |
1313 |
my $commandlineSuperuser = C4::Members::GetMember(userid => 'commandlineadmin'); |
1314 |
unless ($commandlineSuperuser) { |
1315 |
my $dbh = C4::Context->dbh(); |
1316 |
my $ctgr = $dbh->selectrow_array("SELECT categorycode FROM categories WHERE category_type = 'I' LIMIT 1;"); |
1317 |
my $brnchcd = $dbh->selectrow_array("SELECT branchcode FROM borrowers GROUP BY branchcode ORDER BY COUNT(*) DESC LIMIT 1;"); |
1318 |
C4::Members::AddMember(cardnumber => 'commandlineadmin', |
1319 |
userid => 'commandlineadmin', |
1320 |
surname => 'Admin', |
1321 |
firstname => 'Koha', |
1322 |
dateexpiry => '2099-12-31', |
1323 |
categorycode => $ctgr, |
1324 |
branchcode => $brnchcd, |
1325 |
); |
1326 |
$commandlineSuperuser = C4::Members::GetMember(userid => 'commandlineadmin'); |
1327 |
} |
1328 |
return $commandlineSuperuser; |
1329 |
} |
1330 |
|
1296 |
=head2 interface |
1331 |
=head2 interface |
1297 |
|
1332 |
|
1298 |
Sets the current interface for later retrieval in any Perl module |
1333 |
Sets the current interface for later retrieval in any Perl module |