|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright Biblibre 2010 |
| 4 |
|
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 8 |
# terms of the GNU General Public License as published by the Free Software |
| 9 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 10 |
# version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along with |
| 17 |
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
| 18 |
# Suite 330, Boston, MA 02111-1307 USA |
| 19 |
# |
| 20 |
|
| 21 |
# Re-create statistics from issues and old_issues tables |
| 22 |
# (please note that this is not an accurate process) |
| 23 |
|
| 24 |
# If the issue is still in the issues table, we can re-create issues or renewals |
| 25 |
# If the issue is already in the old_issues table, we can re-create returns |
| 26 |
|
| 27 |
use strict; |
| 28 |
use warnings; |
| 29 |
use C4::Context; |
| 30 |
use C4::Items; |
| 31 |
use Data::Dumper; |
| 32 |
|
| 33 |
my $dbh = C4::Context->dbh; |
| 34 |
|
| 35 |
foreach my $table ('issues', 'old_issues') { |
| 36 |
|
| 37 |
print "looking for missing statistics from the $table table\n"; |
| 38 |
|
| 39 |
my $query = "SELECT * from $table where itemnumber is not null"; |
| 40 |
|
| 41 |
my $sth = $dbh->prepare($query); |
| 42 |
$sth->execute; |
| 43 |
while (my $hashref = $sth->fetchrow_hashref) { |
| 44 |
|
| 45 |
my $ctnquery = "SELECT count(*) as cnt FROM statistics WHERE borrowernumber = ? AND itemnumber = ? AND datetime = ?"; |
| 46 |
my $substh = $dbh->prepare($ctnquery); |
| 47 |
$substh->execute($hashref->{'borrowernumber'}, $hashref->{'itemnumber'}, $hashref->{'timestamp'}); |
| 48 |
my $count = $substh->fetchrow_hashref->{'cnt'}; |
| 49 |
if ($count == 0) { |
| 50 |
my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber) |
| 51 |
VALUES(?, ?, ?, ?, ?, ?, ?, ?)"; |
| 52 |
$substh = $dbh->prepare($insert); |
| 53 |
|
| 54 |
my $type = ($table eq 'old_issues') ? 'return' : ($hashref->{'renewals'} ? 'renew' : 'issue') ; |
| 55 |
my $item = GetItem($hashref->{'itemnumber'}); |
| 56 |
|
| 57 |
$substh->execute( |
| 58 |
$hashref->{'timestamp'}, |
| 59 |
$hashref->{'branchcode'}, |
| 60 |
0, |
| 61 |
$type, |
| 62 |
'', |
| 63 |
$hashref->{'itemnumber'}, |
| 64 |
$item->{'itype'}, |
| 65 |
$hashref->{'borrowernumber'} |
| 66 |
); |
| 67 |
print "timestamp: $hashref->{'timestamp'} branchcode: $hashref->{'branchcode'} type: $type itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n"; |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
} |