[Koha-patches] [PATCH] Bug 6025 : MT2889: Adds a script that re-create missing statistics from issues and old_issues tables
Chris Cormack
chrisc at catalyst.net.nz
Thu Mar 31 22:31:04 CEST 2011
From: Matthias Meusburger <matthias.meusburger at biblibre.com>
---
misc/recreateIssueStatistics.pl | 71 +++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
create mode 100644 misc/recreateIssueStatistics.pl
diff --git a/misc/recreateIssueStatistics.pl b/misc/recreateIssueStatistics.pl
new file mode 100644
index 0000000..a87d25b
--- /dev/null
+++ b/misc/recreateIssueStatistics.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+# Copyright Biblibre 2010
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+#
+
+# Re-create statistics from issues and old_issues tables
+# (please note that this is not an accurate process)
+
+# If the issue is still in the issues table, we can re-create issues or renewals
+# If the issue is already in the old_issues table, we can re-create returns
+
+use strict;
+use warnings;
+use C4::Context;
+use C4::Items;
+use Data::Dumper;
+
+my $dbh = C4::Context->dbh;
+
+foreach my $table ('issues', 'old_issues') {
+
+ print "looking for missing statistics from the $table table\n";
+
+ my $query = "SELECT * from $table where itemnumber is not null";
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute;
+ while (my $hashref = $sth->fetchrow_hashref) {
+
+ my $ctnquery = "SELECT count(*) as cnt FROM statistics WHERE borrowernumber = ? AND itemnumber = ? AND datetime = ?";
+ my $substh = $dbh->prepare($ctnquery);
+ $substh->execute($hashref->{'borrowernumber'}, $hashref->{'itemnumber'}, $hashref->{'timestamp'});
+ my $count = $substh->fetchrow_hashref->{'cnt'};
+ if ($count == 0) {
+ my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
+ VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
+ $substh = $dbh->prepare($insert);
+
+ my $type = ($table eq 'old_issues') ? 'return' : ($hashref->{'renewals'} ? 'renew' : 'issue') ;
+ my $item = GetItem($hashref->{'itemnumber'});
+
+ $substh->execute(
+ $hashref->{'timestamp'},
+ $hashref->{'branchcode'},
+ 0,
+ $type,
+ '',
+ $hashref->{'itemnumber'},
+ $item->{'itype'},
+ $hashref->{'borrowernumber'}
+ );
+ print "timestamp: $hashref->{'timestamp'} branchcode: $hashref->{'branchcode'} type: $type itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
+ }
+
+ }
+}
--
1.7.1
More information about the Koha-patches
mailing list