[Koha-patches] [PATCH] (bug #3819) hold policies doesn't work
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Mon Nov 30 15:22:00 CET 2009
This patch backport code from 3.2, create the database, and update kohastructure.sql
---
admin/smart-rules.pl | 80 ++++++++++++++++++++++++++++++
installer/data/mysql/kohastructure.sql | 12 +++++
installer/data/mysql/updatedatabase30.pl | 14 +++++
3 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl
index 13ffa5c..2dd1878 100755
--- a/admin/smart-rules.pl
+++ b/admin/smart-rules.pl
@@ -181,6 +181,86 @@ elsif ($op eq "add-branch-cat") {
}
}
}
+elsif ($op eq "add-branch-item") {
+ my $itemtype = $input->param('itemtype');
+ my $holdallowed = $input->param('holdallowed');
+ $holdallowed =~ s/\s//g;
+ $holdallowed = undef if $holdallowed !~ /^\d+/;
+
+ if ($branch eq "*") {
+ if ($itemtype eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_circ_rules");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
+ (holdallowed)
+ VALUES (?)");
+ my $sth_update = $dbh->prepare("UPDATE default_circ_rules
+ SET holdallowed = ?");
+
+ $sth_search->execute();
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed);
+ } else {
+ $sth_insert->execute($holdallowed);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_item_rules
+ WHERE itemtype = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
+ (itemtype, holdallowed)
+ VALUES (?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
+ SET holdallowed = ?
+ WHERE itemtype = ?");
+ $sth_search->execute($itemtype);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $itemtype);
+ } else {
+ $sth_insert->execute($itemtype, $holdallowed);
+ }
+ }
+ } elsif ($itemtype eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_circ_rules
+ WHERE branchcode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
+ (branchcode, holdallowed)
+ VALUES (?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
+ SET holdallowed = ?
+ WHERE branchcode = ?");
+ $sth_search->execute($branch);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $branch);
+ } else {
+ $sth_insert->execute($branch, $holdallowed);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM branch_item_rules
+ WHERE branchcode = ?
+ AND itemtype = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
+ (branchcode, itemtype, holdallowed)
+ VALUES (?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE branch_item_rules
+ SET holdallowed = ?
+ WHERE branchcode = ?
+ AND itemtype = ?");
+
+ $sth_search->execute($branch, $itemtype);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $branch, $itemtype);
+ } else {
+ $sth_insert->execute($branch, $itemtype, $holdallowed);
+ }
+ }
+}
my $branches = GetBranches();
my @branchloop;
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 81d7c40..4d1d9cf 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -753,6 +753,18 @@ CREATE TABLE `default_branch_circ_rules` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
+-- Table structure for table `default_branch_item_rules`
+--
+
+CREATE TABLE `default_branch_item_rules` (
+ `itemtype` varchar(10) NOT NULL,
+ `holdallowed` tinyint(1) default NULL,
+ PRIMARY KEY (`itemtype`),
+ CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
-- Table structure for table `default_circ_rules`
--
diff --git a/installer/data/mysql/updatedatabase30.pl b/installer/data/mysql/updatedatabase30.pl
index 92a1604..83d3062 100644
--- a/installer/data/mysql/updatedatabase30.pl
+++ b/installer/data/mysql/updatedatabase30.pl
@@ -632,6 +632,20 @@ OPACISBDEN
SetVersion ($DBversion);
}
+$DBversion = "3.00.04.021";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do(<<DEFAULTBRANCHRULES);
+ CREATE TABLE `default_branch_item_rules` (
+ `itemtype` varchar(10) NOT NULL,
+ `holdallowed` tinyint(1) default NULL,
+ PRIMARY KEY (`itemtype`),
+ CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+DEFAULTBRANCHRULES
+}
+
+
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table
--
1.6.3.3
More information about the Koha-patches
mailing list