From 82a0053f5ee15d4e8e8b6dbc6fe378cfe2148631 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 30 Nov 2009 15:21:17 +0100 Subject: [PATCH] (bug #3819) hold policies doesn't work 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(+) diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 13ffa5c9ce..2dd1878168 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 11cfbc9c53..8e45a96c88 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -677,6 +677,18 @@ CREATE TABLE `default_branch_circ_rules` ( ON DELETE CASCADE ON UPDATE CASCADE ) 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 92a1604685..83d3062fbe 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(<